注意
Go to the end to download the full example code or to run this example in your browser via JupyterLite or Binder.
显示估计器和复杂管道#
此示例演示了显示估计器和管道的不同方式。
# Authors: The scikit-learn developers
# SPDX-License-Identifier: BSD-3-Clause
from sklearn.compose import make_column_transformer
from sklearn.impute import SimpleImputer
from sklearn.linear_model import LogisticRegression
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import OneHotEncoder, StandardScaler
紧凑的文本表示#
估计器在显示为字符串时,将仅显示已设置为非默认值的参数。这减少了视觉干扰,使得比较实例时更容易发现差异。
lr = LogisticRegression(l1_ratio=1)
print(lr)
LogisticRegression(l1_ratio=1)
富HTML表示#
在笔记本中,估计器和管道将使用富HTML表示。这对于概括管道和其他复合估计器的结构特别有用,并具有提供详细信息的交互性。单击下面的示例图像以展开管道元素。有关如何使用此功能的详细信息,请参阅可视化复合估计器。
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
Pipeline(steps=[('columntransformer',
ColumnTransformer(transformers=[('pipeline-1',
Pipeline(steps=[('simpleimputer',
SimpleImputer(strategy='median')),
('standardscaler',
StandardScaler())]),
('feat1', 'feat3')),
('pipeline-2',
Pipeline(steps=[('simpleimputer',
SimpleImputer(fill_value='missing',
strategy='constant')),
('onehotencoder',
OneHotEncoder(handle_unknown='ignore'))]),
('feat0', 'feat2'))])),
('logisticregression', LogisticRegression())])在 Jupyter 环境中,请重新运行此单元格以显示 HTML 表示形式或信任 notebook。在 GitHub 上,HTML 表示形式无法渲染,请尝试使用 nbviewer.org 加载此页面。
参数
参数
('feat1', 'feat3')参数
参数
('feat0', 'feat2')参数
参数
参数
脚本总运行时间: (0 minutes 0.027 seconds)
相关示例