Module 3 · step 3 of 4 · Pipelines and preprocessing

Why preprocessing matters

What encoding, scaling and imputation do, and why they are fitted on training rows only.

Concept8 min

In this step you learn what each kind of preprocessing does and find it in the editor you already used. It matters because knowing why a step exists lets you decide what each column needs, instead of applying everything.

The idea

Raw data is rarely in the form an algorithm can use. Three families cover most needs.

Imputation fills missing values, for example with the median or the most frequent category. In the app these are the Fill missing values operations. Without it, many algorithms stop or silently drop rows.

Encoding turns categories into numbers. One-hot creates a 0/1 column per category and suits few categories. Target encoding suits many categories but uses the answer to build a feature, so it needs care. In the editor these sit under Turn categories into numbers.

Scaling puts numeric columns on comparable ranges. Standardise gives zero mean and unit spread; a robust scaler uses the median and is less moved by outliers. Distance-based and gradient-based algorithms, such as nearest neighbours and neural networks, depend on scale. Tree-based ones, such as forests and boosting, do not. Find them under Scale numbers.

One rule sits above all: every step that learns from data (a mean, a fill value, a set of categories) must learn from the training rows only. Then the same fitted step transforms the hold-out rows and any future row. If it learns from everything, test information leaks into training.

Step by step

  1. Open the seeded churn pipeline, Columns part. Press the chip on department and read its Before and after: the categories become 0/1 columns.
  2. Press a numeric column's chip and compare Before and after: the values are recentred and rescaled.
  3. Look for Suggested: on a column with empty cells and press "?" to read the figures behind the rule.
  4. In Steps in order, check that filling comes before scaling.
  5. Open Review & run and select Check without running to see how many columns reach the models.

Columns that no step handles do not stop a run: text categories are ordinal-encoded, dates are split into year, month, day and day of week, booleans become 0 and 1, and empty or free-text columns are dropped. At prediction time, missing numeric and boolean values are filled with values learned on the training rows. Choosing the steps yourself gives you control. mlflow stores the fitted steps with the model, so a deployed endpoint applies them to the raw values you send.

Common mistakes

  • One-hot encoding a column with hundreds of categories: the table gets very wide. Check the column's values in the table first.
  • Scaling for a tree-based model and expecting a gain; it rarely changes anything.
  • Filling a skewed column with the mean; the median is often safer.
  • Encoding an ID column. It carries no pattern and invites memorising.
  • Putting steps in the wrong order. The check reports "Step N already replaced..." with an Open step N link.

As a data scientist

Preparation fitted on the whole dataset is the most common silent leak: the score looks better in the notebook and worse in production. Doing it as pipeline steps removes the problem. Start with simple preparation and a baseline to beat; add complexity only when Before and after and the leaderboard justify it.

Where to go next

For the reasoning behind each family, read Scaling, Encoding, Imputation and Transformations.

Theory to read next

Read in the docs