Skip to content

Commit ce96d1b

Browse files
committed
[ci skip] Update notebooks 73e12fb
1 parent 72904ce commit ce96d1b

File tree

4 files changed

+967
-18
lines changed

4 files changed

+967
-18
lines changed

_sources/python_scripts/03_categorical_pipeline_visualization.py

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,41 @@
9797
("classifier", LogisticRegression()),
9898
]
9999
)
100+
model
100101

101102
# %% [markdown]
102-
# Let's visualize it!
103+
# Let's fit it!
103104

104105
# %%
105-
model
106+
model.fit(data, target)
107+
108+
# %% [markdown]
109+
# Notice that the diagram changes color once the estimator is fit.
110+
#
111+
# So far we used `Pipeline` and `ColumnTransformer`, which allows us to custom
112+
# the names of the steps in the pipeline. An alternative is to use
113+
# `make_column_transformer` and `make_pipeline`, they do not require, and do not
114+
# permit, naming the estimators. Instead, their names are set to the lowercase
115+
# of their types automatically.
116+
117+
# %%
118+
from sklearn.compose import make_column_transformer
119+
from sklearn.pipeline import make_pipeline
120+
121+
numeric_transformer = make_pipeline(
122+
SimpleImputer(strategy="median"), StandardScaler()
123+
)
124+
categorical_transformer = OneHotEncoder(handle_unknown="ignore")
125+
126+
preprocessor = make_column_transformer(
127+
(numeric_transformer, numeric_features),
128+
(categorical_transformer, categorical_features),
129+
)
130+
model = make_pipeline(preprocessor, LogisticRegression())
131+
model.fit(data, target)
106132

107133
# %% [markdown]
108-
# ## Finally we score the model
134+
# ## Finally we can score the model using cross-validation:
109135

110136
# %%
111137
from sklearn.model_selection import cross_validate

appendix/notebook_timings.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -779,9 +779,9 @@ <h1>Notebook timings<a class="headerlink" href="#notebook-timings" title="Link t
779779
<td><p></p></td>
780780
</tr>
781781
<tr class="row-odd"><td><p><a class="xref doc reference internal" href="../python_scripts/03_categorical_pipeline_visualization.html"><span class="doc">python_scripts/03_categorical_pipeline_visualization</span></a></p></td>
782-
<td><p>2025-07-14 23:34</p></td>
782+
<td><p>2025-07-15 17:33</p></td>
783783
<td><p>cache</p></td>
784-
<td><p>2.0</p></td>
784+
<td><p>2.35</p></td>
785785
<td><p></p></td>
786786
</tr>
787787
<tr class="row-even"><td><p><a class="xref doc reference internal" href="../python_scripts/cross_validation_baseline.html"><span class="doc">python_scripts/cross_validation_baseline</span></a></p></td>

0 commit comments

Comments
 (0)