ageron / handson-ml

⛔️ DEPRECATED – See https://github.com/ageron/handson-ml3 instead.
Apache License 2.0
25.22k stars 12.91k forks source link

All intermediate steps should be transformers and implement fit and transform or be the string 'passthrough' 'CombinedAttributesAdder()' (type <class '__main__.CombinedAttributesAdder'>) doesn't #640

Closed MahadAftab closed 3 years ago

MahadAftab commented 3 years ago

I have written this quote and I am getting the error.

from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.impute import SimpleImputer

num_pipeline = Pipeline([
    ('imputer', SimpleImputer(strategy="median")),
    ('attribs_adder', CombinedAttributesAdder()),
    ('std_scaler', StandardScaler())
])
housing_num_tr =  num_pipeline.fit_transform(housing_num)
TypeError                                 Traceback (most recent call last)
<ipython-input-34-695d9dc86d74> in <module>
----> 1 num_pipeline = Pipeline([
      2     ('imputer', SimpleImputer(strategy="median")),
      3     ('attribs_adder', CombinedAttributesAdder()),
      4     ('std_scaler', StandardScaler())
      5 ])

~\anaconda3\lib\site-packages\sklearn\utils\validation.py in inner_f(*args, **kwargs)
     61             extra_args = len(args) - len(all_args)
     62             if extra_args <= 0:
---> 63                 return f(*args, **kwargs)
     64 
     65             # extra_args > 0

~\anaconda3\lib\site-packages\sklearn\pipeline.py in __init__(self, steps, memory, verbose)
    116         self.memory = memory
    117         self.verbose = verbose
--> 118         self._validate_steps()
    119 
    120     def get_params(self, deep=True):

~\anaconda3\lib\site-packages\sklearn\pipeline.py in _validate_steps(self)
    166             if (not (hasattr(t, "fit") or hasattr(t, "fit_transform")) or not
    167                     hasattr(t, "transform")):
--> 168                 raise TypeError("All intermediate steps should be "
    169                                 "transformers and implement fit and transform "
    170                                 "or be the string 'passthrough' "

TypeError: All intermediate steps should be transformers and implement fit and transform or be the string 'passthrough' 'CombinedAttributesAdder()' (type <class '__main__.CombinedAttributesAdder'>) doesn't