Boom
Boom

Reputation: 1325

Last step of Pipeline should implement fit or be the string 'passthrough'

I'm trying to build simple pipeline:

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))])

And I'm getting error:

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

What is wrong ? How can I fix it ?

Upvotes: 2

Views: 6644

Answers (1)

Meti
Meti

Reputation: 2056

you should use pipeline instead of make_pipeline due to you provided the steps with names (more on this 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))])

output:

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

Upvotes: 4

Related Questions