Skip to content

Commit 2a8189a

Browse files
committed
Pushing the docs to dev/ for branch: master, commit bd0fc236e00c57b9a5212e8802c325c99af7b1b4
1 parent 9d47110 commit 2a8189a

File tree

981 files changed

+3184
-3361
lines changed

Some content is hidden

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

981 files changed

+3184
-3361
lines changed
-1.18 KB
Binary file not shown.
-1.13 KB
Binary file not shown.

dev/_downloads/plot_face_compress.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\n# Code source: Ga\u00ebl Varoquaux\n# Modified for documentation by Jaques Grobler\n# License: BSD 3 clause\n\nimport numpy as np\nimport scipy as sp\nimport matplotlib.pyplot as plt\n\nfrom sklearn import cluster\nfrom sklearn.utils.testing import SkipTest\nfrom sklearn.utils.fixes import sp_version\n\nif sp_version < (0, 12):\n raise SkipTest(\"Skipping because SciPy version earlier than 0.12.0 and \"\n \"thus does not include the scipy.misc.face() image.\")\n\ntry:\n face = sp.face(gray=True)\nexcept AttributeError:\n # Newer versions of scipy have face in misc\n from scipy import misc\n face = misc.face(gray=True)\n\nn_clusters = 5\nnp.random.seed(0)\n \nX = face.reshape((-1, 1)) # We need an (n_sample, n_feature) array\nk_means = cluster.KMeans(n_clusters=n_clusters, n_init=4)\nk_means.fit(X)\nvalues = k_means.cluster_centers_.squeeze()\nlabels = k_means.labels_\n\n# create an array from labels and values\nface_compressed = np.choose(labels, values)\nface_compressed.shape = face.shape\n\nvmin = face.min()\nvmax = face.max()\n\n# original face\nplt.figure(1, figsize=(3, 2.2))\nplt.imshow(face, cmap=plt.cm.gray, vmin=vmin, vmax=256)\n\n# compressed face\nplt.figure(2, figsize=(3, 2.2))\nplt.imshow(face_compressed, cmap=plt.cm.gray, vmin=vmin, vmax=vmax)\n\n# equal bins face\nregular_values = np.linspace(0, 256, n_clusters + 1)\nregular_labels = np.searchsorted(regular_values, face) - 1\nregular_values = .5 * (regular_values[1:] + regular_values[:-1]) # mean\nregular_face = np.choose(regular_labels.ravel(), regular_values, mode=\"clip\")\nregular_face.shape = face.shape\nplt.figure(3, figsize=(3, 2.2))\nplt.imshow(regular_face, cmap=plt.cm.gray, vmin=vmin, vmax=vmax)\n\n# histogram\nplt.figure(4, figsize=(3, 2.2))\nplt.clf()\nplt.axes([.01, .01, .98, .98])\nplt.hist(X, bins=256, color='.5', edgecolor='.5')\nplt.yticks(())\nplt.xticks(regular_values)\nvalues = np.sort(values)\nfor center_1, center_2 in zip(values[:-1], values[1:]):\n plt.axvline(.5 * (center_1 + center_2), color='b')\n\nfor center_1, center_2 in zip(regular_values[:-1], regular_values[1:]):\n plt.axvline(.5 * (center_1 + center_2), color='b', linestyle='--')\n\nplt.show()"
29+
"print(__doc__)\n\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 scipy as sp\nimport matplotlib.pyplot as plt\n\nfrom sklearn import cluster\n\n\ntry: # SciPy >= 0.16 have face in misc\n from scipy.misc import face\n face = face(gray=True)\nexcept ImportError:\n face = sp.face(gray=True)\n\nn_clusters = 5\nnp.random.seed(0)\n\nX = face.reshape((-1, 1)) # We need an (n_sample, n_feature) array\nk_means = cluster.KMeans(n_clusters=n_clusters, n_init=4)\nk_means.fit(X)\nvalues = k_means.cluster_centers_.squeeze()\nlabels = k_means.labels_\n\n# create an array from labels and values\nface_compressed = np.choose(labels, values)\nface_compressed.shape = face.shape\n\nvmin = face.min()\nvmax = face.max()\n\n# original face\nplt.figure(1, figsize=(3, 2.2))\nplt.imshow(face, cmap=plt.cm.gray, vmin=vmin, vmax=256)\n\n# compressed face\nplt.figure(2, figsize=(3, 2.2))\nplt.imshow(face_compressed, cmap=plt.cm.gray, vmin=vmin, vmax=vmax)\n\n# equal bins face\nregular_values = np.linspace(0, 256, n_clusters + 1)\nregular_labels = np.searchsorted(regular_values, face) - 1\nregular_values = .5 * (regular_values[1:] + regular_values[:-1]) # mean\nregular_face = np.choose(regular_labels.ravel(), regular_values, mode=\"clip\")\nregular_face.shape = face.shape\nplt.figure(3, figsize=(3, 2.2))\nplt.imshow(regular_face, cmap=plt.cm.gray, vmin=vmin, vmax=vmax)\n\n# histogram\nplt.figure(4, figsize=(3, 2.2))\nplt.clf()\nplt.axes([.01, .01, .98, .98])\nplt.hist(X, bins=256, color='.5', edgecolor='.5')\nplt.yticks(())\nplt.xticks(regular_values)\nvalues = np.sort(values)\nfor center_1, center_2 in zip(values[:-1], values[1:]):\n plt.axvline(.5 * (center_1 + center_2), color='b')\n\nfor center_1, center_2 in zip(regular_values[:-1], regular_values[1:]):\n plt.axvline(.5 * (center_1 + center_2), color='b', linestyle='--')\n\nplt.show()"
3030
]
3131
}
3232
],

dev/_downloads/plot_face_compress.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,17 @@
2323
import matplotlib.pyplot as plt
2424

2525
from sklearn import cluster
26-
from sklearn.utils.testing import SkipTest
27-
from sklearn.utils.fixes import sp_version
2826

29-
if sp_version < (0, 12):
30-
raise SkipTest("Skipping because SciPy version earlier than 0.12.0 and "
31-
"thus does not include the scipy.misc.face() image.")
3227

33-
try:
28+
try: # SciPy >= 0.16 have face in misc
29+
from scipy.misc import face
30+
face = face(gray=True)
31+
except ImportError:
3432
face = sp.face(gray=True)
35-
except AttributeError:
36-
# Newer versions of scipy have face in misc
37-
from scipy import misc
38-
face = misc.face(gray=True)
3933

4034
n_clusters = 5
4135
np.random.seed(0)
42-
36+
4337
X = face.reshape((-1, 1)) # We need an (n_sample, n_feature) array
4438
k_means = cluster.KMeans(n_clusters=n_clusters, n_init=4)
4539
k_means.fit(X)

dev/_downloads/plot_face_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-
"print(__doc__)\n\n# Author: Gael Varoquaux <[email protected]>, Brian Cheung\n# License: BSD 3 clause\n\nimport time\n\nimport numpy as np\nimport scipy as sp\nimport matplotlib.pyplot as plt\n\nfrom sklearn.feature_extraction import image\nfrom sklearn.cluster import spectral_clustering\nfrom sklearn.utils.testing import SkipTest\nfrom sklearn.utils.fixes import sp_version\n\nif sp_version < (0, 12):\n raise SkipTest(\"Skipping because SciPy version earlier than 0.12.0 and \"\n \"thus does not include the scipy.misc.face() image.\")\n\n\n# load the raccoon face as a numpy array\ntry:\n face = sp.face(gray=True)\nexcept AttributeError:\n # Newer versions of scipy have face in misc\n from scipy import misc\n face = misc.face(gray=True)\n\n# Resize it to 10% of the original size to speed up the processing\nface = sp.misc.imresize(face, 0.10) / 255.\n\n# Convert the image into a graph with the value of the gradient on the\n# edges.\ngraph = image.img_to_graph(face)\n\n# Take a decreasing function of the gradient: an exponential\n# The smaller beta is, the more independent the segmentation is of the\n# actual image. For beta=1, the segmentation is close to a voronoi\nbeta = 5\neps = 1e-6\ngraph.data = np.exp(-beta * graph.data / graph.data.std()) + eps\n\n# Apply spectral clustering (this step goes much faster if you have pyamg\n# installed)\nN_REGIONS = 25"
29+
"print(__doc__)\n\n# Author: Gael Varoquaux <[email protected]>, Brian Cheung\n# License: BSD 3 clause\n\nimport time\n\nimport numpy as np\nimport scipy as sp\nimport matplotlib.pyplot as plt\n\nfrom sklearn.feature_extraction import image\nfrom sklearn.cluster import spectral_clustering\n\n\n# load the raccoon face as a numpy array\ntry: # SciPy >= 0.16 have face in misc\n from scipy.misc import face\n face = face(gray=True)\nexcept ImportError:\n face = sp.face(gray=True)\n\n# Resize it to 10% of the original size to speed up the processing\nface = sp.misc.imresize(face, 0.10) / 255.\n\n# Convert the image into a graph with the value of the gradient on the\n# edges.\ngraph = image.img_to_graph(face)\n\n# Take a decreasing function of the gradient: an exponential\n# The smaller beta is, the more independent the segmentation is of the\n# actual image. For beta=1, the segmentation is close to a voronoi\nbeta = 5\neps = 1e-6\ngraph.data = np.exp(-beta * graph.data / graph.data.std()) + eps\n\n# Apply spectral clustering (this step goes much faster if you have pyamg\n# installed)\nN_REGIONS = 25"
3030
]
3131
},
3232
{

dev/_downloads/plot_face_segmentation.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,14 @@
3030

3131
from sklearn.feature_extraction import image
3232
from sklearn.cluster import spectral_clustering
33-
from sklearn.utils.testing import SkipTest
34-
from sklearn.utils.fixes import sp_version
35-
36-
if sp_version < (0, 12):
37-
raise SkipTest("Skipping because SciPy version earlier than 0.12.0 and "
38-
"thus does not include the scipy.misc.face() image.")
3933

4034

4135
# load the raccoon face as a numpy array
42-
try:
36+
try: # SciPy >= 0.16 have face in misc
37+
from scipy.misc import face
38+
face = face(gray=True)
39+
except ImportError:
4340
face = sp.face(gray=True)
44-
except AttributeError:
45-
# Newer versions of scipy have face in misc
46-
from scipy import misc
47-
face = misc.face(gray=True)
4841

4942
# Resize it to 10% of the original size to speed up the processing
5043
face = sp.misc.imresize(face, 0.10) / 255.

dev/_downloads/plot_face_ward_segmentation.ipynb

Lines changed: 2 additions & 2 deletions
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\nimport scipy as sp\n\nimport matplotlib.pyplot as plt\n\nfrom sklearn.feature_extraction.image import grid_to_graph\nfrom sklearn.cluster import AgglomerativeClustering\nfrom sklearn.utils.testing import SkipTest\nfrom sklearn.utils.fixes import sp_version\n\nif sp_version < (0, 12):\n raise SkipTest(\"Skipping because SciPy version earlier than 0.12.0 and \"\n \"thus does not include the scipy.misc.face() image.\")"
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\nimport scipy as sp\n\nimport matplotlib.pyplot as plt\n\nfrom sklearn.feature_extraction.image import grid_to_graph\nfrom sklearn.cluster import AgglomerativeClustering"
3030
]
3131
},
3232
{
@@ -44,7 +44,7 @@
4444
},
4545
"outputs": [],
4646
"source": [
47-
"try:\n face = sp.face(gray=True)\nexcept AttributeError:\n # Newer versions of scipy have face in misc\n from scipy import misc\n face = misc.face(gray=True)\n\n# Resize it to 10% of the original size to speed up the processing\nface = sp.misc.imresize(face, 0.10) / 255.\n\nX = np.reshape(face, (-1, 1))"
47+
"try: # SciPy >= 0.16 have face in misc\n from scipy.misc import face\n face = face(gray=True)\nexcept ImportError:\n face = sp.face(gray=True)\n\n# Resize it to 10% of the original size to speed up the processing\nface = sp.misc.imresize(face, 0.10) / 255.\n\nX = np.reshape(face, (-1, 1))"
4848
]
4949
},
5050
{

dev/_downloads/plot_face_ward_segmentation.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,15 @@
2323

2424
from sklearn.feature_extraction.image import grid_to_graph
2525
from sklearn.cluster import AgglomerativeClustering
26-
from sklearn.utils.testing import SkipTest
27-
from sklearn.utils.fixes import sp_version
28-
29-
if sp_version < (0, 12):
30-
raise SkipTest("Skipping because SciPy version earlier than 0.12.0 and "
31-
"thus does not include the scipy.misc.face() image.")
3226

3327

3428
###############################################################################
3529
# Generate data
36-
try:
30+
try: # SciPy >= 0.16 have face in misc
31+
from scipy.misc import face
32+
face = face(gray=True)
33+
except ImportError:
3734
face = sp.face(gray=True)
38-
except AttributeError:
39-
# Newer versions of scipy have face in misc
40-
from scipy import misc
41-
face = misc.face(gray=True)
4235

4336
# Resize it to 10% of the original size to speed up the processing
4437
face = sp.misc.imresize(face, 0.10) / 255.

dev/_downloads/plot_image_denoising.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
},
2727
"outputs": [],
2828
"source": [
29-
"print(__doc__)\n\nfrom time import time\n\nimport matplotlib.pyplot as plt\nimport numpy as np\nimport scipy as sp\n\nfrom sklearn.decomposition import MiniBatchDictionaryLearning\nfrom sklearn.feature_extraction.image import extract_patches_2d\nfrom sklearn.feature_extraction.image import reconstruct_from_patches_2d\nfrom sklearn.utils.testing import SkipTest\nfrom sklearn.utils.fixes import sp_version\n\nif sp_version < (0, 12):\n raise SkipTest(\"Skipping because SciPy version earlier than 0.12.0 and \"\n \"thus does not include the scipy.misc.face() image.\")"
29+
"print(__doc__)\n\nfrom time import time\n\nimport matplotlib.pyplot as plt\nimport numpy as np\nimport scipy as sp\n\nfrom sklearn.decomposition import MiniBatchDictionaryLearning\nfrom sklearn.feature_extraction.image import extract_patches_2d\nfrom sklearn.feature_extraction.image import reconstruct_from_patches_2d"
3030
]
3131
},
3232
{
@@ -37,7 +37,7 @@
3737
},
3838
"outputs": [],
3939
"source": [
40-
"try:\n from scipy import misc\n face = misc.face(gray=True)\nexcept AttributeError:\n # Old versions of scipy have face in the top level package\n face = sp.face(gray=True)\n\n# Convert from uint8 representation with values between 0 and 255 to\n# a floating point representation with values between 0 and 1.\nface = face / 255\n\n# downsample for higher speed\nface = face[::2, ::2] + face[1::2, ::2] + face[::2, 1::2] + face[1::2, 1::2]\nface /= 4.0\nheight, width = face.shape\n\n# Distort the right half of the image\nprint('Distorting image...')\ndistorted = face.copy()\ndistorted[:, width // 2:] += 0.075 * np.random.randn(height, width // 2)\n\n# Extract all reference patches from the left half of the image\nprint('Extracting reference patches...')\nt0 = time()\npatch_size = (7, 7)\ndata = extract_patches_2d(distorted[:, :width // 2], patch_size)\ndata = data.reshape(data.shape[0], -1)\ndata -= np.mean(data, axis=0)\ndata /= np.std(data, axis=0)\nprint('done in %.2fs.' % (time() - t0))"
40+
"try: # SciPy >= 0.16 have face in misc\n from scipy.misc import face\n face = face(gray=True)\nexcept ImportError:\n face = sp.face(gray=True)\n\n# Convert from uint8 representation with values between 0 and 255 to\n# a floating point representation with values between 0 and 1.\nface = face / 255\n\n# downsample for higher speed\nface = face[::2, ::2] + face[1::2, ::2] + face[::2, 1::2] + face[1::2, 1::2]\nface /= 4.0\nheight, width = face.shape\n\n# Distort the right half of the image\nprint('Distorting image...')\ndistorted = face.copy()\ndistorted[:, width // 2:] += 0.075 * np.random.randn(height, width // 2)\n\n# Extract all reference patches from the left half of the image\nprint('Extracting reference patches...')\nt0 = time()\npatch_size = (7, 7)\ndata = extract_patches_2d(distorted[:, :width // 2], patch_size)\ndata = data.reshape(data.shape[0], -1)\ndata -= np.mean(data, axis=0)\ndata /= np.std(data, axis=0)\nprint('done in %.2fs.' % (time() - t0))"
4141
]
4242
},
4343
{

dev/_downloads/plot_image_denoising.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,13 @@
4242
from sklearn.decomposition import MiniBatchDictionaryLearning
4343
from sklearn.feature_extraction.image import extract_patches_2d
4444
from sklearn.feature_extraction.image import reconstruct_from_patches_2d
45-
from sklearn.utils.testing import SkipTest
46-
from sklearn.utils.fixes import sp_version
4745

48-
if sp_version < (0, 12):
49-
raise SkipTest("Skipping because SciPy version earlier than 0.12.0 and "
50-
"thus does not include the scipy.misc.face() image.")
5146

5247
###############################################################################
53-
try:
54-
from scipy import misc
55-
face = misc.face(gray=True)
56-
except AttributeError:
57-
# Old versions of scipy have face in the top level package
48+
try: # SciPy >= 0.16 have face in misc
49+
from scipy.misc import face
50+
face = face(gray=True)
51+
except ImportError:
5852
face = sp.face(gray=True)
5953

6054
# Convert from uint8 representation with values between 0 and 255 to

0 commit comments

Comments
 (0)