added small feature to PCA slides
This commit is contained in:
@@ -182,6 +182,11 @@ correlation_matrix <span style="color: #666666">=</span> cancerpd<span style="co
|
||||
<span style="color: #408080; font-style: italic"># annot = True to print the values inside the square</span>
|
||||
sns<span style="color: #666666">.</span>heatmap(data<span style="color: #666666">=</span>correlation_matrix, annot<span style="color: #666666">=</span><span style="color: #008000">True</span>)
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
|
||||
<span style="color: #408080; font-style: italic">#print eigvalues of correlation matrix</span>
|
||||
EigValues, EigVectors <span style="color: #666666">=</span> np<span style="color: #666666">.</span>linalg<span style="color: #666666">.</span>eig(correlation_matrix)
|
||||
<span style="color: #008000; font-weight: bold">print</span>(EigValues)
|
||||
|
||||
<span style="color: #408080; font-style: italic">#split into train and test and then scale thereafter</span>
|
||||
X_train, X_test, y_train, y_test <span style="color: #666666">=</span> train_test_split(cancer<span style="color: #666666">.</span>data,cancer<span style="color: #666666">.</span>target,random_state<span style="color: #666666">=0</span>)
|
||||
<span style="color: #008000; font-weight: bold">print</span>(X_train<span style="color: #666666">.</span>shape)
|
||||
|
||||
@@ -459,6 +459,11 @@ correlation_matrix = cancerpd.corr().round(<span style="color: #B452CD">1</span>
|
||||
<span style="color: #228B22"># annot = True to print the values inside the square</span>
|
||||
sns.heatmap(data=correlation_matrix, annot=<span style="color: #658b00">True</span>)
|
||||
plt.show()
|
||||
|
||||
<span style="color: #228B22">#print eigvalues of correlation matrix</span>
|
||||
EigValues, EigVectors = np.linalg.eig(correlation_matrix)
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(EigValues)
|
||||
|
||||
<span style="color: #228B22">#split into train and test and then scale thereafter</span>
|
||||
X_train, X_test, y_train, y_test = train_test_split(cancer.data,cancer.target,random_state=<span style="color: #B452CD">0</span>)
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(X_train.shape)
|
||||
|
||||
@@ -442,6 +442,11 @@ correlation_matrix = cancerpd.corr().round(<span style="color: #B452CD">1</span>
|
||||
<span style="color: #228B22"># annot = True to print the values inside the square</span>
|
||||
sns.heatmap(data=correlation_matrix, annot=<span style="color: #658b00">True</span>)
|
||||
plt.show()
|
||||
|
||||
<span style="color: #228B22">#print eigvalues of correlation matrix</span>
|
||||
EigValues, EigVectors = np.linalg.eig(correlation_matrix)
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(EigValues)
|
||||
|
||||
<span style="color: #228B22">#split into train and test and then scale thereafter</span>
|
||||
X_train, X_test, y_train, y_test = train_test_split(cancer.data,cancer.target,random_state=<span style="color: #B452CD">0</span>)
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(X_train.shape)
|
||||
|
||||
@@ -447,6 +447,11 @@ correlation_matrix <span style="color: #666666">=</span> cancerpd<span style="co
|
||||
<span style="color: #408080; font-style: italic"># annot = True to print the values inside the square</span>
|
||||
sns<span style="color: #666666">.</span>heatmap(data<span style="color: #666666">=</span>correlation_matrix, annot<span style="color: #666666">=</span><span style="color: #008000">True</span>)
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
|
||||
<span style="color: #408080; font-style: italic">#print eigvalues of correlation matrix</span>
|
||||
EigValues, EigVectors <span style="color: #666666">=</span> np<span style="color: #666666">.</span>linalg<span style="color: #666666">.</span>eig(correlation_matrix)
|
||||
<span style="color: #008000; font-weight: bold">print</span>(EigValues)
|
||||
|
||||
<span style="color: #408080; font-style: italic">#split into train and test and then scale thereafter</span>
|
||||
X_train, X_test, y_train, y_test <span style="color: #666666">=</span> train_test_split(cancer<span style="color: #666666">.</span>data,cancer<span style="color: #666666">.</span>target,random_state<span style="color: #666666">=0</span>)
|
||||
<span style="color: #008000; font-weight: bold">print</span>(X_train<span style="color: #666666">.</span>shape)
|
||||
|
||||
@@ -330,6 +330,11 @@
|
||||
"# annot = True to print the values inside the square\n",
|
||||
"sns.heatmap(data=correlation_matrix, annot=True)\n",
|
||||
"plt.show()\n",
|
||||
"\n",
|
||||
"#print eigvalues of correlation matrix\n",
|
||||
"EigValues, EigVectors = np.linalg.eig(correlation_matrix)\n",
|
||||
"print(EigValues)\n",
|
||||
"\n",
|
||||
"#split into train and test and then scale thereafter\n",
|
||||
"X_train, X_test, y_train, y_test = train_test_split(cancer.data,cancer.target,random_state=0)\n",
|
||||
"print(X_train.shape)\n",
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -287,6 +287,11 @@ correlation_matrix = cancerpd.corr().round(1)
|
||||
# annot = True to print the values inside the square
|
||||
sns.heatmap(data=correlation_matrix, annot=True)
|
||||
plt.show()
|
||||
|
||||
#print eigvalues of correlation matrix
|
||||
EigValues, EigVectors = np.linalg.eig(correlation_matrix)
|
||||
print(EigValues)
|
||||
|
||||
#split into train and test and then scale thereafter
|
||||
X_train, X_test, y_train, y_test = train_test_split(cancer.data,cancer.target,random_state=0)
|
||||
print(X_train.shape)
|
||||
|
||||
@@ -8,22 +8,6 @@ import pandas as pd
|
||||
|
||||
cancerpd = pd.DataFrame(cancer.data, columns=cancer.feature_names)
|
||||
|
||||
fig, axes = plt.subplots(15,2,figsize=(10,20))
|
||||
malignant = cancer.data[cancer.target == 0]
|
||||
benign = cancer.data[cancer.target == 1]
|
||||
ax = axes.ravel()
|
||||
|
||||
for i in range(30):
|
||||
_, bins = np.histogram(cancer.data[:,i], bins =50)
|
||||
ax[i].hist(malignant[:,i], bins = bins, alpha = 0.5)
|
||||
ax[i].hist(benign[:,i], bins = bins, alpha = 0.5)
|
||||
ax[i].set_title(cancer.feature_names[i])
|
||||
ax[i].set_yticks(())
|
||||
ax[0].set_xlabel("Feature magnitude")
|
||||
ax[0].set_ylabel("Frequency")
|
||||
ax[0].legend(["Malignant", "Benign"], loc ="best")
|
||||
fig.tight_layout()
|
||||
plt.show()
|
||||
|
||||
import seaborn as sns
|
||||
correlation_matrix = cancerpd.corr().round(1)
|
||||
@@ -31,6 +15,9 @@ correlation_matrix = cancerpd.corr().round(1)
|
||||
# annot = True to print the values inside the square
|
||||
sns.heatmap(data=correlation_matrix, annot=True)
|
||||
plt.show()
|
||||
EigValues, EigVectors = np.linalg.eig(correlation_matrix)
|
||||
print(EigValues)
|
||||
|
||||
X_train, X_test, y_train, y_test = train_test_split(cancer.data,cancer.target,random_state=0)
|
||||
print(X_train.shape)
|
||||
print(X_test.shape)
|
||||
|
||||
Reference in New Issue
Block a user