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库的简介、安装、使用方法之详细攻略
|
10月前
|
存储 数据可视化 安全
万字长文读懂低代码(Low-Code)前世今生、分类、能力、趋势及选型
低代码是一种可视化应用开发方式,通过拖拽、配置等方式快速构建系统,降低开发门槛,提升效率。它起源于上世纪80年代,发展至今已广泛应用于ERP、CRM、MES等企业系统。低代码平台具备可视化编程、预置组件、快速部署、多端支持等功能,适合不同规模企业的多样化需求。相比传统开发,其优势在于缩短开发周期、促进业务与技术融合。
|
机器学习/深度学习 数据采集 数据处理
Pipeline基础语法
Pipeline是处理数据流和构建机器学习模型的重要工具,它能够简化代码、提高可读性并减少错误。通过本篇文章,读者应能掌握Pipeline的基本语法、使用方法及其在数据科学中的重要性。正确使用Pipeline将极大地提高机器学习项目的效率与可靠性。希望本文能为您的数据处理工作提供实用的指导和帮助。
1345 9
|
机器学习/深度学习 数据采集 算法
Python机器学习:Scikit-learn库的高效使用技巧
【10月更文挑战第28天】Scikit-learn 是 Python 中最受欢迎的机器学习库之一,以其简洁的 API、丰富的算法和良好的文档支持而受到开发者喜爱。本文介绍了 Scikit-learn 的高效使用技巧,包括数据预处理(如使用 Pipeline 和 ColumnTransformer)、模型选择与评估(如交叉验证和 GridSearchCV)以及模型持久化(如使用 joblib)。通过这些技巧,你可以在机器学习项目中事半功倍。
437 3
|
机器学习/深度学习 算法 Python
LightGBM高级教程:时间序列建模
LightGBM高级教程:时间序列建模【2月更文挑战第7天】
1096 0
LabVIEW中不同颜色连线的含义
LabVIEW中不同颜色连线的含义
583 2
|
达摩院 供应链 JavaScript
网络流问题--仓储物流调度【数学规划的应用(含代码)】阿里达摩院MindOpt
本文通过使用MindOpt工具优化仓储物流调度问题,旨在提高物流效率并降低成本。首先,通过考虑供需匹配、运输时间与距离、车辆容量、仓库储存能力等因素构建案例场景。接着,利用数学规划方法,包括线性规划和网络流问题,来建立模型。在网络流问题中,通过定义节点(资源)和边(资源间的关系),确保流量守恒和容量限制条件下找到最优解。文中还详细介绍了MindOpt Studio云建模平台和MindOpt APL建模语言的应用,并通过实例展示了如何声明集合、参数、变量、目标函数及约束条件,并最终解析了求解结果。通过这些步骤,实现了在满足各仓库需求的同时最小化运输成本的目标。
|
数据处理 开发者 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‘
3701 1
|
存储 XML JSON
使用Protocol Buffers优化数据传输
使用Protocol Buffers优化数据传输
|
机器学习/深度学习 人工智能 供应链
人工智能在社会中的影响与未来展望
人工智能(AI)作为一项重要的技术革新,正在深刻地改变着我们的生活方式、工作方式以及社会结构。本文旨在探讨人工智能在社会中的影响,并展望其未来发展趋势。首先,我们回顾了人工智能的发展历程,从其起源到当前的发展阶段,概述了人工智能技术的基本原理和应用领域。其次,我们分析了人工智能对各个行业的影响,包括但不限于医疗保健、金融、制造业、交通运输和教育等领域。人工智能的广泛应用使得这些行业更加智能化、高效化,但也带来了一些挑战,如就业岗位的变化、隐私安全问题等。接着,我们讨论了人工智能在社会中的伦理和道德问题,包括人工智能算法的公平性、透明性和责任问题。最后,我们展望了人工智能的未来发展,包括强化学习
1015 0