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).
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.
Hint
pipe = make_pipeline(StandardScaler(), LogisticRegression()).fit(X, y); acc = pipe.score(X, y)Output appears here.