Skip to Content
Python机器学习基础教程
book

Python机器学习基础教程

by Andreas C. Müller, Sarah Guido
January 2018
Intermediate to advanced
301 pages
8h 54m
Chinese
Posts & Telecom Press
Content preview from Python机器学习基础教程
算法链与管道
243
6-3:管道的训练和预测过程概述
管道实际上比上图更加通用。管道的最后一步不需要具有
predict
函数,比如说,我们可
以创建一个只包含一个缩放器和一个 PCA 的管道。由于最后一步(PCA)具有 transform
法,所以我们可以对管道调用 transform,以得到将 PCA.transform 应用于前一个步骤处理
过的数据后得到的输出。管道的最后一步只需要具有 fit 方法。
6.4.1
 用
make_pipeline
方便地创建管道
利用上述语法创建管道有时有点麻烦,我们通常不需要为每一个步骤提供用户指定的名
称。有一个很方便的函数 make_pipeline,可以为我们创建管道并根据每个步骤所属的类
为其自动命名。make_pipeline 的语法如下所示:
In[17]:
from sklearn.pipeline import make_pipeline
# 标准语法
pipe_long = Pipeline([("scaler", MinMaxScaler()), ("svm", SVC(C=100))])
# 缩写语法
pipe_short = make_pipeline(MinMaxScaler(), SVC(C=100))
管道对象 pipe_long pipe_short 的作用完全相同,但 pipe_short 的步骤是自动命名的。
我们可以通过查看 steps 属性来查看步骤的名称:
In[18]:
print("Pipeline steps:\n{}".format(pipe_short.steps)) ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

数据驱动力:企业数据分析实战

数据驱动力:企业数据分析实战

Carl Anderson
Python应用开发指南

Python应用开发指南

Posts & Telecom Press, Ninad Sathaye
管理Kubernetes

管理Kubernetes

Brendan Burns, Craig Tracey

Publisher Resources

ISBN: 9787115475619