Skip to content

Commit 3167fa4

Browse files
committed
Pushing the docs to dev/ for branch: master, commit cee79b05b815eb370502cd9e36b944fa3efad06e
1 parent 02ba915 commit 3167fa4

File tree

1,088 files changed

+2955
-2958
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,088 files changed

+2955
-2958
lines changed
2 Bytes
Binary file not shown.
3 Bytes
Binary file not shown.

dev/_downloads/plot_nca_illustration.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-
"# License: BSD 3 clause\n\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom sklearn.datasets import make_classification\nfrom sklearn.neighbors import NeighborhoodComponentsAnalysis\nfrom matplotlib import cm\nfrom sklearn.utils.fixes import logsumexp\n\nprint(__doc__)\n\nn_neighbors = 1\nrandom_state = 0\n\n# Create a tiny data set of 9 samples from 3 classes\nX, y = make_classification(n_samples=9, n_features=2, n_informative=2,\n n_redundant=0, n_classes=3, n_clusters_per_class=1,\n class_sep=1.0, random_state=random_state)\n\n# Plot the points in the original space\nplt.figure()\nax = plt.gca()\n\n# Draw the graph nodes\nfor i in range(X.shape[0]):\n ax.text(X[i, 0], X[i, 1], str(i), va='center', ha='center')\n ax.scatter(X[i, 0], X[i, 1], s=300, c=cm.Set1(y[i]), alpha=0.4)\n\n\ndef p_i(X, i):\n diff_embedded = X[i] - X\n dist_embedded = np.einsum('ij,ij->i', diff_embedded,\n diff_embedded)\n dist_embedded[i] = np.inf\n\n # compute exponentiated distances (use the log-sum-exp trick to\n # avoid numerical instabilities\n exp_dist_embedded = np.exp(-dist_embedded -\n logsumexp(-dist_embedded))\n return exp_dist_embedded\n\n\ndef relate_point(X, i, ax):\n pt_i = X[i]\n for j, pt_j in enumerate(X):\n thickness = p_i(X, i)\n if i != j:\n line = ([pt_i[0], pt_j[0]], [pt_i[1], pt_j[1]])\n ax.plot(*line, c=cm.Set1(y[j]),\n linewidth=5*thickness[j])\n\n\n# we consider only point 3\ni = 3\n\n# Plot bonds linked to sample i in the original space\nrelate_point(X, i, ax)\nax.set_title(\"Original points\")\nax.axes.get_xaxis().set_visible(False)\nax.axes.get_yaxis().set_visible(False)\nax.axis('equal')\n\n# Learn an embedding with NeighborhoodComponentsAnalysis\nnca = NeighborhoodComponentsAnalysis(max_iter=30, random_state=random_state)\nnca = nca.fit(X, y)\n\n# Plot the points after transformation with NeighborhoodComponentsAnalysis\nplt.figure()\nax2 = plt.gca()\n\n# Get the embedding and find the new nearest neighbors\nX_embedded = nca.transform(X)\n\nrelate_point(X_embedded, i, ax2)\n\nfor i in range(len(X)):\n ax2.text(X_embedded[i, 0], X_embedded[i, 1], str(i),\n va='center', ha='center')\n ax2.scatter(X_embedded[i, 0], X_embedded[i, 1], s=300, c=cm.Set1(y[i]),\n alpha=0.4)\n\n# Make axes equal so that boundaries are displayed correctly as circles\nax2.set_title(\"NCA embedding\")\nax2.axes.get_xaxis().set_visible(False)\nax2.axes.get_yaxis().set_visible(False)\nax2.axis('equal')\nplt.show()"
29+
"# License: BSD 3 clause\n\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom sklearn.datasets import make_classification\nfrom sklearn.neighbors import NeighborhoodComponentsAnalysis\nfrom matplotlib import cm\nfrom sklearn.utils.fixes import logsumexp\n\nprint(__doc__)\n\nn_neighbors = 1\nrandom_state = 0\n\n# Create a tiny data set of 9 samples from 3 classes\nX, y = make_classification(n_samples=9, n_features=2, n_informative=2,\n n_redundant=0, n_classes=3, n_clusters_per_class=1,\n class_sep=1.0, random_state=random_state)\n\n# Plot the points in the original space\nplt.figure()\nax = plt.gca()\n\n# Draw the graph nodes\nfor i in range(X.shape[0]):\n ax.text(X[i, 0], X[i, 1], str(i), va='center', ha='center')\n ax.scatter(X[i, 0], X[i, 1], s=300, c=cm.Set1(y[[i]]), alpha=0.4)\n\ndef p_i(X, i):\n diff_embedded = X[i] - X\n dist_embedded = np.einsum('ij,ij->i', diff_embedded,\n diff_embedded)\n dist_embedded[i] = np.inf\n\n # compute exponentiated distances (use the log-sum-exp trick to\n # avoid numerical instabilities\n exp_dist_embedded = np.exp(-dist_embedded -\n logsumexp(-dist_embedded))\n return exp_dist_embedded\n\n\ndef relate_point(X, i, ax):\n pt_i = X[i]\n for j, pt_j in enumerate(X):\n thickness = p_i(X, i)\n if i != j:\n line = ([pt_i[0], pt_j[0]], [pt_i[1], pt_j[1]])\n ax.plot(*line, c=cm.Set1(y[j]),\n linewidth=5*thickness[j])\n\n\n# we consider only point 3\ni = 3\n\n# Plot bonds linked to sample i in the original space\nrelate_point(X, i, ax)\nax.set_title(\"Original points\")\nax.axes.get_xaxis().set_visible(False)\nax.axes.get_yaxis().set_visible(False)\nax.axis('equal')\n\n# Learn an embedding with NeighborhoodComponentsAnalysis\nnca = NeighborhoodComponentsAnalysis(max_iter=30, random_state=random_state)\nnca = nca.fit(X, y)\n\n# Plot the points after transformation with NeighborhoodComponentsAnalysis\nplt.figure()\nax2 = plt.gca()\n\n# Get the embedding and find the new nearest neighbors\nX_embedded = nca.transform(X)\n\nrelate_point(X_embedded, i, ax2)\n\nfor i in range(len(X)):\n ax2.text(X_embedded[i, 0], X_embedded[i, 1], str(i),\n va='center', ha='center')\n ax2.scatter(X_embedded[i, 0], X_embedded[i, 1], s=300, c=cm.Set1(y[[i]]),\n alpha=0.4)\n\n# Make axes equal so that boundaries are displayed correctly as circles\nax2.set_title(\"NCA embedding\")\nax2.axes.get_xaxis().set_visible(False)\nax2.axes.get_yaxis().set_visible(False)\nax2.axis('equal')\nplt.show()"
3030
]
3131
}
3232
],

dev/_downloads/plot_nca_illustration.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@
3535
# Draw the graph nodes
3636
for i in range(X.shape[0]):
3737
ax.text(X[i, 0], X[i, 1], str(i), va='center', ha='center')
38-
ax.scatter(X[i, 0], X[i, 1], s=300, c=cm.Set1(y[i]), alpha=0.4)
39-
38+
ax.scatter(X[i, 0], X[i, 1], s=300, c=cm.Set1(y[[i]]), alpha=0.4)
4039

4140
def p_i(X, i):
4241
diff_embedded = X[i] - X
@@ -87,7 +86,7 @@ def relate_point(X, i, ax):
8786
for i in range(len(X)):
8887
ax2.text(X_embedded[i, 0], X_embedded[i, 1], str(i),
8988
va='center', ha='center')
90-
ax2.scatter(X_embedded[i, 0], X_embedded[i, 1], s=300, c=cm.Set1(y[i]),
89+
ax2.scatter(X_embedded[i, 0], X_embedded[i, 1], s=300, c=cm.Set1(y[[i]]),
9190
alpha=0.4)
9291

9392
# Make axes equal so that boundaries are displayed correctly as circles

dev/_downloads/scikit-learn-docs.pdf

-10.8 KB
Binary file not shown.

dev/_images/iris.png

0 Bytes
-82 Bytes
-82 Bytes
-940 Bytes
-940 Bytes

0 commit comments

Comments
 (0)