This commit is contained in:
mhjensen
2020-01-02 10:54:04 +01:00
parent ac368dd0c1
commit a9ea09f8fd
9 changed files with 9 additions and 9 deletions
+1 -1
View File
@@ -374,7 +374,7 @@ X2Dsl <span style="color: #666666">=</span> pca<span style="color: #666666">.</s
<span style="color: #008000; font-weight: bold">print</span>(pca<span style="color: #666666">.</span>components_<span style="color: #666666">.</span>T[:, <span style="color: #666666">0</span>])
</pre></div>
<p>
This code does not contain all the above elements, but it shows how we can use <b>Scikit-Learn</b> to extract the eigenvector which corresponds to the largest eigenvalue. Try to, based on the above, to address the questions above.
This code does not contain all the above elements, but it shows how we can use <b>Scikit-Learn</b> to extract the eigenvector which corresponds to the largest eigenvalue. Try to address the questions we pose before the above code. Try also to change the values of the covariance matrix by making one of the diagonal elements much larger than the other. What do you observe then?
<p>
<p>
+1 -1
View File
@@ -1187,7 +1187,7 @@ X2Dsl = pca.fit_transform(X)
<span style="color: #8B008B; font-weight: bold">print</span>(pca.components_.T[:, <span style="color: #B452CD">0</span>])
</pre></div>
<p>
This code does not contain all the above elements, but it shows how we can use <b>Scikit-Learn</b> to extract the eigenvector which corresponds to the largest eigenvalue. Try to, based on the above, to address the questions above.
This code does not contain all the above elements, but it shows how we can use <b>Scikit-Learn</b> to extract the eigenvector which corresponds to the largest eigenvalue. Try to address the questions we pose before the above code. Try also to change the values of the covariance matrix by making one of the diagonal elements much larger than the other. What do you observe then?
</section>
+1 -1
View File
@@ -1160,7 +1160,7 @@ X2Dsl = pca.fit_transform(X)
<span style="color: #8B008B; font-weight: bold">print</span>(pca.components_.T[:, <span style="color: #B452CD">0</span>])
</pre></div>
<p>
This code does not contain all the above elements, but it shows how we can use <b>Scikit-Learn</b> to extract the eigenvector which corresponds to the largest eigenvalue. Try to, based on the above, to address the questions above.
This code does not contain all the above elements, but it shows how we can use <b>Scikit-Learn</b> to extract the eigenvector which corresponds to the largest eigenvalue. Try to address the questions we pose before the above code. Try also to change the values of the covariance matrix by making one of the diagonal elements much larger than the other. What do you observe then?
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
+1 -1
View File
@@ -1165,7 +1165,7 @@ X2Dsl <span style="color: #666666">=</span> pca<span style="color: #666666">.</s
<span style="color: #008000; font-weight: bold">print</span>(pca<span style="color: #666666">.</span>components_<span style="color: #666666">.</span>T[:, <span style="color: #666666">0</span>])
</pre></div>
<p>
This code does not contain all the above elements, but it shows how we can use <b>Scikit-Learn</b> to extract the eigenvector which corresponds to the largest eigenvalue. Try to, based on the above, to address the questions above.
This code does not contain all the above elements, but it shows how we can use <b>Scikit-Learn</b> to extract the eigenvector which corresponds to the largest eigenvalue. Try to address the questions we pose before the above code. Try also to change the values of the covariance matrix by making one of the diagonal elements much larger than the other. What do you observe then?
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
+1 -1
View File
@@ -1335,7 +1335,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"This code does not contain all the above elements, but it shows how we can use **Scikit-Learn** to extract the eigenvector which corresponds to the largest eigenvalue. Try to, based on the above, to address the questions above. \n",
"This code does not contain all the above elements, but it shows how we can use **Scikit-Learn** to extract the eigenvector which corresponds to the largest eigenvalue. Try to address the questions we pose before the above code. Try also to change the values of the covariance matrix by making one of the diagonal elements much larger than the other. What do you observe then? \n",
"\n",
"## Classical PCA Theorem\n",
"\n",
Binary file not shown.
Binary file not shown.
+1 -1
View File
@@ -911,7 +911,7 @@ print("Eigenvector of largest eigenvalue")
print(pca.components_.T[:, 0])
!ec
This code does not contain all the above elements, but it shows how we can use _Scikit-Learn_ to extract the eigenvector which corresponds to the largest eigenvalue. Try to, based on the above, to address the questions above.
This code does not contain all the above elements, but it shows how we can use _Scikit-Learn_ to extract the eigenvector which corresponds to the largest eigenvalue. Try to address the questions we pose before the above code. Try also to change the values of the covariance matrix by making one of the diagonal elements much larger than the other. What do you observe then?
!split
===== Classical PCA Theorem =====
+3 -3
View File
@@ -5,7 +5,7 @@ import matplotlib.pyplot as plt
n = 1000
mean = (-1, 2)
cov = [[4, 2], [2, 2]]
cov = [[10, 1], [1, 0.5]]
X = np.random.multivariate_normal(mean, cov, n)
df = pd.DataFrame(X)
@@ -21,8 +21,8 @@ X_centered = X - X.mean(axis=0)
print("Centered covariance using numpy")
print(np.cov(X_centered.T))
# extract the relevant columns from the centered design matrix
x = X_centered[:,[0]]
y = X_centered[:,[1]]
x = X_centered[:,0]
y = X_centered[:,1]
Cov = np.zeros((2,2))
Cov[0,1] = np.sum(x.T@y)/(n-1.0)
Cov[0,0] = np.sum(x.T@x)/(n-1.0)