【问题标题】:Last step of Pipeline should implement fit or be the string 'passthrough'Pipeline 的最后一步应该实现 fit 或者是字符串 'passthrough'
【发布时间】:2021-10-06 23:13:40
【问题描述】:

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

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

怎么了?我该如何解决?

【问题讨论】:

    标签: machine-learning scikit-learn


    【解决方案1】:

    您应该使用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())])
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-06
      • 2021-09-12
      • 2021-01-04
      • 2021-02-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多