Skip to content

Commit 1142b02

Browse files
committed
Pushing the docs to dev/ for branch: main, commit 0852d7bc9cff705d50d76c93c9280d94f4cd647a
1 parent 1a5bd51 commit 1142b02

File tree

699 files changed

+2219
-2219
lines changed

Some content is hidden

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

699 files changed

+2219
-2219
lines changed
Binary file not shown.

dev/_downloads/54c7ea3b3671861fbfb2161a6f0ab6d0/plot_nca_classification.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 matplotlib.colors import ListedColormap\nfrom sklearn import datasets\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.preprocessing import StandardScaler\nfrom sklearn.neighbors import KNeighborsClassifier, NeighborhoodComponentsAnalysis\nfrom sklearn.pipeline import Pipeline\n\n\nn_neighbors = 1\n\ndataset = datasets.load_iris()\nX, y = dataset.data, dataset.target\n\n# we only take two features. We could avoid this ugly\n# slicing by using a two-dim dataset\nX = X[:, [0, 2]]\n\nX_train, X_test, y_train, y_test = train_test_split(\n X, y, stratify=y, test_size=0.7, random_state=42\n)\n\nh = 0.05 # step size in the mesh\n\n# Create color maps\ncmap_light = ListedColormap([\"#FFAAAA\", \"#AAFFAA\", \"#AAAAFF\"])\ncmap_bold = ListedColormap([\"#FF0000\", \"#00FF00\", \"#0000FF\"])\n\nnames = [\"KNN\", \"NCA, KNN\"]\n\nclassifiers = [\n Pipeline(\n [\n (\"scaler\", StandardScaler()),\n (\"knn\", KNeighborsClassifier(n_neighbors=n_neighbors)),\n ]\n ),\n Pipeline(\n [\n (\"scaler\", StandardScaler()),\n (\"nca\", NeighborhoodComponentsAnalysis()),\n (\"knn\", KNeighborsClassifier(n_neighbors=n_neighbors)),\n ]\n ),\n]\n\nx_min, x_max = X[:, 0].min() - 1, X[:, 0].max() + 1\ny_min, y_max = X[:, 1].min() - 1, X[:, 1].max() + 1\nxx, yy = np.meshgrid(np.arange(x_min, x_max, h), np.arange(y_min, y_max, h))\n\nfor name, clf in zip(names, classifiers):\n\n clf.fit(X_train, y_train)\n score = clf.score(X_test, y_test)\n\n # Plot the decision boundary. For that, we will assign a color to each\n # point in the mesh [x_min, x_max]x[y_min, y_max].\n Z = clf.predict(np.c_[xx.ravel(), yy.ravel()])\n\n # Put the result into a color plot\n Z = Z.reshape(xx.shape)\n plt.figure()\n plt.pcolormesh(xx, yy, Z, cmap=cmap_light, alpha=0.8)\n\n # Plot also the training and testing points\n plt.scatter(X[:, 0], X[:, 1], c=y, cmap=cmap_bold, edgecolor=\"k\", s=20)\n plt.xlim(xx.min(), xx.max())\n plt.ylim(yy.min(), yy.max())\n plt.title(\"{} (k = {})\".format(name, n_neighbors))\n plt.text(\n 0.9,\n 0.1,\n \"{:.2f}\".format(score),\n size=15,\n ha=\"center\",\n va=\"center\",\n transform=plt.gca().transAxes,\n )\n\nplt.show()"
29+
"# License: BSD 3 clause\n\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom matplotlib.colors import ListedColormap\nfrom sklearn import datasets\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.preprocessing import StandardScaler\nfrom sklearn.neighbors import KNeighborsClassifier, NeighborhoodComponentsAnalysis\nfrom sklearn.pipeline import Pipeline\n\n\nn_neighbors = 1\n\ndataset = datasets.load_iris()\nX, y = dataset.data, dataset.target\n\n# we only take two features. We could avoid this ugly\n# slicing by using a two-dim dataset\nX = X[:, [0, 2]]\n\nX_train, X_test, y_train, y_test = train_test_split(\n X, y, stratify=y, test_size=0.7, random_state=42\n)\n\nh = 0.01 # step size in the mesh\n\n# Create color maps\ncmap_light = ListedColormap([\"#FFAAAA\", \"#AAFFAA\", \"#AAAAFF\"])\ncmap_bold = ListedColormap([\"#FF0000\", \"#00FF00\", \"#0000FF\"])\n\nnames = [\"KNN\", \"NCA, KNN\"]\n\nclassifiers = [\n Pipeline(\n [\n (\"scaler\", StandardScaler()),\n (\"knn\", KNeighborsClassifier(n_neighbors=n_neighbors)),\n ]\n ),\n Pipeline(\n [\n (\"scaler\", StandardScaler()),\n (\"nca\", NeighborhoodComponentsAnalysis()),\n (\"knn\", KNeighborsClassifier(n_neighbors=n_neighbors)),\n ]\n ),\n]\n\nx_min, x_max = X[:, 0].min() - 1, X[:, 0].max() + 1\ny_min, y_max = X[:, 1].min() - 1, X[:, 1].max() + 1\nxx, yy = np.meshgrid(np.arange(x_min, x_max, h), np.arange(y_min, y_max, h))\n\nfor name, clf in zip(names, classifiers):\n\n clf.fit(X_train, y_train)\n score = clf.score(X_test, y_test)\n\n # Plot the decision boundary. For that, we will assign a color to each\n # point in the mesh [x_min, x_max]x[y_min, y_max].\n Z = clf.predict(np.c_[xx.ravel(), yy.ravel()])\n\n # Put the result into a color plot\n Z = Z.reshape(xx.shape)\n plt.figure()\n plt.pcolormesh(xx, yy, Z, cmap=cmap_light, alpha=0.8)\n\n # Plot also the training and testing points\n plt.scatter(X[:, 0], X[:, 1], c=y, cmap=cmap_bold, edgecolor=\"k\", s=20)\n plt.xlim(xx.min(), xx.max())\n plt.ylim(yy.min(), yy.max())\n plt.title(\"{} (k = {})\".format(name, n_neighbors))\n plt.text(\n 0.9,\n 0.1,\n \"{:.2f}\".format(score),\n size=15,\n ha=\"center\",\n va=\"center\",\n transform=plt.gca().transAxes,\n )\n\nplt.show()"
3030
]
3131
}
3232
],
Binary file not shown.

dev/_downloads/b7792f6c26a74369f67bbe6f9ac41edf/plot_nca_classification.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
X, y, stratify=y, test_size=0.7, random_state=42
4141
)
4242

43-
h = 0.05 # step size in the mesh
43+
h = 0.01 # step size in the mesh
4444

4545
# Create color maps
4646
cmap_light = ListedColormap(["#FFAAAA", "#AAFFAA", "#AAAAFF"])

dev/_downloads/scikit-learn-docs.zip

-5.08 KB
Binary file not shown.
-65 Bytes
106 Bytes
-392 Bytes
-354 Bytes
-12 Bytes

0 commit comments

Comments
 (0)