NPS估计器和复杂管道#

此示例说明了显示估计器和管道的不同方式。

# 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(penalty="l1")
print(lr)
LogisticRegression(penalty='l1')

富HTML表示#

在笔记本中,估计器和管道将使用丰富的HTML表示。这对于总结管道和其他复合估计器的结构特别有用,并通过交互性提供细节。 单击下面的示例图像以展开Pipeline元素。 看到 可视化复合估计器 了解如何使用此功能。

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())])
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.


Total running time of the script: (0分0.029秒)

相关实例

管道

Displaying Pipelines

scikit-learn 0.23的发布亮点

Release Highlights for scikit-learn 0.23

使用堆叠组合预测因子

Combine predictors using stacking

混合类型的列Transformer

Column Transformer with Mixed Types

Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io> _