Skip to main content

Module 4 Review

You have learned to combine preprocessing and a model into one object. This page sums up the Self-study of this module and checks the main ideas.

Summary

  • Pipelines & ColumnTransformer:
    • A Pipeline chains transformers and a model: one fit, one predict, and you save one object.
    • In cross-validation, a pipeline fits every step in each fold on the training part only, so no information from the validation folds leaks into the preprocessing.
    • A ColumnTransformer gives different columns different preprocessing; make_column_selector, OneHotEncoder(handle_unknown="ignore") and get_feature_names_out help with real data.
    • Parameters of a step are set as step__parameter, which lets you tune the preprocessing and the model together.

Quiz

These questions are easy if you have worked through the activities. Choose an answer to see whether it is right and why.

Why does a pipeline make cross-validation correct?

  • It makes the training faster, so you can use more folds in the same time.
  • It refits the preprocessing in each fold, on the training part.
  • It chooses the best model for you by trying them all.

A pipeline has an SVR step called model. How do you set its C to 10?

  • pipeline.set_params(model__C=10)
  • pipeline.set_params(C=10)
  • pipeline.steps[1].C = 10, the second step of the pipeline

Your data has numeric columns and one column with text categories. Which tool gives each type of column its own preprocessing?

  • A StandardScaler, which scales every column.
  • A second model for the text column.
  • A ColumnTransformer.