Skip to content

Commit 039d8df

Browse files
committed
Pushing the docs to dev/ for branch: main, commit 7601f87b7a8faaf0d3bd14add9a050b127cbb865
1 parent c785204 commit 039d8df

File tree

1,233 files changed

+6383
-4440
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,233 files changed

+6383
-4440
lines changed
Binary file not shown.

dev/_downloads/26f110ad6cff1a8a7c58b1a00d8b8b5a/plot_column_transformer_mixed_types.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"cell_type": "markdown",
5252
"metadata": {},
5353
"source": [
54-
"## HTML representation of ``Pipeline``\n When the ``Pipeline`` is printed out in a jupyter notebook an HTML\n representation of the estimator is displayed as follows:\n\n"
54+
"## HTML representation of ``Pipeline`` (display diagram)\n When the ``Pipeline`` is printed out in a jupyter notebook an HTML\n representation of the estimator is displayed as follows:\n\n"
5555
]
5656
},
5757
{
Lines changed: 241 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,241 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {
7+
"collapsed": false
8+
},
9+
"outputs": [],
10+
"source": [
11+
"%matplotlib inline"
12+
]
13+
},
14+
{
15+
"cell_type": "markdown",
16+
"metadata": {},
17+
"source": [
18+
"\n# Displaying Pipelines\n\nThe default configuration for displaying a pipeline is `'text'` where\n`set_config(display='text')`. To visualize the diagram in Jupyter Notebook,\nuse `set_config(display='diagram')` and then output the pipeline object.\n\nTo see more detailed steps in the visualization of the pipeline, click on the\nsteps in the pipeline.\n"
19+
]
20+
},
21+
{
22+
"cell_type": "markdown",
23+
"metadata": {},
24+
"source": [
25+
"## Displaying a Pipeline with a Preprocessing Step and Classifier\n This section constructs a :class:`~sklearn.pipeline.Pipeline` with a preprocessing\n step, :class:`~sklearn.preprocessing.StandardScaler`, and classifier,\n :class:`~sklearn.linear_model.LogisticRegression`, and displays its visual\n representation.\n\n"
26+
]
27+
},
28+
{
29+
"cell_type": "code",
30+
"execution_count": null,
31+
"metadata": {
32+
"collapsed": false
33+
},
34+
"outputs": [],
35+
"source": [
36+
"from sklearn.pipeline import Pipeline\nfrom sklearn.preprocessing import StandardScaler\nfrom sklearn.linear_model import LogisticRegression\nfrom sklearn import set_config\n\nsteps = [\n (\"preprocessing\", StandardScaler()),\n (\"classifier\", LogisticRegression()),\n]\npipe = Pipeline(steps)"
37+
]
38+
},
39+
{
40+
"cell_type": "markdown",
41+
"metadata": {},
42+
"source": [
43+
"To view the text pipeline, the default is `display='text'`.\n\n"
44+
]
45+
},
46+
{
47+
"cell_type": "code",
48+
"execution_count": null,
49+
"metadata": {
50+
"collapsed": false
51+
},
52+
"outputs": [],
53+
"source": [
54+
"set_config(display=\"text\")\npipe"
55+
]
56+
},
57+
{
58+
"cell_type": "markdown",
59+
"metadata": {},
60+
"source": [
61+
"To visualize the diagram, change `display='diagram'`.\n\n"
62+
]
63+
},
64+
{
65+
"cell_type": "code",
66+
"execution_count": null,
67+
"metadata": {
68+
"collapsed": false
69+
},
70+
"outputs": [],
71+
"source": [
72+
"set_config(display=\"diagram\")\npipe # click on the diagram below to see the details of each step"
73+
]
74+
},
75+
{
76+
"cell_type": "markdown",
77+
"metadata": {},
78+
"source": [
79+
"## Displaying a Pipeline Chaining Multiple Preprocessing Steps & Classifier\n This section constructs a :class:`~sklearn.pipeline.Pipeline` with multiple\n preprocessing steps, :class:`~sklearn.preprocessing.PolynomialFeatures` and\n :class:`~sklearn.preprocessing.StandardScaler`, and a classifer step,\n :class:`~sklearn.linear_model.LogisticRegression`, and displays its visual\n representation.\n\n"
80+
]
81+
},
82+
{
83+
"cell_type": "code",
84+
"execution_count": null,
85+
"metadata": {
86+
"collapsed": false
87+
},
88+
"outputs": [],
89+
"source": [
90+
"from sklearn.pipeline import Pipeline\nfrom sklearn.preprocessing import StandardScaler, PolynomialFeatures\nfrom sklearn.linear_model import LogisticRegression\nfrom sklearn import set_config\n\nsteps = [\n (\"standard_scaler\", StandardScaler()),\n (\"polynomial\", PolynomialFeatures(degree=3)),\n (\"classifier\", LogisticRegression(C=2.0)),\n]\npipe = Pipeline(steps)"
91+
]
92+
},
93+
{
94+
"cell_type": "markdown",
95+
"metadata": {},
96+
"source": [
97+
"To visualize the diagram, change to display='diagram'\n\n"
98+
]
99+
},
100+
{
101+
"cell_type": "code",
102+
"execution_count": null,
103+
"metadata": {
104+
"collapsed": false
105+
},
106+
"outputs": [],
107+
"source": [
108+
"set_config(display=\"diagram\")\npipe # click on the diagram below to see the details of each step"
109+
]
110+
},
111+
{
112+
"cell_type": "markdown",
113+
"metadata": {},
114+
"source": [
115+
"## Displaying a Pipeline and Dimensionality Reduction and Classifier\n This section constructs a :class:`~sklearn.pipeline.Pipeline` with a\n dimensionality reduction step, :class:`~sklearn.decomposition.PCA`,\n a classifier, :class:`~sklearn.svm.SVC`, and displays its visual\n representation.\n\n"
116+
]
117+
},
118+
{
119+
"cell_type": "code",
120+
"execution_count": null,
121+
"metadata": {
122+
"collapsed": false
123+
},
124+
"outputs": [],
125+
"source": [
126+
"from sklearn.pipeline import Pipeline\nfrom sklearn.svm import SVC\nfrom sklearn.decomposition import PCA\nfrom sklearn import set_config\n\nsteps = [(\"reduce_dim\", PCA(n_components=4)), (\"classifier\", SVC(kernel=\"linear\"))]\npipe = Pipeline(steps)"
127+
]
128+
},
129+
{
130+
"cell_type": "markdown",
131+
"metadata": {},
132+
"source": [
133+
"To visualize the diagram, change to `display='diagram'`.\n\n"
134+
]
135+
},
136+
{
137+
"cell_type": "code",
138+
"execution_count": null,
139+
"metadata": {
140+
"collapsed": false
141+
},
142+
"outputs": [],
143+
"source": [
144+
"set_config(display=\"diagram\")\npipe # click on the diagram below to see the details of each step"
145+
]
146+
},
147+
{
148+
"cell_type": "markdown",
149+
"metadata": {},
150+
"source": [
151+
"## Displaying a Complex Pipeline Chaining a Column Transformer\n This section constructs a complex :class:`~sklearn.pipeline.Pipeline` with a\n :class:`~sklearn.compose.ColumnTransformer` and a classifier,\n :class:`~sklearn.linear_model.LogisticRegression`, and displays its visual\n representation.\n\n"
152+
]
153+
},
154+
{
155+
"cell_type": "code",
156+
"execution_count": null,
157+
"metadata": {
158+
"collapsed": false
159+
},
160+
"outputs": [],
161+
"source": [
162+
"import numpy as np\nfrom sklearn.pipeline import make_pipeline\nfrom sklearn.pipeline import Pipeline\nfrom sklearn.impute import SimpleImputer\nfrom sklearn.compose import ColumnTransformer\nfrom sklearn.preprocessing import OneHotEncoder, StandardScaler\nfrom sklearn.linear_model import LogisticRegression\nfrom sklearn import set_config\n\nnumeric_preprocessor = Pipeline(\n steps=[\n (\"imputation_mean\", SimpleImputer(missing_values=np.nan, strategy=\"mean\")),\n (\"scaler\", StandardScaler()),\n ]\n)\n\ncategorical_preprocessor = Pipeline(\n steps=[\n (\n \"imputation_constant\",\n SimpleImputer(fill_value=\"missing\", strategy=\"constant\"),\n ),\n (\"onehot\", OneHotEncoder(handle_unknown=\"ignore\")),\n ]\n)\n\npreprocessor = ColumnTransformer(\n [\n (\"categorical\", categorical_preprocessor, [\"state\", \"gender\"]),\n (\"numerical\", numeric_preprocessor, [\"age\", \"weight\"]),\n ]\n)\n\npipe = make_pipeline(preprocessor, LogisticRegression(max_iter=500))"
163+
]
164+
},
165+
{
166+
"cell_type": "markdown",
167+
"metadata": {},
168+
"source": [
169+
"To visualize the diagram, change to `display='diagram'`\n\n"
170+
]
171+
},
172+
{
173+
"cell_type": "code",
174+
"execution_count": null,
175+
"metadata": {
176+
"collapsed": false
177+
},
178+
"outputs": [],
179+
"source": [
180+
"set_config(display=\"diagram\")\npipe # click on the diagram below to see the details of each step"
181+
]
182+
},
183+
{
184+
"cell_type": "markdown",
185+
"metadata": {},
186+
"source": [
187+
"## Displaying a Grid Search over a Pipeline with a Classifier\n This section constructs a :class:`~sklearn.model_selection.GridSearchCV`\n over a :class:`~sklearn.pipeline.Pipeline` with\n :class:`~sklearn.ensemble.RandomForestClassifier` and displays its visual\n representation.\n\n"
188+
]
189+
},
190+
{
191+
"cell_type": "code",
192+
"execution_count": null,
193+
"metadata": {
194+
"collapsed": false
195+
},
196+
"outputs": [],
197+
"source": [
198+
"import numpy as np\nfrom sklearn.pipeline import make_pipeline\nfrom sklearn.pipeline import Pipeline\nfrom sklearn.impute import SimpleImputer\nfrom sklearn.compose import ColumnTransformer\nfrom sklearn.preprocessing import OneHotEncoder, StandardScaler\nfrom sklearn.ensemble import RandomForestClassifier\nfrom sklearn.model_selection import GridSearchCV\nfrom sklearn import set_config\n\nnumeric_preprocessor = Pipeline(\n steps=[\n (\"imputation_mean\", SimpleImputer(missing_values=np.nan, strategy=\"mean\")),\n (\"scaler\", StandardScaler()),\n ]\n)\n\ncategorical_preprocessor = Pipeline(\n steps=[\n (\n \"imputation_constant\",\n SimpleImputer(fill_value=\"missing\", strategy=\"constant\"),\n ),\n (\"onehot\", OneHotEncoder(handle_unknown=\"ignore\")),\n ]\n)\n\npreprocessor = ColumnTransformer(\n [\n (\"categorical\", categorical_preprocessor, [\"state\", \"gender\"]),\n (\"numerical\", numeric_preprocessor, [\"age\", \"weight\"]),\n ]\n)\n\npipe = Pipeline(\n steps=[(\"preprocessor\", preprocessor), (\"classifier\", RandomForestClassifier())]\n)\n\nparam_grid = {\n \"classifier__n_estimators\": [200, 500],\n \"classifier__max_features\": [\"auto\", \"sqrt\", \"log2\"],\n \"classifier__max_depth\": [4, 5, 6, 7, 8],\n \"classifier__criterion\": [\"gini\", \"entropy\"],\n}\n\ngrid_search = GridSearchCV(pipe, param_grid=param_grid, n_jobs=1)"
199+
]
200+
},
201+
{
202+
"cell_type": "markdown",
203+
"metadata": {},
204+
"source": [
205+
"To visualize the diagram, change to `display='diagram'`.\n\n"
206+
]
207+
},
208+
{
209+
"cell_type": "code",
210+
"execution_count": null,
211+
"metadata": {
212+
"collapsed": false
213+
},
214+
"outputs": [],
215+
"source": [
216+
"set_config(display=\"diagram\")\ngrid_search # click on the diagram below to see the details of each step"
217+
]
218+
}
219+
],
220+
"metadata": {
221+
"kernelspec": {
222+
"display_name": "Python 3",
223+
"language": "python",
224+
"name": "python3"
225+
},
226+
"language_info": {
227+
"codemirror_mode": {
228+
"name": "ipython",
229+
"version": 3
230+
},
231+
"file_extension": ".py",
232+
"mimetype": "text/x-python",
233+
"name": "python",
234+
"nbconvert_exporter": "python",
235+
"pygments_lexer": "ipython3",
236+
"version": "3.9.7"
237+
}
238+
},
239+
"nbformat": 4,
240+
"nbformat_minor": 0
241+
}
Binary file not shown.

dev/_downloads/79c38d2f2cb1f2ef7d68e0cc7ea7b4e4/plot_column_transformer_mixed_types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
print("model score: %.3f" % clf.score(X_test, y_test))
9494

9595
# %%
96-
# HTML representation of ``Pipeline``
96+
# HTML representation of ``Pipeline`` (display diagram)
9797
###############################################################################
9898
# When the ``Pipeline`` is printed out in a jupyter notebook an HTML
9999
# representation of the estimator is displayed as follows:

0 commit comments

Comments
 (0)