Classical Machine Learning

Feature Engineering

Feature engineering turns raw data into model-usable signal. In classical ML, better features often beat fancier algorithms; in deep learning, learned representations reduce but do not eliminate feature thinking.
  • Features define what the model can notice
  • Categorical variables need deliberate encoding
  • Aggregates are often high-value features
  • Time awareness prevents leakage
  • Pipelines protect train/serve consistency
  • Feature quality is often product knowledge
Feature engineering moves
MoveExampleRisk
ScalingStandardize numeric inputsFitting scaler on all data leaks validation/test
EncodingOne-hot country or product tierHigh-cardinality explosion
Rolling aggregatepurchases_last_30_daysFuture leakage
Ratioprice_per_square_meterDivide-by-zero / noisy denominator
Text featureTF-IDF or embeddingVocabulary drift / privacy
Interactionplan_type × regionOverfitting rare combinations
Keep preprocessing inside the validation path
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler, OneHotEncoder
from sklearn.compose import ColumnTransformer
from sklearn.linear_model import LogisticRegression

preprocess = ColumnTransformer([
    ("num", StandardScaler(), numeric_cols),
    ("cat", OneHotEncoder(handle_unknown="ignore"), categorical_cols),
])

pipeline = Pipeline([
    ("features", preprocess),
    ("model", LogisticRegression(max_iter=1000)),
])

# cross_val_score fits preprocessing separately inside each fold.
scores = cross_val_score(pipeline, X, y, cv=5)
This avoids fitting preprocessing on validation/test data by accident.
Sources
  • Machine Learning Crash CourseWorking with numerical and categorical data
  • scikit-learn User GuidePreprocessing data
  • Rules of Machine LearningFeature engineering guidance