日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

pipeline python,Python-什么是sklearn.pipeline.Pipeline?

發布時間:2023/12/3 python 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 pipeline python,Python-什么是sklearn.pipeline.Pipeline? 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

I can't figure out how the sklearn.pipeline.Pipeline works exactly.

There are a few explanation in the doc. For example what do they mean by:

Pipeline of transforms with a final estimator.

To make my question clearer, what are steps? How do they work?

Edit

Thanks to the answers I can make my question clearer:

When I call pipeline and pass, as steps, two transformers and one estimator, e.g:

pipln = Pipeline([("trsfm1",transformer_1),

("trsfm2",transformer_2),

("estmtr",estimator)])

What happens when I call this?

pipln.fit()

OR

pipln.fit_transform()

I can't figure out how an estimator can be a transformer and how a transformer can be fitted.

解決方案

Transformer in scikit-learn - some class that have fit and transform method, or fit_transform method.

Predictor - some class that has fit and predict methods, or fit_predict method.

Pipeline is just an abstract notion, it's not some existing ml algorithm. Often in ML tasks you need to perform sequence of different transformations (find set of features, generate new features, select only some good features) of raw dataset before applying final estimator.

Here is a good example of Pipeline usage.

Pipeline gives you a single interface for all 3 steps of transformation and resulting estimator. It encapsulates transformers and predictors inside, and now you can do something like:

vect = CountVectorizer()

tfidf = TfidfTransformer()

clf = SGDClassifier()

vX = vect.fit_transform(Xtrain)

tfidfX = tfidf.fit_transform(vX)

predicted = clf.fit_predict(tfidfX)

# Now evaluate all steps on test set

vX = vect.fit_transform(Xtest)

tfidfX = tfidf.fit_transform(vX)

predicted = clf.fit_predict(tfidfX)

With just:

pipeline = Pipeline([

('vect', CountVectorizer()),

('tfidf', TfidfTransformer()),

('clf', SGDClassifier()),

])

predicted = pipeline.fit(Xtrain).predict(Xtrain)

# Now evaluate all steps on test set

predicted = pipeline.predict(Xtest)

With pipelines you can easily perform a grid-search over set of parameters for each step of this meta-estimator. As described in the link above. All steps except last one must be transforms, last step can be transformer or predictor.

Answer to edit:

When you call pipln.fit() - each transformer inside pipeline will be fitted on outputs of previous transformer (First transformer is learned on raw dataset). Last estimator may be transformer or predictor, you can call fit_transform() on pipeline only if your last estimator is transformer (that implements fit_transform, or transform and fit methods separately), you can call fit_predict() or predict() on pipeline only if your last estimator is predictor. So you just can't call fit_transform or transform on pipeline, last step of which is predictor.

總結

以上是生活随笔為你收集整理的pipeline python,Python-什么是sklearn.pipeline.Pipeline?的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。