Skip to content

Commit c00f69f

Browse files
committed
Pushing the docs for revision for branch: master, commit 28bcb43dd2eacfaa98f0215ec8481e0da9f8ec5d
1 parent e9be350 commit c00f69f

File tree

905 files changed

+2671
-2647
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

905 files changed

+2671
-2647
lines changed
473 Bytes
Binary file not shown.
464 Bytes
Binary file not shown.

dev/_downloads/face_recognition.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"execution_count": null,
2525
"cell_type": "code",
2626
"source": [
27-
"from __future__ import print_function\n\nfrom time import time\nimport logging\nimport matplotlib.pyplot as plt\n\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.model_selection import GridSearchCV\nfrom sklearn.datasets import fetch_lfw_people\nfrom sklearn.metrics import classification_report\nfrom sklearn.metrics import confusion_matrix\nfrom sklearn.decomposition import RandomizedPCA\nfrom sklearn.svm import SVC\n\n\nprint(__doc__)\n\n# Display progress logs on stdout\nlogging.basicConfig(level=logging.INFO, format='%(asctime)s %(message)s')"
27+
"from __future__ import print_function\n\nfrom time import time\nimport logging\nimport matplotlib.pyplot as plt\n\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.model_selection import GridSearchCV\nfrom sklearn.datasets import fetch_lfw_people\nfrom sklearn.metrics import classification_report\nfrom sklearn.metrics import confusion_matrix\nfrom sklearn.decomposition import PCA\nfrom sklearn.svm import SVC\n\n\nprint(__doc__)\n\n# Display progress logs on stdout\nlogging.basicConfig(level=logging.INFO, format='%(asctime)s %(message)s')"
2828
],
2929
"outputs": [],
3030
"metadata": {
@@ -78,7 +78,7 @@
7878
"execution_count": null,
7979
"cell_type": "code",
8080
"source": [
81-
"n_components = 150\n\nprint(\"Extracting the top %d eigenfaces from %d faces\"\n % (n_components, X_train.shape[0]))\nt0 = time()\npca = RandomizedPCA(n_components=n_components, whiten=True).fit(X_train)\nprint(\"done in %0.3fs\" % (time() - t0))\n\neigenfaces = pca.components_.reshape((n_components, h, w))\n\nprint(\"Projecting the input data on the eigenfaces orthonormal basis\")\nt0 = time()\nX_train_pca = pca.transform(X_train)\nX_test_pca = pca.transform(X_test)\nprint(\"done in %0.3fs\" % (time() - t0))"
81+
"n_components = 150\n\nprint(\"Extracting the top %d eigenfaces from %d faces\"\n % (n_components, X_train.shape[0]))\nt0 = time()\npca = PCA(n_components=n_components, svd_solver='randomized',\n whiten=True).fit(X_train)\nprint(\"done in %0.3fs\" % (time() - t0))\n\neigenfaces = pca.components_.reshape((n_components, h, w))\n\nprint(\"Projecting the input data on the eigenfaces orthonormal basis\")\nt0 = time()\nX_train_pca = pca.transform(X_train)\nX_test_pca = pca.transform(X_test)\nprint(\"done in %0.3fs\" % (time() - t0))"
8282
],
8383
"outputs": [],
8484
"metadata": {

dev/_downloads/face_recognition.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
from sklearn.datasets import fetch_lfw_people
3939
from sklearn.metrics import classification_report
4040
from sklearn.metrics import confusion_matrix
41-
from sklearn.decomposition import RandomizedPCA
41+
from sklearn.decomposition import PCA
4242
from sklearn.svm import SVC
4343

4444

@@ -88,7 +88,8 @@
8888
print("Extracting the top %d eigenfaces from %d faces"
8989
% (n_components, X_train.shape[0]))
9090
t0 = time()
91-
pca = RandomizedPCA(n_components=n_components, whiten=True).fit(X_train)
91+
pca = PCA(n_components=n_components, svd_solver='randomized',
92+
whiten=True).fit(X_train)
9293
print("done in %0.3fs" % (time() - t0))
9394

9495
eigenfaces = pca.components_.reshape((n_components, h, w))

dev/_downloads/plot_faces_decomposition.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
"execution_count": null,
7272
"cell_type": "code",
7373
"source": [
74-
"estimators = [\n ('Eigenfaces - RandomizedPCA',\n decomposition.RandomizedPCA(n_components=n_components, whiten=True),\n True),\n\n ('Non-negative components - NMF',\n decomposition.NMF(n_components=n_components, init='nndsvda', tol=5e-3),\n False),\n\n ('Independent components - FastICA',\n decomposition.FastICA(n_components=n_components, whiten=True),\n True),\n\n ('Sparse comp. - MiniBatchSparsePCA',\n decomposition.MiniBatchSparsePCA(n_components=n_components, alpha=0.8,\n n_iter=100, batch_size=3,\n random_state=rng),\n True),\n\n ('MiniBatchDictionaryLearning',\n decomposition.MiniBatchDictionaryLearning(n_components=15, alpha=0.1,\n n_iter=50, batch_size=3,\n random_state=rng),\n True),\n\n ('Cluster centers - MiniBatchKMeans',\n MiniBatchKMeans(n_clusters=n_components, tol=1e-3, batch_size=20,\n max_iter=50, random_state=rng),\n True),\n\n ('Factor Analysis components - FA',\n decomposition.FactorAnalysis(n_components=n_components, max_iter=2),\n True),\n]"
74+
"estimators = [\n ('Eigenfaces - PCA using randomized SVD',\n decomposition.PCA(n_components=n_components, svd_solver='randomized',\n whiten=True),\n True),\n\n ('Non-negative components - NMF',\n decomposition.NMF(n_components=n_components, init='nndsvda', tol=5e-3),\n False),\n\n ('Independent components - FastICA',\n decomposition.FastICA(n_components=n_components, whiten=True),\n True),\n\n ('Sparse comp. - MiniBatchSparsePCA',\n decomposition.MiniBatchSparsePCA(n_components=n_components, alpha=0.8,\n n_iter=100, batch_size=3,\n random_state=rng),\n True),\n\n ('MiniBatchDictionaryLearning',\n decomposition.MiniBatchDictionaryLearning(n_components=15, alpha=0.1,\n n_iter=50, batch_size=3,\n random_state=rng),\n True),\n\n ('Cluster centers - MiniBatchKMeans',\n MiniBatchKMeans(n_clusters=n_components, tol=1e-3, batch_size=20,\n max_iter=50, random_state=rng),\n True),\n\n ('Factor Analysis components - FA',\n decomposition.FactorAnalysis(n_components=n_components, max_iter=2),\n True),\n]"
7575
],
7676
"outputs": [],
7777
"metadata": {
@@ -107,7 +107,7 @@
107107
"execution_count": null,
108108
"cell_type": "code",
109109
"source": [
110-
"for name, estimator, center in estimators:\n print(\"Extracting the top %d %s...\" % (n_components, name))\n t0 = time()\n data = faces\n if center:\n data = faces_centered\n estimator.fit(data)\n train_time = (time() - t0)\n print(\"done in %0.3fs\" % train_time)\n if hasattr(estimator, 'cluster_centers_'):\n components_ = estimator.cluster_centers_\n else:\n components_ = estimator.components_\n if hasattr(estimator, 'noise_variance_'):\n plot_gallery(\"Pixelwise variance\",\n estimator.noise_variance_.reshape(1, -1), n_col=1,\n n_row=1)\n plot_gallery('%s - Train time %.1fs' % (name, train_time),\n components_[:n_components])\n\nplt.show()"
110+
"for name, estimator, center in estimators:\n print(\"Extracting the top %d %s...\" % (n_components, name))\n t0 = time()\n data = faces\n if center:\n data = faces_centered\n estimator.fit(data)\n train_time = (time() - t0)\n print(\"done in %0.3fs\" % train_time)\n if hasattr(estimator, 'cluster_centers_'):\n components_ = estimator.cluster_centers_\n else:\n components_ = estimator.components_\n\n # Plot an image representing the pixelwise variance provided by the\n # estimator e.g its noise_variance_ attribute. The Eigenfaces estimator,\n # via the PCA decomposition, also provides a scalar noise_variance_\n # (the mean of pixelwise variance) that cannot be displayed as an image\n # so we skip it.\n if (hasattr(estimator, 'noise_variance_') and\n estimator.noise_variance_.ndim > 0): # Skip the Eigenfaces case\n plot_gallery(\"Pixelwise variance\",\n estimator.noise_variance_.reshape(1, -1), n_col=1,\n n_row=1)\n plot_gallery('%s - Train time %.1fs' % (name, train_time),\n components_[:n_components])\n\nplt.show()"
111111
],
112112
"outputs": [],
113113
"metadata": {

dev/_downloads/plot_faces_decomposition.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@ def plot_gallery(title, images, n_col=n_col, n_row=n_row):
6666
# List of the different estimators, whether to center and transpose the
6767
# problem, and whether the transformer uses the clustering API.
6868
estimators = [
69-
('Eigenfaces - RandomizedPCA',
70-
decomposition.RandomizedPCA(n_components=n_components, whiten=True),
69+
('Eigenfaces - PCA using randomized SVD',
70+
decomposition.PCA(n_components=n_components, svd_solver='randomized',
71+
whiten=True),
7172
True),
7273

7374
('Non-negative components - NMF',
@@ -122,7 +123,14 @@ def plot_gallery(title, images, n_col=n_col, n_row=n_row):
122123
components_ = estimator.cluster_centers_
123124
else:
124125
components_ = estimator.components_
125-
if hasattr(estimator, 'noise_variance_'):
126+
127+
# Plot an image representing the pixelwise variance provided by the
128+
# estimator e.g its noise_variance_ attribute. The Eigenfaces estimator,
129+
# via the PCA decomposition, also provides a scalar noise_variance_
130+
# (the mean of pixelwise variance) that cannot be displayed as an image
131+
# so we skip it.
132+
if (hasattr(estimator, 'noise_variance_') and
133+
estimator.noise_variance_.ndim > 0): # Skip the Eigenfaces case
126134
plot_gallery("Pixelwise variance",
127135
estimator.noise_variance_.reshape(1, -1), n_col=1,
128136
n_row=1)

0 commit comments

Comments
 (0)