mirror of
https://github.com/ArthurDanjou/ml_exercises.git
synced 2026-01-14 12:14:38 +01:00
minor changes to notebooks
This commit is contained in:
@@ -225,6 +225,10 @@
|
||||
"source": [
|
||||
"# lambdas = eigenvalues\n",
|
||||
"print(kpca.lambdas_[:10])\n",
|
||||
"# check how much \"information\" we would keep if we were to reduce the dimensionality to 20\n",
|
||||
"# (this is not 100% accurate, since we only computed the first 100 kPCA components, i.e.,\n",
|
||||
"# normally lambda_ should contain all eigenvalues - but this should be close enough)\n",
|
||||
"print(\"Percentage of variance retained with 20 components:\", 100*(sum(kpca.lambdas_[:20])/sum(kpca.lambdas_)))\n",
|
||||
"# plot eigenvalue spectrum\n",
|
||||
"plt.figure()\n",
|
||||
"plt.plot(range(1, len(kpca.lambdas_)+1), kpca.lambdas_)\n",
|
||||
|
||||
@@ -54,7 +54,8 @@
|
||||
"source": [
|
||||
"# reshape image into a matrix with RGB values for each pixel\n",
|
||||
"h, w, d = img_array.shape\n",
|
||||
"X = ... # TODO: reshape img_array such that X is a matrix of shape n_pixels x 3 RGB channels\n",
|
||||
"X = new_X.reshape(h*w, d)\n",
|
||||
"# 1 pixel = 1 data point; RGB values = features\n",
|
||||
"print(X.shape)"
|
||||
]
|
||||
},
|
||||
@@ -122,7 +123,7 @@
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# reshape back into image format\n",
|
||||
"img_new = new_X.reshape(h, w, d)\n",
|
||||
"img_new = ... # TODO: reshape new_X such that img_new is a matrix of shape height x width x 3 RGB channels\n",
|
||||
"print(img_new.shape)"
|
||||
]
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user