Skip to content

Commit f0faa7f

Browse files
committed
Pushing the docs to dev/ for branch: master, commit 6f7394953b0dbcd6400b9f39f1dbd2e430a4a9e5
1 parent e000022 commit f0faa7f

File tree

1,524 files changed

+3251
-3237
lines changed

Some content is hidden

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

1,524 files changed

+3251
-3237
lines changed
140 Bytes
Binary file not shown.
137 Bytes
Binary file not shown.

dev/_downloads/plot_agglomerative_clustering.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
},
2727
"outputs": [],
2828
"source": [
29-
"# Authors: Gael Varoquaux, Nelle Varoquaux\n# License: BSD 3 clause\n\nimport time\nimport matplotlib.pyplot as plt\nimport numpy as np\n\nfrom sklearn.cluster import AgglomerativeClustering\nfrom sklearn.neighbors import kneighbors_graph\n\n# Generate sample data\nn_samples = 1500\nnp.random.seed(0)\nt = 1.5 * np.pi * (1 + 3 * np.random.rand(1, n_samples))\nx = t * np.cos(t)\ny = t * np.sin(t)\n\n\nX = np.concatenate((x, y))\nX += .7 * np.random.randn(2, n_samples)\nX = X.T\n\n# Create a graph capturing local connectivity. Larger number of neighbors\n# will give more homogeneous clusters to the cost of computation\n# time. A very large number of neighbors gives more evenly distributed\n# cluster sizes, but may not impose the local manifold structure of\n# the data\nknn_graph = kneighbors_graph(X, 30, include_self=False)\n\nfor connectivity in (None, knn_graph):\n for n_clusters in (30, 3):\n plt.figure(figsize=(10, 4))\n for index, linkage in enumerate(('average',\n 'complete',\n 'ward',\n 'single')):\n plt.subplot(1, 4, index + 1)\n model = AgglomerativeClustering(linkage=linkage,\n connectivity=connectivity,\n n_clusters=n_clusters)\n t0 = time.time()\n model.fit(X)\n elapsed_time = time.time() - t0\n plt.scatter(X[:, 0], X[:, 1], c=model.labels_,\n cmap=plt.cm.spectral)\n plt.title('linkage=%s\\n(time %.2fs)' % (linkage, elapsed_time),\n fontdict=dict(verticalalignment='top'))\n plt.axis('equal')\n plt.axis('off')\n\n plt.subplots_adjust(bottom=0, top=.89, wspace=0,\n left=0, right=1)\n plt.suptitle('n_cluster=%i, connectivity=%r' %\n (n_clusters, connectivity is not None), size=17)\n\n\nplt.show()"
29+
"# Authors: Gael Varoquaux, Nelle Varoquaux\n# License: BSD 3 clause\n\nimport time\nimport matplotlib.pyplot as plt\nimport numpy as np\n\nfrom sklearn.cluster import AgglomerativeClustering\nfrom sklearn.neighbors import kneighbors_graph\n\n# Generate sample data\nn_samples = 1500\nnp.random.seed(0)\nt = 1.5 * np.pi * (1 + 3 * np.random.rand(1, n_samples))\nx = t * np.cos(t)\ny = t * np.sin(t)\n\n\nX = np.concatenate((x, y))\nX += .7 * np.random.randn(2, n_samples)\nX = X.T\n\n# Create a graph capturing local connectivity. Larger number of neighbors\n# will give more homogeneous clusters to the cost of computation\n# time. A very large number of neighbors gives more evenly distributed\n# cluster sizes, but may not impose the local manifold structure of\n# the data\nknn_graph = kneighbors_graph(X, 30, include_self=False)\n\nfor connectivity in (None, knn_graph):\n for n_clusters in (30, 3):\n plt.figure(figsize=(10, 4))\n for index, linkage in enumerate(('average',\n 'complete',\n 'ward',\n 'single')):\n plt.subplot(1, 4, index + 1)\n model = AgglomerativeClustering(linkage=linkage,\n connectivity=connectivity,\n n_clusters=n_clusters)\n t0 = time.time()\n model.fit(X)\n elapsed_time = time.time() - t0\n plt.scatter(X[:, 0], X[:, 1], c=model.labels_,\n cmap=plt.cm.nipy_spectral)\n plt.title('linkage=%s\\n(time %.2fs)' % (linkage, elapsed_time),\n fontdict=dict(verticalalignment='top'))\n plt.axis('equal')\n plt.axis('off')\n\n plt.subplots_adjust(bottom=0, top=.89, wspace=0,\n left=0, right=1)\n plt.suptitle('n_cluster=%i, connectivity=%r' %\n (n_clusters, connectivity is not None), size=17)\n\n\nplt.show()"
3030
]
3131
}
3232
],

dev/_downloads/plot_agglomerative_clustering.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
model.fit(X)
6666
elapsed_time = time.time() - t0
6767
plt.scatter(X[:, 0], X[:, 1], c=model.labels_,
68-
cmap=plt.cm.spectral)
68+
cmap=plt.cm.nipy_spectral)
6969
plt.title('linkage=%s\n(time %.2fs)' % (linkage, elapsed_time),
7070
fontdict=dict(verticalalignment='top'))
7171
plt.axis('equal')

dev/_downloads/plot_coin_segmentation.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
},
4545
"outputs": [],
4646
"source": [
47-
"for assign_labels in ('kmeans', 'discretize'):\n t0 = time.time()\n labels = spectral_clustering(graph, n_clusters=N_REGIONS,\n assign_labels=assign_labels, random_state=42)\n t1 = time.time()\n labels = labels.reshape(rescaled_coins.shape)\n\n plt.figure(figsize=(5, 5))\n plt.imshow(rescaled_coins, cmap=plt.cm.gray)\n for l in range(N_REGIONS):\n plt.contour(labels == l,\n colors=[plt.cm.spectral(l / float(N_REGIONS))])\n plt.xticks(())\n plt.yticks(())\n title = 'Spectral clustering: %s, %.2fs' % (assign_labels, (t1 - t0))\n print(title)\n plt.title(title)\nplt.show()"
47+
"for assign_labels in ('kmeans', 'discretize'):\n t0 = time.time()\n labels = spectral_clustering(graph, n_clusters=N_REGIONS,\n assign_labels=assign_labels, random_state=42)\n t1 = time.time()\n labels = labels.reshape(rescaled_coins.shape)\n\n plt.figure(figsize=(5, 5))\n plt.imshow(rescaled_coins, cmap=plt.cm.gray)\n for l in range(N_REGIONS):\n plt.contour(labels == l,\n colors=[plt.cm.nipy_spectral(l / float(N_REGIONS))])\n plt.xticks(())\n plt.yticks(())\n title = 'Spectral clustering: %s, %.2fs' % (assign_labels, (t1 - t0))\n print(title)\n plt.title(title)\nplt.show()"
4848
]
4949
}
5050
],

dev/_downloads/plot_coin_segmentation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
plt.imshow(rescaled_coins, cmap=plt.cm.gray)
7373
for l in range(N_REGIONS):
7474
plt.contour(labels == l,
75-
colors=[plt.cm.spectral(l / float(N_REGIONS))])
75+
colors=[plt.cm.nipy_spectral(l / float(N_REGIONS))])
7676
plt.xticks(())
7777
plt.yticks(())
7878
title = 'Spectral clustering: %s, %.2fs' % (assign_labels, (t1 - t0))

dev/_downloads/plot_coin_ward_segmentation.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
},
2727
"outputs": [],
2828
"source": [
29-
"# Author : Vincent Michel, 2010\n# Alexandre Gramfort, 2011\n# License: BSD 3 clause\n\nprint(__doc__)\n\nimport time as time\n\nimport numpy as np\nfrom scipy.ndimage.filters import gaussian_filter\n\nimport matplotlib.pyplot as plt\n\nfrom skimage.data import coins\nfrom skimage.transform import rescale\n\nfrom sklearn.feature_extraction.image import grid_to_graph\nfrom sklearn.cluster import AgglomerativeClustering\n\n\n# #############################################################################\n# Generate data\norig_coins = coins()\n\n# Resize it to 20% of the original size to speed up the processing\n# Applying a Gaussian filter for smoothing prior to down-scaling\n# reduces aliasing artifacts.\nsmoothened_coins = gaussian_filter(orig_coins, sigma=2)\nrescaled_coins = rescale(smoothened_coins, 0.2, mode=\"reflect\")\n\nX = np.reshape(rescaled_coins, (-1, 1))\n\n# #############################################################################\n# Define the structure A of the data. Pixels connected to their neighbors.\nconnectivity = grid_to_graph(*rescaled_coins.shape)\n\n# #############################################################################\n# Compute clustering\nprint(\"Compute structured hierarchical clustering...\")\nst = time.time()\nn_clusters = 27 # number of regions\nward = AgglomerativeClustering(n_clusters=n_clusters, linkage='ward',\n connectivity=connectivity)\nward.fit(X)\nlabel = np.reshape(ward.labels_, rescaled_coins.shape)\nprint(\"Elapsed time: \", time.time() - st)\nprint(\"Number of pixels: \", label.size)\nprint(\"Number of clusters: \", np.unique(label).size)\n\n# #############################################################################\n# Plot the results on an image\nplt.figure(figsize=(5, 5))\nplt.imshow(rescaled_coins, cmap=plt.cm.gray)\nfor l in range(n_clusters):\n plt.contour(label == l,\n colors=[plt.cm.spectral(l / float(n_clusters)), ])\nplt.xticks(())\nplt.yticks(())\nplt.show()"
29+
"# Author : Vincent Michel, 2010\n# Alexandre Gramfort, 2011\n# License: BSD 3 clause\n\nprint(__doc__)\n\nimport time as time\n\nimport numpy as np\nfrom scipy.ndimage.filters import gaussian_filter\n\nimport matplotlib.pyplot as plt\n\nfrom skimage.data import coins\nfrom skimage.transform import rescale\n\nfrom sklearn.feature_extraction.image import grid_to_graph\nfrom sklearn.cluster import AgglomerativeClustering\n\n\n# #############################################################################\n# Generate data\norig_coins = coins()\n\n# Resize it to 20% of the original size to speed up the processing\n# Applying a Gaussian filter for smoothing prior to down-scaling\n# reduces aliasing artifacts.\nsmoothened_coins = gaussian_filter(orig_coins, sigma=2)\nrescaled_coins = rescale(smoothened_coins, 0.2, mode=\"reflect\")\n\nX = np.reshape(rescaled_coins, (-1, 1))\n\n# #############################################################################\n# Define the structure A of the data. Pixels connected to their neighbors.\nconnectivity = grid_to_graph(*rescaled_coins.shape)\n\n# #############################################################################\n# Compute clustering\nprint(\"Compute structured hierarchical clustering...\")\nst = time.time()\nn_clusters = 27 # number of regions\nward = AgglomerativeClustering(n_clusters=n_clusters, linkage='ward',\n connectivity=connectivity)\nward.fit(X)\nlabel = np.reshape(ward.labels_, rescaled_coins.shape)\nprint(\"Elapsed time: \", time.time() - st)\nprint(\"Number of pixels: \", label.size)\nprint(\"Number of clusters: \", np.unique(label).size)\n\n# #############################################################################\n# Plot the results on an image\nplt.figure(figsize=(5, 5))\nplt.imshow(rescaled_coins, cmap=plt.cm.gray)\nfor l in range(n_clusters):\n plt.contour(label == l,\n colors=[plt.cm.nipy_spectral(l / float(n_clusters)), ])\nplt.xticks(())\nplt.yticks(())\nplt.show()"
3030
]
3131
}
3232
],

dev/_downloads/plot_coin_ward_segmentation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
plt.imshow(rescaled_coins, cmap=plt.cm.gray)
6464
for l in range(n_clusters):
6565
plt.contour(label == l,
66-
colors=[plt.cm.spectral(l / float(n_clusters)), ])
66+
colors=[plt.cm.nipy_spectral(l / float(n_clusters)), ])
6767
plt.xticks(())
6868
plt.yticks(())
6969
plt.show()

dev/_downloads/plot_digits_agglomeration.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
},
2727
"outputs": [],
2828
"source": [
29-
"print(__doc__)\n\n# Code source: Ga\u00ebl Varoquaux\n# Modified for documentation by Jaques Grobler\n# License: BSD 3 clause\n\nimport numpy as np\nimport matplotlib.pyplot as plt\n\nfrom sklearn import datasets, cluster\nfrom sklearn.feature_extraction.image import grid_to_graph\n\ndigits = datasets.load_digits()\nimages = digits.images\nX = np.reshape(images, (len(images), -1))\nconnectivity = grid_to_graph(*images[0].shape)\n\nagglo = cluster.FeatureAgglomeration(connectivity=connectivity,\n n_clusters=32)\n\nagglo.fit(X)\nX_reduced = agglo.transform(X)\n\nX_restored = agglo.inverse_transform(X_reduced)\nimages_restored = np.reshape(X_restored, images.shape)\nplt.figure(1, figsize=(4, 3.5))\nplt.clf()\nplt.subplots_adjust(left=.01, right=.99, bottom=.01, top=.91)\nfor i in range(4):\n plt.subplot(3, 4, i + 1)\n plt.imshow(images[i], cmap=plt.cm.gray, vmax=16, interpolation='nearest')\n plt.xticks(())\n plt.yticks(())\n if i == 1:\n plt.title('Original data')\n plt.subplot(3, 4, 4 + i + 1)\n plt.imshow(images_restored[i], cmap=plt.cm.gray, vmax=16,\n interpolation='nearest')\n if i == 1:\n plt.title('Agglomerated data')\n plt.xticks(())\n plt.yticks(())\n\nplt.subplot(3, 4, 10)\nplt.imshow(np.reshape(agglo.labels_, images[0].shape),\n interpolation='nearest', cmap=plt.cm.spectral)\nplt.xticks(())\nplt.yticks(())\nplt.title('Labels')\nplt.show()"
29+
"print(__doc__)\n\n# Code source: Ga\u00ebl Varoquaux\n# Modified for documentation by Jaques Grobler\n# License: BSD 3 clause\n\nimport numpy as np\nimport matplotlib.pyplot as plt\n\nfrom sklearn import datasets, cluster\nfrom sklearn.feature_extraction.image import grid_to_graph\n\ndigits = datasets.load_digits()\nimages = digits.images\nX = np.reshape(images, (len(images), -1))\nconnectivity = grid_to_graph(*images[0].shape)\n\nagglo = cluster.FeatureAgglomeration(connectivity=connectivity,\n n_clusters=32)\n\nagglo.fit(X)\nX_reduced = agglo.transform(X)\n\nX_restored = agglo.inverse_transform(X_reduced)\nimages_restored = np.reshape(X_restored, images.shape)\nplt.figure(1, figsize=(4, 3.5))\nplt.clf()\nplt.subplots_adjust(left=.01, right=.99, bottom=.01, top=.91)\nfor i in range(4):\n plt.subplot(3, 4, i + 1)\n plt.imshow(images[i], cmap=plt.cm.gray, vmax=16, interpolation='nearest')\n plt.xticks(())\n plt.yticks(())\n if i == 1:\n plt.title('Original data')\n plt.subplot(3, 4, 4 + i + 1)\n plt.imshow(images_restored[i], cmap=plt.cm.gray, vmax=16,\n interpolation='nearest')\n if i == 1:\n plt.title('Agglomerated data')\n plt.xticks(())\n plt.yticks(())\n\nplt.subplot(3, 4, 10)\nplt.imshow(np.reshape(agglo.labels_, images[0].shape),\n interpolation='nearest', cmap=plt.cm.nipy_spectral)\nplt.xticks(())\nplt.yticks(())\nplt.title('Labels')\nplt.show()"
3030
]
3131
}
3232
],

dev/_downloads/plot_digits_agglomeration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454

5555
plt.subplot(3, 4, 10)
5656
plt.imshow(np.reshape(agglo.labels_, images[0].shape),
57-
interpolation='nearest', cmap=plt.cm.spectral)
57+
interpolation='nearest', cmap=plt.cm.nipy_spectral)
5858
plt.xticks(())
5959
plt.yticks(())
6060
plt.title('Labels')

0 commit comments

Comments
 (0)