Skip to content

Commit 2ca30c1

Browse files
committed
Pushing the docs to dev/ for branch: main, commit ba1d23d13e402367c6401e07256867fdd5a4a0bf
1 parent 3c822d5 commit 2ca30c1

File tree

1,262 files changed

+4868
-4526
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,262 files changed

+4868
-4526
lines changed
Binary file not shown.

dev/_downloads/1b3f17ff0f112d5b77cbdb90f1c17046/plot_set_output.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,10 @@
8484
set_config(transform_output="pandas")
8585

8686
num_pipe = make_pipeline(SimpleImputer(), StandardScaler())
87+
num_cols = ["age", "fare"]
8788
ct = ColumnTransformer(
8889
(
89-
("numerical", num_pipe, ["age", "fare"]),
90+
("numerical", num_pipe, num_cols),
9091
(
9192
"categorical",
9293
OneHotEncoder(
@@ -114,3 +115,24 @@
114115
# This resets `transform_output` to its default value to avoid impacting other
115116
# examples when generating the scikit-learn documentation
116117
set_config(transform_output="default")
118+
119+
# %%
120+
# When configuring the output type with :func:`config_context` the
121+
# configuration at the time when `transform` or `fit_transform` are
122+
# called is what counts. Setting these only when you construct or fit
123+
# the transformer has no effect.
124+
from sklearn import config_context
125+
126+
scaler = StandardScaler()
127+
scaler.fit(X_train[num_cols])
128+
129+
# %%
130+
with config_context(transform_output="pandas"):
131+
# the output of transform will be a Pandas DataFrame
132+
X_test_scaled = scaler.transform(X_test[num_cols])
133+
X_test_scaled.head()
134+
135+
# %%
136+
# outside of the context manager, the output will be a NumPy array
137+
X_test_scaled = scaler.transform(X_test[num_cols])
138+
X_test_scaled[:5]
Binary file not shown.

dev/_downloads/e23929e86fa0a415fb85ef2834a3ff7d/plot_set_output.ipynb

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@
141141
},
142142
"outputs": [],
143143
"source": [
144-
"from sklearn.compose import ColumnTransformer\nfrom sklearn.preprocessing import OneHotEncoder, StandardScaler\nfrom sklearn.impute import SimpleImputer\nfrom sklearn import set_config\n\nset_config(transform_output=\"pandas\")\n\nnum_pipe = make_pipeline(SimpleImputer(), StandardScaler())\nct = ColumnTransformer(\n (\n (\"numerical\", num_pipe, [\"age\", \"fare\"]),\n (\n \"categorical\",\n OneHotEncoder(\n sparse_output=False, drop=\"if_binary\", handle_unknown=\"ignore\"\n ),\n [\"embarked\", \"sex\", \"pclass\"],\n ),\n ),\n verbose_feature_names_out=False,\n)\nclf = make_pipeline(ct, SelectPercentile(percentile=50), LogisticRegression())\nclf.fit(X_train, y_train)\nclf.score(X_test, y_test)"
144+
"from sklearn.compose import ColumnTransformer\nfrom sklearn.preprocessing import OneHotEncoder, StandardScaler\nfrom sklearn.impute import SimpleImputer\nfrom sklearn import set_config\n\nset_config(transform_output=\"pandas\")\n\nnum_pipe = make_pipeline(SimpleImputer(), StandardScaler())\nnum_cols = [\"age\", \"fare\"]\nct = ColumnTransformer(\n (\n (\"numerical\", num_pipe, num_cols),\n (\n \"categorical\",\n OneHotEncoder(\n sparse_output=False, drop=\"if_binary\", handle_unknown=\"ignore\"\n ),\n [\"embarked\", \"sex\", \"pclass\"],\n ),\n ),\n verbose_feature_names_out=False,\n)\nclf = make_pipeline(ct, SelectPercentile(percentile=50), LogisticRegression())\nclf.fit(X_train, y_train)\nclf.score(X_test, y_test)"
145145
]
146146
},
147147
{
@@ -179,6 +179,53 @@
179179
"source": [
180180
"set_config(transform_output=\"default\")"
181181
]
182+
},
183+
{
184+
"cell_type": "markdown",
185+
"metadata": {},
186+
"source": [
187+
"When configuring the output type with :func:`config_context` the\nconfiguration at the time when `transform` or `fit_transform` are\ncalled is what counts. Setting these only when you construct or fit\nthe transformer has no effect.\n\n"
188+
]
189+
},
190+
{
191+
"cell_type": "code",
192+
"execution_count": null,
193+
"metadata": {
194+
"collapsed": false
195+
},
196+
"outputs": [],
197+
"source": [
198+
"from sklearn import config_context\n\nscaler = StandardScaler()\nscaler.fit(X_train[num_cols])"
199+
]
200+
},
201+
{
202+
"cell_type": "code",
203+
"execution_count": null,
204+
"metadata": {
205+
"collapsed": false
206+
},
207+
"outputs": [],
208+
"source": [
209+
"with config_context(transform_output=\"pandas\"):\n # the output of transform will be a Pandas DataFrame\n X_test_scaled = scaler.transform(X_test[num_cols])\nX_test_scaled.head()"
210+
]
211+
},
212+
{
213+
"cell_type": "markdown",
214+
"metadata": {},
215+
"source": [
216+
"outside of the context manager, the output will be a NumPy array\n\n"
217+
]
218+
},
219+
{
220+
"cell_type": "code",
221+
"execution_count": null,
222+
"metadata": {
223+
"collapsed": false
224+
},
225+
"outputs": [],
226+
"source": [
227+
"X_test_scaled = scaler.transform(X_test[num_cols])\nX_test_scaled[:5]"
228+
]
182229
}
183230
],
184231
"metadata": {

dev/_downloads/scikit-learn-docs.zip

-3.96 KB
Binary file not shown.
187 Bytes
-1 Bytes
202 Bytes
148 Bytes
80 Bytes

0 commit comments

Comments
 (0)