Data & Feature Engineering

Feature Engineering Fundamentals

Better data beats fancy algorithms. Where 80% of real-world model accuracy improvements actually come from.

🟢 beginner4 min readfeaturesmust-know
Feature engineering extracts predictive signals from raw data. Techniques must match the target model family: tree-based models need minimal scaling but benefit from target stats and ratios; linear/neural models require strict feature scaling, one-hot encoding, and non-linear log or cyclical transforms (sin/cos). Key topics include handling missingness, high-cardinality encodings, interaction features, and preventing target leakage.

Encodings matched to model family

Feature engineering choice depends entirely on the model downstream:

TechniqueLinear Models / Neural NetsTree Models (GBDT / RF)
Feature ScalingMandatory (StandardScaler / MinMax)Not required (Invariant to monotonic scaling)
Low-Cardinality CategoricalsOne-Hot EncodingCategorical / Ordinal / One-Hot
High-Cardinality CategoricalsTarget Encoding / Entity EmbeddingsTarget Encoding (Out-of-Fold) / Frequency
Non-Linear RelationshipsLog transform, Polynomials, SplinesLearned naturally via recursive splits
Feature InteractionsExplicit crosses (x1 × x2)Learned implicitly along tree branches
Missing ValuesImputation (Mean/Median/Iterative)Native handling (sent to best split direction)

Handling continuous variables & non-linear transformations

  1. Log Transformation (log1p(x)): Re-shapes right-skewed heavy-tailed distributions (income, price, transaction amount) into near-Gaussian shapes, reducing outlier distortion.
  2. Box-Cox / Yeo-Johnson: Automated power transformations to stabilize variance and normalize distributions.
  3. Binning / Discretization: Converts continuous feature into categorical bins (quantile or uniform), enabling linear models to capture non-linear step functions.

Time & cyclical features

Timestamp columns hold rich signal when decomposed:

x_sin = np.sin(2 * np.pi * hour / 24.0)
x_cos = np.cos(2 * np.pi * hour / 24.0)

This guarantees Distance(23h, 0h) == Distance(0h, 1h).

Say this out loud

"Feature engineering must be tailored to model choice. Linear models and neural networks require strict normalization, one-hot encoding, log transforms for skewed inputs, and cyclical sin/cos encodings for periodic time features. Tree models are invariant to monotonic scaling, but benefit immensely from out-of-fold target encoding for high-cardinality categories, domain-specific interaction ratios, and window aggregations."

Follow-ups to expect

Check yourself

Question 1 of 3

Why should cyclical time features like 'hour of day' (0–23) be transformed into sine and cosine pairs rather than passed as raw integers to a Logistic Regression model?

More in Data & Feature Engineering

See all →
SQL Questions in ML Interviews5 minEncoding Categorical Variables4 minScaling & Normalization5 min