Error creating a pipeline in Python

Discussion in 'Masters Program - Customers only' started by Ovo Okpubuluku, Mar 15, 2020.

  1. Ovo Okpubuluku

    Jul 16, 2019
    Likes Received:
    Dear all,
    I was trying to execute a piece of code from the self-learning section, particularly on Pipeline in the sklear section.

    I ran into the following problem when I am trying to make a pipeline object (in blue).

    import pandas as pd
    import numpy as np

    from sklearn.pipeline import Pipeline
    from sklearn.linear_model import LogisticRegression
    from sklearn.linear_model import LinearRegression
    from sklearn.decomposition import PCA

    estimator = [('dim_reduction',PCA()), ('logReg_model',LogisticRegression()), ('linear_model',LinearRegression())]

    pipeline_estimator = Pipeline(estimator)

    It give the following error...
    TypeError Traceback (most recent call last)
    <ipython-input-17-3c68d56d97e0> in <module>
    1 # create a pipeline object and pss the chain estimators to it
    ----> 2pipeline_estimator = Pipeline(estimator)

    /opt/anaconda3/lib/python3.6/site-packages/sklearn/ in __init__(self, steps, memory)
    117 def __init__(self, steps, memory=None):
    118 self.steps = steps
    --> 119self._validate_steps()
    120 self.memory = memory

    /opt/anaconda3/lib/python3.6/site-packages/sklearn/ in _validate_steps(self)
    165 raise TypeError("All intermediate steps should be "
    166 "transformers and implement fit and transform."
    --> 167 " '%s' (type %s) doesn't" % (t, type(t)))
    169 # We allow last estimator to be None as an identity transformation

    TypeError: All intermediate steps should be transformers and implement fit and transform. 'LogisticRegression(C=1.0, class_weight=None, dual=False, fit_intercept=True,
    intercept_scaling=1, max_iter=100, multi_class='warn',
    n_jobs=None, penalty='l2', random_state=None, solver='warn',
    tol=0.0001, verbose=0, warm_start=False)' (type <class 'sklearn.linear_model.logistic.LogisticRegression'>) doesn't
    I will appreciate any suggestion, hints or comments.
    Thank you in advance!

Share This Page