Skip to content

Commit 86f3ce5

Browse files
committed
Pushing the docs to dev/ for branch: main, commit 03fdd0271ee54e55361e342cef5ee01154f8dacc
1 parent 0eaace6 commit 86f3ce5

File tree

1,223 files changed

+4637
-4312
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,223 files changed

+4637
-4312
lines changed
Binary file not shown.
Binary file not shown.

dev/_downloads/9cdba5635a180cdcca7d23b9cf18ffac/plot_segmentation_toy.py

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,10 @@
3030
# Gael Varoquaux <gael.varoquaux@normalesup.org>
3131
# License: BSD 3 clause
3232

33+
# %%
34+
# Generate the data
35+
# -----------------
3336
import numpy as np
34-
import matplotlib.pyplot as plt
35-
36-
from sklearn.feature_extraction import image
37-
from sklearn.cluster import spectral_clustering
3837

3938
l = 100
4039
x, y = np.indices((l, l))
@@ -51,8 +50,9 @@
5150
circle3 = (x - center3[0]) ** 2 + (y - center3[1]) ** 2 < radius3**2
5251
circle4 = (x - center4[0]) ** 2 + (y - center4[1]) ** 2 < radius4**2
5352

54-
# #############################################################################
55-
# 4 circles
53+
# %%
54+
# Plotting four circles
55+
# ---------------------
5656
img = circle1 + circle2 + circle3 + circle4
5757

5858
# We use a mask that limits to the foreground: the problem that we are
@@ -63,25 +63,41 @@
6363
img = img.astype(float)
6464
img += 1 + 0.2 * np.random.randn(*img.shape)
6565

66+
# %%
6667
# Convert the image into a graph with the value of the gradient on the
6768
# edges.
69+
from sklearn.feature_extraction import image
70+
6871
graph = image.img_to_graph(img, mask=mask)
6972

70-
# Take a decreasing function of the gradient: we take it weakly
71-
# dependent from the gradient the segmentation is close to a voronoi
73+
# %%
74+
# Take a decreasing function of the gradient resulting in a segmentation
75+
# that is close to a Voronoi partition
7276
graph.data = np.exp(-graph.data / graph.data.std())
7377

74-
# Force the solver to be arpack, since amg is numerically
75-
# unstable on this example
78+
# %%
79+
# Here we perform spectral clustering using the arpack solver since amg is
80+
# numerically unstable on this example. We then plot the results.
81+
from sklearn.cluster import spectral_clustering
82+
import matplotlib.pyplot as plt
83+
7684
labels = spectral_clustering(graph, n_clusters=4, eigen_solver="arpack")
7785
label_im = np.full(mask.shape, -1.0)
7886
label_im[mask] = labels
7987

80-
plt.matshow(img)
81-
plt.matshow(label_im)
88+
fig, axs = plt.subplots(nrows=1, ncols=2, figsize=(10, 5))
89+
axs[0].matshow(img)
90+
axs[1].matshow(label_im)
91+
92+
plt.show()
93+
94+
# %%
95+
# Plotting two circles
96+
# --------------------
97+
# Here we repeat the above process but only consider the first two circles
98+
# we generated. Note that this results in a cleaner separation between the
99+
# circles as the region sizes are easier to balance in this case.
82100

83-
# #############################################################################
84-
# 2 circles
85101
img = circle1 + circle2
86102
mask = img.astype(bool)
87103
img = img.astype(float)
@@ -95,7 +111,8 @@
95111
label_im = np.full(mask.shape, -1.0)
96112
label_im[mask] = labels
97113

98-
plt.matshow(img)
99-
plt.matshow(label_im)
114+
fig, axs = plt.subplots(nrows=1, ncols=2, figsize=(10, 5))
115+
axs[0].matshow(img)
116+
axs[1].matshow(label_im)
100117

101118
plt.show()

dev/_downloads/e7311e6599ab6ff3129117a6d8c302ec/plot_segmentation_toy.ipynb

Lines changed: 109 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,115 @@
2626
},
2727
"outputs": [],
2828
"source": [
29-
"# Authors: Emmanuelle Gouillart <emmanuelle.gouillart@normalesup.org>\n# Gael Varoquaux <gael.varoquaux@normalesup.org>\n# License: BSD 3 clause\n\nimport numpy as np\nimport matplotlib.pyplot as plt\n\nfrom sklearn.feature_extraction import image\nfrom sklearn.cluster import spectral_clustering\n\nl = 100\nx, y = np.indices((l, l))\n\ncenter1 = (28, 24)\ncenter2 = (40, 50)\ncenter3 = (67, 58)\ncenter4 = (24, 70)\n\nradius1, radius2, radius3, radius4 = 16, 14, 15, 14\n\ncircle1 = (x - center1[0]) ** 2 + (y - center1[1]) ** 2 < radius1**2\ncircle2 = (x - center2[0]) ** 2 + (y - center2[1]) ** 2 < radius2**2\ncircle3 = (x - center3[0]) ** 2 + (y - center3[1]) ** 2 < radius3**2\ncircle4 = (x - center4[0]) ** 2 + (y - center4[1]) ** 2 < radius4**2\n\n# #############################################################################\n# 4 circles\nimg = circle1 + circle2 + circle3 + circle4\n\n# We use a mask that limits to the foreground: the problem that we are\n# interested in here is not separating the objects from the background,\n# but separating them one from the other.\nmask = img.astype(bool)\n\nimg = img.astype(float)\nimg += 1 + 0.2 * np.random.randn(*img.shape)\n\n# Convert the image into a graph with the value of the gradient on the\n# edges.\ngraph = image.img_to_graph(img, mask=mask)\n\n# Take a decreasing function of the gradient: we take it weakly\n# dependent from the gradient the segmentation is close to a voronoi\ngraph.data = np.exp(-graph.data / graph.data.std())\n\n# Force the solver to be arpack, since amg is numerically\n# unstable on this example\nlabels = spectral_clustering(graph, n_clusters=4, eigen_solver=\"arpack\")\nlabel_im = np.full(mask.shape, -1.0)\nlabel_im[mask] = labels\n\nplt.matshow(img)\nplt.matshow(label_im)\n\n# #############################################################################\n# 2 circles\nimg = circle1 + circle2\nmask = img.astype(bool)\nimg = img.astype(float)\n\nimg += 1 + 0.2 * np.random.randn(*img.shape)\n\ngraph = image.img_to_graph(img, mask=mask)\ngraph.data = np.exp(-graph.data / graph.data.std())\n\nlabels = spectral_clustering(graph, n_clusters=2, eigen_solver=\"arpack\")\nlabel_im = np.full(mask.shape, -1.0)\nlabel_im[mask] = labels\n\nplt.matshow(img)\nplt.matshow(label_im)\n\nplt.show()"
29+
"# Authors: Emmanuelle Gouillart <emmanuelle.gouillart@normalesup.org>\n# Gael Varoquaux <gael.varoquaux@normalesup.org>\n# License: BSD 3 clause"
30+
]
31+
},
32+
{
33+
"cell_type": "markdown",
34+
"metadata": {},
35+
"source": [
36+
"## Generate the data\n\n"
37+
]
38+
},
39+
{
40+
"cell_type": "code",
41+
"execution_count": null,
42+
"metadata": {
43+
"collapsed": false
44+
},
45+
"outputs": [],
46+
"source": [
47+
"import numpy as np\n\nl = 100\nx, y = np.indices((l, l))\n\ncenter1 = (28, 24)\ncenter2 = (40, 50)\ncenter3 = (67, 58)\ncenter4 = (24, 70)\n\nradius1, radius2, radius3, radius4 = 16, 14, 15, 14\n\ncircle1 = (x - center1[0]) ** 2 + (y - center1[1]) ** 2 < radius1**2\ncircle2 = (x - center2[0]) ** 2 + (y - center2[1]) ** 2 < radius2**2\ncircle3 = (x - center3[0]) ** 2 + (y - center3[1]) ** 2 < radius3**2\ncircle4 = (x - center4[0]) ** 2 + (y - center4[1]) ** 2 < radius4**2"
48+
]
49+
},
50+
{
51+
"cell_type": "markdown",
52+
"metadata": {},
53+
"source": [
54+
"## Plotting four circles\n\n"
55+
]
56+
},
57+
{
58+
"cell_type": "code",
59+
"execution_count": null,
60+
"metadata": {
61+
"collapsed": false
62+
},
63+
"outputs": [],
64+
"source": [
65+
"img = circle1 + circle2 + circle3 + circle4\n\n# We use a mask that limits to the foreground: the problem that we are\n# interested in here is not separating the objects from the background,\n# but separating them one from the other.\nmask = img.astype(bool)\n\nimg = img.astype(float)\nimg += 1 + 0.2 * np.random.randn(*img.shape)"
66+
]
67+
},
68+
{
69+
"cell_type": "markdown",
70+
"metadata": {},
71+
"source": [
72+
"Convert the image into a graph with the value of the gradient on the\nedges.\n\n"
73+
]
74+
},
75+
{
76+
"cell_type": "code",
77+
"execution_count": null,
78+
"metadata": {
79+
"collapsed": false
80+
},
81+
"outputs": [],
82+
"source": [
83+
"from sklearn.feature_extraction import image\n\ngraph = image.img_to_graph(img, mask=mask)"
84+
]
85+
},
86+
{
87+
"cell_type": "markdown",
88+
"metadata": {},
89+
"source": [
90+
"Take a decreasing function of the gradient resulting in a segmentation\nthat is close to a Voronoi partition\n\n"
91+
]
92+
},
93+
{
94+
"cell_type": "code",
95+
"execution_count": null,
96+
"metadata": {
97+
"collapsed": false
98+
},
99+
"outputs": [],
100+
"source": [
101+
"graph.data = np.exp(-graph.data / graph.data.std())"
102+
]
103+
},
104+
{
105+
"cell_type": "markdown",
106+
"metadata": {},
107+
"source": [
108+
"Here we perform spectral clustering using the arpack solver since amg is\nnumerically unstable on this example. We then plot the results.\n\n"
109+
]
110+
},
111+
{
112+
"cell_type": "code",
113+
"execution_count": null,
114+
"metadata": {
115+
"collapsed": false
116+
},
117+
"outputs": [],
118+
"source": [
119+
"from sklearn.cluster import spectral_clustering\nimport matplotlib.pyplot as plt\n\nlabels = spectral_clustering(graph, n_clusters=4, eigen_solver=\"arpack\")\nlabel_im = np.full(mask.shape, -1.0)\nlabel_im[mask] = labels\n\nfig, axs = plt.subplots(nrows=1, ncols=2, figsize=(10, 5))\naxs[0].matshow(img)\naxs[1].matshow(label_im)\n\nplt.show()"
120+
]
121+
},
122+
{
123+
"cell_type": "markdown",
124+
"metadata": {},
125+
"source": [
126+
"## Plotting two circles\nHere we repeat the above process but only consider the first two circles\nwe generated. Note that this results in a cleaner separation between the\ncircles as the region sizes are easier to balance in this case.\n\n"
127+
]
128+
},
129+
{
130+
"cell_type": "code",
131+
"execution_count": null,
132+
"metadata": {
133+
"collapsed": false
134+
},
135+
"outputs": [],
136+
"source": [
137+
"img = circle1 + circle2\nmask = img.astype(bool)\nimg = img.astype(float)\n\nimg += 1 + 0.2 * np.random.randn(*img.shape)\n\ngraph = image.img_to_graph(img, mask=mask)\ngraph.data = np.exp(-graph.data / graph.data.std())\n\nlabels = spectral_clustering(graph, n_clusters=2, eigen_solver=\"arpack\")\nlabel_im = np.full(mask.shape, -1.0)\nlabel_im[mask] = labels\n\nfig, axs = plt.subplots(nrows=1, ncols=2, figsize=(10, 5))\naxs[0].matshow(img)\naxs[1].matshow(label_im)\n\nplt.show()"
30138
]
31139
}
32140
],

dev/_downloads/scikit-learn-docs.zip

-31.7 KB
Binary file not shown.
-171 Bytes
155 Bytes
-124 Bytes
-51 Bytes
-81 Bytes
-676 Bytes
-17 Bytes
-86 Bytes
-5 Bytes
55 Bytes
49 Bytes
-69 Bytes
2.89 KB
90 Bytes
48 Bytes
189 Bytes
-93 Bytes
67 Bytes
-2 Bytes
51 Bytes
47 Bytes
-7 Bytes
135 Bytes
-200 Bytes
-906 Bytes
Binary file not shown.
Binary file not shown.
-206 Bytes
-54 Bytes
-110 Bytes

dev/_sources/auto_examples/applications/plot_cyclical_feature_engineering.rst.txt

Lines changed: 1 addition & 1 deletion

dev/_sources/auto_examples/applications/plot_digits_denoising.rst.txt

Lines changed: 1 addition & 1 deletion

dev/_sources/auto_examples/applications/plot_face_recognition.rst.txt

Lines changed: 5 additions & 5 deletions

dev/_sources/auto_examples/applications/plot_model_complexity_influence.rst.txt

Lines changed: 14 additions & 14 deletions

0 commit comments

Comments
 (0)