Qi Nan Sun
Qi Nan Sun

Reputation: 1

how to plot 8x8 correlation matrix

I am trying to plot an 8x8 correlation matrix between the different feature scores and the corresponding chances of admit. May I know how I am supposed to do so?

import tensorflow as tf
import numpy as np
import pylab as plt
from sklearn.model_selection import train_test_split
from sklearn import preprocessing
import pandas as pd

admit_data = np.genfromtxt('admission_predict.csv', delimiter= ',')
X_data, Y_data = admit_data[1:,1:8], admit_data[1:,-1]
x_train, x_test, y_train_, y_test_ = train_test_split(
                                            X_data, 
                                            Y_data, 
                                            test_size=0.3, 
                                            random_state=42
                                      )
scaler = preprocessing.StandardScaler()
x_train = scaler.fit_transform(x_train)
x_test = scaler.fit_transform(x_test)
y_train = y_train_.reshape(len(y_train_), no_labels)
y_test = y_test_.reshape(len(y_test_), no_labels)

data = admit_data
df = pd.DataFrame(data, columns = ['Serial No.','GRE Score','TOEFL Score','University Rating','SOP','LOR','CGPA','Research','Chance of Admit'])
df.corr()

This is the code I'm reading now and my file looks like this

Please help me plot a 8x8 correlation matrix as of now my code doesn't return a 8x8 correlation matrix

Upvotes: 0

Views: 369

Answers (1)

Justas
Justas

Reputation: 159

What about

import matplotlib.pyplot as plt
cors = df.corr()
plt.matshow(cors)
plt.yticks(range(cors.shape[1]), cors.columns, fontsize=7)
plt.xticks(range(cors.shape[1]), cors.columns, fontsize=7, rotation=90)
plt.colorbar()

to use all except "Serial No" column use this cors instead:

cors = df.drop("Serial No.", axis=1).corr()

Upvotes: 1

Related Questions