I am reading through Hands-On Machine Learning with Scikit-Learn & TensorFlow. We are going over scikit-learn Transformation Pipelines for preparing data for the machine learning algorithms.
Here is the code (housing_num
is a dataframe of the numerical attributes of the main dataframe housing):
num_pipeline = Pipeline([
('imputer', Imputer(strategy='median')),
('attribs_adder', CombinedAttributesAdder()),
('std_scaler', StandardScaler())
])
housing_num_tr = num_pipeline.fit_transform(housing_num)
The text explains:
The Pipeline constructor takes a list of name/estimator pairs defining a sequence of steps. All but the last estimator must be transformers (i.e., they must have a
fit_transform()
method).
Why do we
fit_transform()
some, but onlyfit()
without transforming others? I am guessing this has to do with the difference between estimators and transformers, which I am confused on in this context.So when using
Pipeline
, you can only include one estimator that won't be transformed, and it has to be the last input? ("all but the last estimator must be transformers")