← Lesson
BitWithBite
AI & Machine Learning · Quick Reference

lesson-1.3 Cheat Sheet

AI & Machine Learning
In one line: A Pipeline chains a sequence of steps — typically several transformers followed by one final estimator — into a single object exposing the same fit / predict interface as any ot...

Key Ideas

1ColumnTransformer for mixed-type data. Most real datasets mix numeric columns (needing scaling) with categorical columns (needing encoding). ColumnTransformer applies different transformers to different col...
2Why pipelines matter beyond convenience. They make cross-validation safe by construction. If you preprocess your whole dataset once and then run cross-validation, each fold's "test" portion was preprocessed u...

Code Examples

from sklearn.pipeline import Pipeline from sklearn.preprocessing import StandardScaler from sklearn.linear_model import LogisticRegression pipe = Pipeline([ ('scaler', StandardScaler()), ('clf', LogisticRegression()) ]) pipe.fit(X_train, y_...
from sklearn.compose import ColumnTransformer from sklearn.preprocessing import OneHotEncoder preprocessor = ColumnTransformer([ ('num', StandardScaler(), numeric_cols), ('cat', OneHotEncoder(handle_unknown='ignore'), categorical_cols) ]) ...
from sklearn.model_selection import cross_val_score scores = cross_val_score(full_pipe, X, y, cv=5) # Each fold refits preprocessor + model on that fold's train split only