Machine Learning

Preprocessing

Handle missing values, scaling and encoding safely.

Best Practice: Use Pipelines

Keep preprocessing inside a pipeline so training and inference do the exact same thing.

from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression

pipe = Pipeline([
  ("scale", StandardScaler()),
  ("model", LogisticRegression(max_iter=200))
])

Common Steps

  • Missing values: impute (median/most_frequent) or drop.
  • Scaling: important for SVM/KNN/logistic regression.
  • Encoding: one-hot for categories (start simple).