Skip to content

DOC Update estimator representation example #24439

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@
"examples/model_selection/grid_search_text_feature_extraction.py": (
"examples/model_selection/plot_grid_search_text_feature_extraction.py"
),
"examples/miscellaneous/plot_changed_only_pprint_parameter": (
"examples/miscellaneous/plot_estimator_representation"
),
}
html_context["redirects"] = redirects
for old_link in redirects:
Expand Down
30 changes: 0 additions & 30 deletions examples/miscellaneous/plot_changed_only_pprint_parameter.py

This file was deleted.

50 changes: 50 additions & 0 deletions examples/miscellaneous/plot_estimator_representation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
"""
===========================================
Displaying estimators and complex pipelines
===========================================

This example illustrates different ways estimators and pipelines can be
displayed.
"""

from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import OneHotEncoder, StandardScaler
from sklearn.impute import SimpleImputer
from sklearn.compose import make_column_transformer
from sklearn.linear_model import LogisticRegression


# %%
# Compact text representation
# ---------------------------
#
# Estimators will only show the parameters that have been set to non-default
# values when displayed as a string. This reduces the visual noise and makes it
# easier to spot what the differences are when comparing instances.

lr = LogisticRegression(penalty="l1")
print(lr)

# %%
# Rich HTML representation
# ------------------------
# In notebooks estimators and pipelines will use a rich HTML representation.
# This is particularly useful to summarise the
# structure of pipelines and other composite estimators, with interactivity to
# provide detail. Click on the example image below to expand Pipeline
# elements. See :ref:`visualizing_composite_estimators` for how you can use
# this feature.

num_proc = make_pipeline(SimpleImputer(strategy="median"), StandardScaler())

cat_proc = make_pipeline(
SimpleImputer(strategy="constant", fill_value="missing"),
OneHotEncoder(handle_unknown="ignore"),
)

preprocessor = make_column_transformer(
(num_proc, ("feat1", "feat3")), (cat_proc, ("feat0", "feat2"))
)

clf = make_pipeline(preprocessor, LogisticRegression())
clf