Skip to content

Chapter 2 (page90), full_pipeline.transform() #637

@luluqinqin

Description

@luluqinqin

Hi Aurélien,

Thank you for a GREAT book! I really enjoy reading it and practicing the examples in the book.
In chapter 2, when we need to transform the test data, you mention that not using the fit_transform() as we don't want to fit the test data, and we should use the transform() function. But the SimpleImputer needs to run the fit() first before running the transform(). Can you please illustrate a solution for that? Thank you!!

Lu

Code:

num_pipeline = Pipeline([
    ('imputer', SimpleImputer(strategy = 'median')),
    ('std_scaler', StandardScaler()),
])

#
num_attr = list(test_num)
cat_attr = ['ocean_proximity']   
full_pipeline = ColumnTransformer([
        ("num", num_pipeline, num_attr),
        ("cat", OneHotEncoder(), cat_attr),
    ])
test_x_tr = full_pipeline.transform(test_x) 
test_x_tr

Error:

NotFittedError: This ColumnTransformer instance is not fitted yet. Call 'fit' with
appropriate arguments before using this estimator.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions