Topics / 🤖 AI & Machine Learning / 📏 Level 22: Evaluate & Engineer

Python exercise · about 5 minutes · free

Pipelines: Scale + Model Together

Scaling on all the data before splitting quietly leaks test information. Pipelines prevent that mistake.

make_pipeline(StandardScaler(), LogisticRegression()) bundles preprocessing and the model, so scaling is learned only from the data the pipeline is fitted on, every time (including inside cross-validation).

Flow: raw X → StandardScaler (learned from fit data only) → LogisticRegression → predictions. one object: fit, predict and cross-validate without leaking test dataraw XStandardScalerlearned from fit data onlyLogisticRegressionpredictionsone object: fit, predict and cross-validate without leaking test data
Your quest: Build pipe = StandardScaler + LogisticRegression, fit it on the iris data, and set acc to its training accuracy.
Try it now Runs in your browser. No sign-in needed. Ctrl+Enter to run.
Hintpipe = make_pipeline(StandardScaler(), LogisticRegression()).fit(X, y); acc = pipe.score(X, y)
Output appears here.

Open it in the full course → Free with Google: saves your progress and unlocks 627 lessons.

In this level you'll learn:
More in Level 22: Evaluate & Engineer

Share on LinkedIn