Skip to content

Commit c4ab014

Browse files
committed
Pushing the docs to dev/ for branch: master, commit be6bf6902c199b27f4f001ce3597e521c3a0d0aa
1 parent 26ad78d commit c4ab014

File tree

1,211 files changed

+3726
-3705
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,211 files changed

+3726
-3705
lines changed

dev/_downloads/1d4bce7e02c88f07c85f455ef1193191/plot_caching_nearest_neighbors.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-
"# Author: Tom Dupre la Tour\n#\n# License: BSD 3 clause\nimport matplotlib.pyplot as plt\n\nfrom sklearn.neighbors import KNeighborsTransformer, KNeighborsClassifier\nfrom sklearn.model_selection import GridSearchCV\nfrom sklearn.datasets import load_digits\nfrom sklearn.pipeline import Pipeline\n\nprint(__doc__)\n\nX, y = load_digits(return_X_y=True)\nn_neighbors_list = [1, 2, 3, 4, 5, 6, 7, 8, 9]\n\n# The transformer computes the nearest neighbors graph using the maximum number\n# of neighbors necessary in the grid search. The classifier model filters the\n# nearest neighbors graph as required by its own n_neighbors parameter.\ngraph_model = KNeighborsTransformer(n_neighbors=max(n_neighbors_list),\n mode='distance')\nclassifier_model = KNeighborsClassifier(metric='precomputed')\n\n# Note that we give `memory` a directory to cache the graph computation.\nfull_model = Pipeline(\n steps=[('graph', graph_model), ('classifier', classifier_model)],\n memory='./cache')\n\nparam_grid = {'classifier__n_neighbors': n_neighbors_list}\ngrid_model = GridSearchCV(full_model, param_grid)\ngrid_model.fit(X, y)\n\n# Plot the results of the grid search.\nfig, axes = plt.subplots(1, 2, figsize=(8, 4))\naxes[0].errorbar(x=n_neighbors_list,\n y=grid_model.cv_results_['mean_test_score'],\n yerr=grid_model.cv_results_['std_test_score'])\naxes[0].set(xlabel='n_neighbors', title='Classification accuracy')\naxes[1].errorbar(x=n_neighbors_list, y=grid_model.cv_results_['mean_fit_time'],\n yerr=grid_model.cv_results_['std_fit_time'], color='r')\naxes[1].set(xlabel='n_neighbors', title='Fit time (with caching)')\nfig.tight_layout()\nplt.show()"
29+
"# Author: Tom Dupre la Tour\n#\n# License: BSD 3 clause\nfrom tempfile import TemporaryDirectory\nimport matplotlib.pyplot as plt\n\nfrom sklearn.neighbors import KNeighborsTransformer, KNeighborsClassifier\nfrom sklearn.model_selection import GridSearchCV\nfrom sklearn.datasets import load_digits\nfrom sklearn.pipeline import Pipeline\n\nprint(__doc__)\n\nX, y = load_digits(return_X_y=True)\nn_neighbors_list = [1, 2, 3, 4, 5, 6, 7, 8, 9]\n\n# The transformer computes the nearest neighbors graph using the maximum number\n# of neighbors necessary in the grid search. The classifier model filters the\n# nearest neighbors graph as required by its own n_neighbors parameter.\ngraph_model = KNeighborsTransformer(n_neighbors=max(n_neighbors_list),\n mode='distance')\nclassifier_model = KNeighborsClassifier(metric='precomputed')\n\n# Note that we give `memory` a directory to cache the graph computation\n# that will be used several times when tuning the hyperparameters of the\n# classifier.\nwith TemporaryDirectory(prefix=\"sklearn_graph_cache_\") as tmpdir:\n full_model = Pipeline(\n steps=[('graph', graph_model), ('classifier', classifier_model)],\n memory=tmpdir)\n\n param_grid = {'classifier__n_neighbors': n_neighbors_list}\n grid_model = GridSearchCV(full_model, param_grid)\n grid_model.fit(X, y)\n\n# Plot the results of the grid search.\nfig, axes = plt.subplots(1, 2, figsize=(8, 4))\naxes[0].errorbar(x=n_neighbors_list,\n y=grid_model.cv_results_['mean_test_score'],\n yerr=grid_model.cv_results_['std_test_score'])\naxes[0].set(xlabel='n_neighbors', title='Classification accuracy')\naxes[1].errorbar(x=n_neighbors_list, y=grid_model.cv_results_['mean_fit_time'],\n yerr=grid_model.cv_results_['std_fit_time'], color='r')\naxes[1].set(xlabel='n_neighbors', title='Fit time (with caching)')\nfig.tight_layout()\nplt.show()"
3030
]
3131
}
3232
],
Binary file not shown.

dev/_downloads/4d6dfc2952a4797fcae4a1abee99951f/plot_caching_nearest_neighbors.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
# Author: Tom Dupre la Tour
2020
#
2121
# License: BSD 3 clause
22+
from tempfile import TemporaryDirectory
2223
import matplotlib.pyplot as plt
2324

2425
from sklearn.neighbors import KNeighborsTransformer, KNeighborsClassifier
@@ -38,14 +39,17 @@
3839
mode='distance')
3940
classifier_model = KNeighborsClassifier(metric='precomputed')
4041

41-
# Note that we give `memory` a directory to cache the graph computation.
42-
full_model = Pipeline(
43-
steps=[('graph', graph_model), ('classifier', classifier_model)],
44-
memory='./cache')
42+
# Note that we give `memory` a directory to cache the graph computation
43+
# that will be used several times when tuning the hyperparameters of the
44+
# classifier.
45+
with TemporaryDirectory(prefix="sklearn_graph_cache_") as tmpdir:
46+
full_model = Pipeline(
47+
steps=[('graph', graph_model), ('classifier', classifier_model)],
48+
memory=tmpdir)
4549

46-
param_grid = {'classifier__n_neighbors': n_neighbors_list}
47-
grid_model = GridSearchCV(full_model, param_grid)
48-
grid_model.fit(X, y)
50+
param_grid = {'classifier__n_neighbors': n_neighbors_list}
51+
grid_model = GridSearchCV(full_model, param_grid)
52+
grid_model.fit(X, y)
4953

5054
# Plot the results of the grid search.
5155
fig, axes = plt.subplots(1, 2, figsize=(8, 4))

dev/_downloads/7ee55c12f8d3eb1dd8d2005d9dd7b6f1/plot_release_highlights_0_22_0.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,16 +133,19 @@
133133
# implementations, such as approximate nearest neighbors methods.
134134
# See more details in the :ref:`User Guide <neighbors_transformer>`.
135135

136+
from tempfile import TemporaryDirectory
136137
from sklearn.neighbors import KNeighborsTransformer
137138
from sklearn.manifold import Isomap
138139
from sklearn.pipeline import make_pipeline
139140

140-
estimator = make_pipeline(
141-
KNeighborsTransformer(n_neighbors=10, mode='distance'),
142-
Isomap(n_neighbors=10, metric='precomputed'),
143-
memory='.')
144-
estimator.fit(X)
145-
146-
# We can decrease the number of neighbors and the graph will not be recomputed.
147-
estimator.set_params(isomap__n_neighbors=5)
148-
estimator.fit(X)
141+
with TemporaryDirectory(prefix="sklearn_cache_") as tmpdir:
142+
estimator = make_pipeline(
143+
KNeighborsTransformer(n_neighbors=10, mode='distance'),
144+
Isomap(n_neighbors=10, metric='precomputed'),
145+
memory=tmpdir)
146+
estimator.fit(X)
147+
148+
# We can decrease the number of neighbors and the graph will not be
149+
# recomputed.
150+
estimator.set_params(isomap__n_neighbors=5)
151+
estimator.fit(X)

dev/_downloads/c101b602d0b3510ef47dd19d64a4a92b/plot_release_highlights_0_22_0.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
123123
},
124124
"outputs": [],
125125
"source": [
126-
"from sklearn.neighbors import KNeighborsTransformer\nfrom sklearn.manifold import Isomap\nfrom sklearn.pipeline import make_pipeline\n\nestimator = make_pipeline(\n KNeighborsTransformer(n_neighbors=10, mode='distance'),\n Isomap(n_neighbors=10, metric='precomputed'),\n memory='.')\nestimator.fit(X)\n\n# We can decrease the number of neighbors and the graph will not be recomputed.\nestimator.set_params(isomap__n_neighbors=5)\nestimator.fit(X)"
126+
"from tempfile import TemporaryDirectory\nfrom sklearn.neighbors import KNeighborsTransformer\nfrom sklearn.manifold import Isomap\nfrom sklearn.pipeline import make_pipeline\n\nwith TemporaryDirectory(prefix=\"sklearn_cache_\") as tmpdir:\n estimator = make_pipeline(\n KNeighborsTransformer(n_neighbors=10, mode='distance'),\n Isomap(n_neighbors=10, metric='precomputed'),\n memory=tmpdir)\n estimator.fit(X)\n\n # We can decrease the number of neighbors and the graph will not be\n # recomputed.\n estimator.set_params(isomap__n_neighbors=5)\n estimator.fit(X)"
127127
]
128128
}
129129
],
Binary file not shown.

dev/_downloads/scikit-learn-docs.pdf

-14.8 KB
Binary file not shown.

dev/_images/iris.png

0 Bytes
82 Bytes
82 Bytes

0 commit comments

Comments
 (0)