sklearn之pipeline:sklearn.pipeline函数使用及其参数解释之详细攻略

简介: sklearn之pipeline:sklearn.pipeline函数使用及其参数解释之详细攻略

sklearn.pipeline函数使用及其参数解释


class Pipeline(_BaseComposition):

   """

   Pipeline of transforms with a final estimator.

   Sequentially apply a list of transforms and a final estimator.

   Intermediate steps of the pipeline must be 'transforms', that is, they must implement fit and transform methods.

   The final estimator only needs to implement fit.

   The transformers in the pipeline can be cached using ``memory`` argument.

The purpose of the pipeline is to assemble several steps that can be cross-validated together while setting different parameters.

   For this, it enables setting parameters of the various steps using their  names and the parameter name separated by a '__', as in the example below.

   A step's estimator may be replaced entirely by setting the parameter with its name to another estimator, or a transformer removed by setting  it to 'passthrough' or ``None``.

   Read more in the :ref:`User Guide <pipeline>`.

   .. versionadded:: 0.5

具有最终估计器的转换管道。

按顺序应用一组转换和一个最终的估计器。

管道的中间步骤必须是“transforms”,也就是说,它们必须实现fit和transform方法。

最终的评估器只需要实现fit。

可以使用“memory”参数缓存管道中的转换器。

管道的目的是将几个可以交叉验证的步骤组装在一起,同时设置不同的参数。

为此,它允许使用它们的名称和由“__”分隔的参数名称来设置各个步骤的参数,如下例所示。

可以通过将参数的名称设置为另一个估计器来完全替换步骤的估计器,或者通过将其设置为“passthrough”或“None”来删除转换器。

详见:ref: ' User Guide  '。</pipeline>

. .versionadded:: 0.5

   Parameters

   ----------

   steps : list. List of (name, transform) tuples (implementing fit/transform) that are chained, in the order in which they are chained, with the last object an estimator.

   memory : str or object with the joblib.Memory interface, default=None. Used to cache the fitted transformers of the pipeline. By default, no caching is performed. If a string is given, it is the path to the caching directory. Enabling caching triggers a clone of the transformers before fitting. Therefore, the transformer instance given to the pipeline cannot be inspected directly. Use the attribute ``named_steps`` or ``steps`` to inspect estimators within the pipeline. Caching the transformers is advantageous when fitting is time consuming.

   verbose : bool, default=False. If True, the time elapsed while fitting each step will be printed as it is completed.

   Attributes

   ----------

   named_steps: :class:`~sklearn.utils.Bunch`

   Dictionary-like object, with the following attributes. Read-only attribute to access any step parameter by user given name. Keys are step names and values are steps parameters.

 

   See Also

   --------

   sklearn.pipeline.make_pipeline : Convenience function for simplified pipeline construction.

steps :列表。(名称、转换)元组(实现fit/转换)的列表,按照它们被链接的顺序,最后一个对象是评估器。

memory:str或物体与joblib。内存接口,默认=没有。用于缓存安装在管道中的变压器。默认情况下,不执行缓存。如果给定一个字符串,它就是到缓存目录的路径。启用缓存会在安装前触发变压器的克隆。因此,给管线的变压器实例不能直接检查。使用属性' ' named_steps ' ' '或' ' steps ' '检查管道中的评估器。当装配耗时时,缓存变压器是有利的。

verbose :bool,默认=False。如果为真,在完成每个步骤时所经过的时间将被打印出来。

属性

----------

named_steps::类:“~ sklearn.utils.Bunch”

类字典的对象,具有以下属性。只读属性,按用户名访问任何步骤参数。键是步骤名称,值是步骤参数。

另请参阅

--------

sklearn.pipeline。make_pipeline:简化管道构造的方便函数。

   Examples

   --------

   >>> from sklearn.svm import SVC

   >>> from sklearn.preprocessing import StandardScaler

   >>> from sklearn.datasets import make_classification

   >>> from sklearn.model_selection import train_test_split

   >>> from sklearn.pipeline import Pipeline

   >>> X, y = make_classification(random_state=0)

   >>> X_train, X_test, y_train, y_test = train_test_split(X, y,

   ...                                                     random_state=0)

   >>> pipe = Pipeline([('scaler', StandardScaler()), ('svc', SVC())])

   >>> # The pipeline can be used as any other estimator

   >>> # and avoids leaking the test set into the train set

   >>> pipe.fit(X_train, y_train)

   Pipeline(steps=[('scaler', StandardScaler()), ('svc', SVC())])

   >>> pipe.score(X_test, y_test)

   0.88




相关文章
|
机器学习/深度学习 算法 TensorFlow
Py之imblearn:imblearn/imbalanced-learn库的简介、安装、使用方法之详细攻略
Py之imblearn:imblearn/imbalanced-learn库的简介、安装、使用方法之详细攻略
Py之imblearn:imblearn/imbalanced-learn库的简介、安装、使用方法之详细攻略
|
机器学习/深度学习 数据采集 数据处理
Pipeline基础语法
Pipeline是处理数据流和构建机器学习模型的重要工具,它能够简化代码、提高可读性并减少错误。通过本篇文章,读者应能掌握Pipeline的基本语法、使用方法及其在数据科学中的重要性。正确使用Pipeline将极大地提高机器学习项目的效率与可靠性。希望本文能为您的数据处理工作提供实用的指导和帮助。
1397 9
|
机器学习/深度学习 编解码 计算机视觉
RT-DETR改进策略【Backbone/主干网络】| 替换骨干网络为:Swin Transformer,提高多尺度特征提取能力
RT-DETR改进策略【Backbone/主干网络】| 替换骨干网络为:Swin Transformer,提高多尺度特征提取能力
766 12
RT-DETR改进策略【Backbone/主干网络】| 替换骨干网络为:Swin Transformer,提高多尺度特征提取能力
|
大数据 开发者 C++
Python语法糖详解教程
《Python语法糖详解教程》介绍了编程语言中的“语法糖”,即通过特殊语法形式简化代码,使代码更简洁、易读和高效。文章详细解析了列表推导式、字典推导式、元组解包、条件表达式、with语句和装饰器等核心语法糖,并提供了具体示例和最佳实践指南。通过这些技巧,开发者可以在保持底层功能不变的前提下,显著提升开发效率和代码质量。
1181 8
|
数据处理 开发者 Python
【Python】已解决:FileNotFoundError: [Errno 2] No such file or directory: ‘E:\自动备份文档\Python\修改配置.csv‘
【Python】已解决:FileNotFoundError: [Errno 2] No such file or directory: ‘E:\自动备份文档\Python\修改配置.csv‘
3776 1
|
机器学习/深度学习 编解码 Java
YOLOv11改进策略【卷积层】| GnConv:一种通过门控卷积和递归设计来实现高效、可扩展、平移等变的高阶空间交互操作
YOLOv11改进策略【卷积层】| GnConv:一种通过门控卷积和递归设计来实现高效、可扩展、平移等变的高阶空间交互操作
453 0
YOLOv11改进策略【卷积层】| GnConv:一种通过门控卷积和递归设计来实现高效、可扩展、平移等变的高阶空间交互操作
|
机器学习/深度学习 数据采集 算法
利用scikit-learn进行时间序列预测
【4月更文挑战第17天】本文介绍了如何使用Scikit-learn进行时间序列预测,涉及数据预处理(如缺失值填充、平滑和特征提取)、模型选择(线性回归、SVM、随机森林等)、模型评估与优化(如MSE、RMSE、MAE作为评估指标,超参数优化和模型融合)。Scikit-learn为时间序列预测提供了强大支持,但实际应用需结合问题需求和数据特性。未来可探索深度学习在此领域的应用。
1190 99
|
机器学习/深度学习 数据采集 算法
Python机器学习:Scikit-learn库的高效使用技巧
【10月更文挑战第28天】Scikit-learn 是 Python 中最受欢迎的机器学习库之一,以其简洁的 API、丰富的算法和良好的文档支持而受到开发者喜爱。本文介绍了 Scikit-learn 的高效使用技巧,包括数据预处理(如使用 Pipeline 和 ColumnTransformer)、模型选择与评估(如交叉验证和 GridSearchCV)以及模型持久化(如使用 joblib)。通过这些技巧,你可以在机器学习项目中事半功倍。
465 3
|
机器学习/深度学习 存储 数据采集
强化学习系列:A3C算法解析
【7月更文挑战第13天】A3C算法作为一种高效且广泛应用的强化学习算法,通过结合Actor-Critic结构和异步训练的思想,实现了在复杂环境下的高效学习和优化策略的能力。其并行化的训练方式和优势函数的引入,使得A3C算法在解决大规模连续动作空间和高维状态空间的问题上表现优异。未来,随着技术的不断发展,A3C算法有望在更多领域发挥重要作用,推动强化学习技术的进一步发展。
1212 9
|
存储 XML JSON
使用Protocol Buffers优化数据传输
使用Protocol Buffers优化数据传输