gpt4 book ai didi

machine-learning - Pipeline 的最后一步应该实现 fit 或者是字符串 'passthrough'

转载 作者:行者123 更新时间:2023-12-05 02:40:23 34 4
gpt4 key购买 nike

我正在尝试构建简单的管道:

from sklearn.linear_model import Lasso
from sklearn.preprocessing import PolynomialFeatures
from sklearn.pipeline import make_pipeline


make_pipeline([
('PolynomialFeatures', PolynomialFeatures(include_bias=False)),
('Lasso', Lasso(fit_intercept=True, max_iter=1000))])

我收到错误:

TypeError: Last step of Pipeline should implement fit or be the string 'passthrough'. '[('PolynomialFeatures', PolynomialFeatures(include_bias=False)), ('Lasso', Lasso())]' (type <class 'list'>) doesn't

怎么了?我该如何解决?

最佳答案

您应该使用 pipeline 而不是 make_pipeline 因为您提供了带名称的步骤(更多信息 here !)。

from sklearn.linear_model import Lasso
from sklearn.preprocessing import PolynomialFeatures
from sklearn.pipeline import make_pipeline, Pipeline


Pipeline([
('PolynomialFeatures', PolynomialFeatures(include_bias=False)),
('Lasso', Lasso(fit_intercept=True, max_iter=1000))])

输出:

Pipeline(steps=[('PolynomialFeatures', PolynomialFeatures(include_bias=False)),
('Lasso', Lasso())])

关于machine-learning - Pipeline 的最后一步应该实现 fit 或者是字符串 'passthrough',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68607375/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com