Skip to content

Commit 18a4887

Browse files
committed
Pushing the docs to dev/ for branch: main, commit 5f91dca9f0ded71df9f82e7f120f0263f15fb18e
1 parent 46f5137 commit 18a4887

File tree

1,559 files changed

+6282
-6221
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,559 files changed

+6282
-6221
lines changed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

dev/_downloads/a9a5b8f39dd796eae478e4c9c39cd207/plot_mds.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
},
1616
"outputs": [],
1717
"source": [
18-
"# Authors: The scikit-learn developers\n# SPDX-License-Identifier: BSD-3-Clause\n\nimport numpy as np\nfrom matplotlib import pyplot as plt\nfrom matplotlib.collections import LineCollection\n\nfrom sklearn import manifold\nfrom sklearn.decomposition import PCA\nfrom sklearn.metrics import euclidean_distances\n\nEPSILON = np.finfo(np.float32).eps\nn_samples = 20\nseed = np.random.RandomState(seed=3)\nX_true = seed.randint(0, 20, 2 * n_samples).astype(float)\nX_true = X_true.reshape((n_samples, 2))\n# Center the data\nX_true -= X_true.mean()\n\nsimilarities = euclidean_distances(X_true)\n\n# Add noise to the similarities\nnoise = np.random.rand(n_samples, n_samples)\nnoise = noise + noise.T\nnoise[np.arange(noise.shape[0]), np.arange(noise.shape[0])] = 0\nsimilarities += noise\n\nmds = manifold.MDS(\n n_components=2,\n max_iter=3000,\n eps=1e-9,\n random_state=seed,\n dissimilarity=\"precomputed\",\n n_jobs=1,\n)\npos = mds.fit(similarities).embedding_\n\nnmds = manifold.MDS(\n n_components=2,\n metric=False,\n max_iter=3000,\n eps=1e-12,\n dissimilarity=\"precomputed\",\n random_state=seed,\n n_jobs=1,\n n_init=1,\n)\nnpos = nmds.fit_transform(similarities, init=pos)\n\n# Rescale the data\npos *= np.sqrt((X_true**2).sum()) / np.sqrt((pos**2).sum())\nnpos *= np.sqrt((X_true**2).sum()) / np.sqrt((npos**2).sum())\n\n# Rotate the data\nclf = PCA(n_components=2)\nX_true = clf.fit_transform(X_true)\n\npos = clf.fit_transform(pos)\n\nnpos = clf.fit_transform(npos)\n\nfig = plt.figure(1)\nax = plt.axes([0.0, 0.0, 1.0, 1.0])\n\ns = 100\nplt.scatter(X_true[:, 0], X_true[:, 1], color=\"navy\", s=s, lw=0, label=\"True Position\")\nplt.scatter(pos[:, 0], pos[:, 1], color=\"turquoise\", s=s, lw=0, label=\"MDS\")\nplt.scatter(npos[:, 0], npos[:, 1], color=\"darkorange\", s=s, lw=0, label=\"NMDS\")\nplt.legend(scatterpoints=1, loc=\"best\", shadow=False)\n\nsimilarities = similarities.max() / (similarities + EPSILON) * 100\nnp.fill_diagonal(similarities, 0)\n# Plot the edges\nstart_idx, end_idx = np.where(pos)\n# a sequence of (*line0*, *line1*, *line2*), where::\n# linen = (x0, y0), (x1, y1), ... (xm, ym)\nsegments = [\n [X_true[i, :], X_true[j, :]] for i in range(len(pos)) for j in range(len(pos))\n]\nvalues = np.abs(similarities)\nlc = LineCollection(\n segments, zorder=0, cmap=plt.cm.Blues, norm=plt.Normalize(0, values.max())\n)\nlc.set_array(similarities.flatten())\nlc.set_linewidths(np.full(len(segments), 0.5))\nax.add_collection(lc)\n\nplt.show()"
18+
"# Authors: The scikit-learn developers\n# SPDX-License-Identifier: BSD-3-Clause\n\nimport numpy as np\nfrom matplotlib import pyplot as plt\nfrom matplotlib.collections import LineCollection\n\nfrom sklearn import manifold\nfrom sklearn.decomposition import PCA\nfrom sklearn.metrics import euclidean_distances\n\n# Generate the data\nEPSILON = np.finfo(np.float32).eps\nn_samples = 20\nrng = np.random.RandomState(seed=3)\nX_true = rng.randint(0, 20, 2 * n_samples).astype(float)\nX_true = X_true.reshape((n_samples, 2))\n\n# Center the data\nX_true -= X_true.mean()\n\n# Compute pairwise Euclidean distances\ndistances = euclidean_distances(X_true)\n\n# Add noise to the distances\nnoise = rng.rand(n_samples, n_samples)\nnoise = noise + noise.T\nnp.fill_diagonal(noise, 0)\ndistances += noise\n\nmds = manifold.MDS(\n n_components=2,\n max_iter=3000,\n eps=1e-9,\n random_state=42,\n dissimilarity=\"precomputed\",\n n_jobs=1,\n)\nX_mds = mds.fit(distances).embedding_\n\nnmds = manifold.MDS(\n n_components=2,\n metric=False,\n max_iter=3000,\n eps=1e-12,\n dissimilarity=\"precomputed\",\n random_state=42,\n n_jobs=1,\n n_init=1,\n)\nX_nmds = nmds.fit_transform(distances)\n\n# Rescale the data\nX_mds *= np.sqrt((X_true**2).sum()) / np.sqrt((X_mds**2).sum())\nX_nmds *= np.sqrt((X_true**2).sum()) / np.sqrt((X_nmds**2).sum())\n\n# Rotate the data\npca = PCA(n_components=2)\nX_true = pca.fit_transform(X_true)\nX_mds = pca.fit_transform(X_mds)\nX_nmds = pca.fit_transform(X_nmds)\n\n# Align the sign of PCs\nfor i in [0, 1]:\n if np.corrcoef(X_mds[:, i], X_true[:, i])[0, 1] < 0:\n X_mds[:, i] *= -1\n if np.corrcoef(X_nmds[:, i], X_true[:, i])[0, 1] < 0:\n X_nmds[:, i] *= -1\n\nfig = plt.figure(1)\nax = plt.axes([0.0, 0.0, 1.0, 1.0])\n\ns = 100\nplt.scatter(X_true[:, 0], X_true[:, 1], color=\"navy\", s=s, lw=0, label=\"True Position\")\nplt.scatter(X_mds[:, 0], X_mds[:, 1], color=\"turquoise\", s=s, lw=0, label=\"MDS\")\nplt.scatter(X_nmds[:, 0], X_nmds[:, 1], color=\"darkorange\", s=s, lw=0, label=\"NMDS\")\nplt.legend(scatterpoints=1, loc=\"best\", shadow=False)\n\n# Plot the edges\nstart_idx, end_idx = np.where(X_mds)\n# a sequence of (*line0*, *line1*, *line2*), where::\n# linen = (x0, y0), (x1, y1), ... (xm, ym)\nsegments = [\n [X_true[i, :], X_true[j, :]] for i in range(len(X_true)) for j in range(len(X_true))\n]\nedges = distances.max() / (distances + EPSILON) * 100\nnp.fill_diagonal(edges, 0)\nedges = np.abs(edges)\nlc = LineCollection(\n segments, zorder=0, cmap=plt.cm.Blues, norm=plt.Normalize(0, edges.max())\n)\nlc.set_array(edges.flatten())\nlc.set_linewidths(np.full(len(segments), 0.5))\nax.add_collection(lc)\n\nplt.show()"
1919
]
2020
}
2121
],
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

dev/_downloads/d64ed0728005aaeba058d3ccec909e73/plot_mds.py

+36-28
Original file line numberDiff line numberDiff line change
@@ -21,79 +21,87 @@
2121
from sklearn.decomposition import PCA
2222
from sklearn.metrics import euclidean_distances
2323

24+
# Generate the data
2425
EPSILON = np.finfo(np.float32).eps
2526
n_samples = 20
26-
seed = np.random.RandomState(seed=3)
27-
X_true = seed.randint(0, 20, 2 * n_samples).astype(float)
27+
rng = np.random.RandomState(seed=3)
28+
X_true = rng.randint(0, 20, 2 * n_samples).astype(float)
2829
X_true = X_true.reshape((n_samples, 2))
30+
2931
# Center the data
3032
X_true -= X_true.mean()
3133

32-
similarities = euclidean_distances(X_true)
34+
# Compute pairwise Euclidean distances
35+
distances = euclidean_distances(X_true)
3336

34-
# Add noise to the similarities
35-
noise = np.random.rand(n_samples, n_samples)
37+
# Add noise to the distances
38+
noise = rng.rand(n_samples, n_samples)
3639
noise = noise + noise.T
37-
noise[np.arange(noise.shape[0]), np.arange(noise.shape[0])] = 0
38-
similarities += noise
40+
np.fill_diagonal(noise, 0)
41+
distances += noise
3942

4043
mds = manifold.MDS(
4144
n_components=2,
4245
max_iter=3000,
4346
eps=1e-9,
44-
random_state=seed,
47+
random_state=42,
4548
dissimilarity="precomputed",
4649
n_jobs=1,
4750
)
48-
pos = mds.fit(similarities).embedding_
51+
X_mds = mds.fit(distances).embedding_
4952

5053
nmds = manifold.MDS(
5154
n_components=2,
5255
metric=False,
5356
max_iter=3000,
5457
eps=1e-12,
5558
dissimilarity="precomputed",
56-
random_state=seed,
59+
random_state=42,
5760
n_jobs=1,
5861
n_init=1,
5962
)
60-
npos = nmds.fit_transform(similarities, init=pos)
63+
X_nmds = nmds.fit_transform(distances)
6164

6265
# Rescale the data
63-
pos *= np.sqrt((X_true**2).sum()) / np.sqrt((pos**2).sum())
64-
npos *= np.sqrt((X_true**2).sum()) / np.sqrt((npos**2).sum())
66+
X_mds *= np.sqrt((X_true**2).sum()) / np.sqrt((X_mds**2).sum())
67+
X_nmds *= np.sqrt((X_true**2).sum()) / np.sqrt((X_nmds**2).sum())
6568

6669
# Rotate the data
67-
clf = PCA(n_components=2)
68-
X_true = clf.fit_transform(X_true)
69-
70-
pos = clf.fit_transform(pos)
71-
72-
npos = clf.fit_transform(npos)
70+
pca = PCA(n_components=2)
71+
X_true = pca.fit_transform(X_true)
72+
X_mds = pca.fit_transform(X_mds)
73+
X_nmds = pca.fit_transform(X_nmds)
74+
75+
# Align the sign of PCs
76+
for i in [0, 1]:
77+
if np.corrcoef(X_mds[:, i], X_true[:, i])[0, 1] < 0:
78+
X_mds[:, i] *= -1
79+
if np.corrcoef(X_nmds[:, i], X_true[:, i])[0, 1] < 0:
80+
X_nmds[:, i] *= -1
7381

7482
fig = plt.figure(1)
7583
ax = plt.axes([0.0, 0.0, 1.0, 1.0])
7684

7785
s = 100
7886
plt.scatter(X_true[:, 0], X_true[:, 1], color="navy", s=s, lw=0, label="True Position")
79-
plt.scatter(pos[:, 0], pos[:, 1], color="turquoise", s=s, lw=0, label="MDS")
80-
plt.scatter(npos[:, 0], npos[:, 1], color="darkorange", s=s, lw=0, label="NMDS")
87+
plt.scatter(X_mds[:, 0], X_mds[:, 1], color="turquoise", s=s, lw=0, label="MDS")
88+
plt.scatter(X_nmds[:, 0], X_nmds[:, 1], color="darkorange", s=s, lw=0, label="NMDS")
8189
plt.legend(scatterpoints=1, loc="best", shadow=False)
8290

83-
similarities = similarities.max() / (similarities + EPSILON) * 100
84-
np.fill_diagonal(similarities, 0)
8591
# Plot the edges
86-
start_idx, end_idx = np.where(pos)
92+
start_idx, end_idx = np.where(X_mds)
8793
# a sequence of (*line0*, *line1*, *line2*), where::
8894
# linen = (x0, y0), (x1, y1), ... (xm, ym)
8995
segments = [
90-
[X_true[i, :], X_true[j, :]] for i in range(len(pos)) for j in range(len(pos))
96+
[X_true[i, :], X_true[j, :]] for i in range(len(X_true)) for j in range(len(X_true))
9197
]
92-
values = np.abs(similarities)
98+
edges = distances.max() / (distances + EPSILON) * 100
99+
np.fill_diagonal(edges, 0)
100+
edges = np.abs(edges)
93101
lc = LineCollection(
94-
segments, zorder=0, cmap=plt.cm.Blues, norm=plt.Normalize(0, values.max())
102+
segments, zorder=0, cmap=plt.cm.Blues, norm=plt.Normalize(0, edges.max())
95103
)
96-
lc.set_array(similarities.flatten())
104+
lc.set_array(edges.flatten())
97105
lc.set_linewidths(np.full(len(segments), 0.5))
98106
ax.add_collection(lc)
99107

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

dev/_downloads/scikit-learn-docs.zip

-26.8 KB
Binary file not shown.
-661 Bytes
-137 Bytes

0 commit comments

Comments
 (0)