Machine Learning β€Ί Features and Support Vector Machines β€Ί Day 170

Day 170: Feature Scaling and Encoding

Day 170 of 365 β€” Feature Scaling and Encoding

Master the mathematical theory and practical implementation of Feature Scaling and Categorical Encoding: understand why gradient descent condition numbers and distance metrics demand scaling, compare StandardScaler vs MinMaxScaler vs RobustScaler vs MaxAbsScaler, master categorical encodings from One-Hot to Out-of-Fold Smoothed Target Encoding with Bayesian shrinkage, and identify exact scaling and encoding rules across all major model families.

Course
Machine Learning
Category
Features and Support Vector Machines
Reading time
β‰ˆ 50 min
Practical time
β‰ˆ 60 min
Lesson duration
1h 50m
Last verified
2026-08-29

Hands-on lab for this lesson

Lab files on GitHub: https://github.com/ai-roadmap-365/ai-roadmap-365.github.io/tree/main/labs/sections/machine-learning/day-170-feature-scaling-and-encoding

  1. Get the hands-on files. Clone the labs repository once (you can reuse this clone for every lesson). This works on macOS, Linux, and Windows (PowerShell or WSL):
    git clone https://github.com/ai-roadmap-365/ai-roadmap-365.github.io.git
    cd ai-roadmap-365.github.io
  2. Open this lesson's lab. Move into the directory for this specific day. Every lab lives at the same predictable path β€” section / subsection / week / day:
    cd labs/sections/machine-learning/day-170-feature-scaling-and-encoding
  3. Read the lab guide. Open `README.md` in that directory. It lists the exact commands, what each does, the expected output, and how to check your work β€” read it before running anything.
  4. Run it and check your work. Follow the README's "How to run" section: run the example first to see the finished result, then complete the numbered exercises in `starter/`, then run the tests. The tests pass (exit 0) only when your work is correct.
    bash tests/run_tests.sh   # or the test command named in the lab README

You can also open the lab as a local page (works offline, shows the file tree and expected output).

Learning objectives

By the end of this lesson you will be able to:

Prerequisites

Why this matters

In Weeks 23 and 24, we built linear models, SVMs, and tree ensembles.

Yet raw real-world data never arrives neatly formatted as standardized numbers. A typical enterprise dataset contains:

If you feed these raw columns into a Logistic Regression model or a Support Vector Machine:

  1. Optimization Stalls: The Hessian matrix condition number explodes, causing gradient descent to oscillate wildly and fail to converge.
  2. Distances Collapse: Euclidean distances ||x_1 - x_2|| will be dominated 99.99% by Annual_Income, rendering Age and Credit_Score completely invisible.
  3. L2 Regularization Fails: Penalizing ||w||_2^2 crushes weights on small-magnitude features while ignoring large-scale features.
  4. One-Hot Encoding Blows Up Memory: One-hot encoding ZipCode generates 40,000 sparse columns, exhausting RAM.

Feature scaling and categorical encoding are the first mathematical filters in machine learning. Mastering them prevents silent numerical failures and unlocks peak performance across all model families.


The idea in plain language

Imagine a fitness competition comparing athletes across three events:

If the judges simply add up the three numbers to determine the winner:

Feature Scaling (StandardScaler) converts each event into standard deviations above or below the average (Z-scores), giving every event equal weight.

Categorical Encoding converts descriptive words (like "Gold", "Silver", "Bronze") into numbers so algorithms can process them without inventing false mathematical relationships.


Historical background

In the early 20th century, Karl Pearson formalized the Z-score standard deviation normalization in classical statistics.

In 1964, George Box and David Cox published their seminal work on the Box-Cox Power Transformation, enabling non-normal, skewed positive data to be transformed into Gaussian distributions. In 2000, In-Kwon Yeo and Richard Johnson extended power transformations to handle zero and negative values.

In 2001, Daniele Micci-Barreca published A Preprocessing Scheme for High-Cardinality Categorical Attributes in Classification and Prediction Problems at ACM SIGKDD. This landmark paper introduced Empirical Bayesian Smoothed Target Encoding, solving the curse of dimensionality for categorical variables with thousands of levels.

In 2018, Yandex released CatBoost, revolutionizing target encoding with ordered target statistics to eliminate temporal prediction shifts.


What it is β€” and what it is not

Let us define the scope of feature scaling and categorical encoding:

What it IS:

What it is NOT:


Why it was created and what problems it solves

Proper feature scaling and encoding resolves five critical bottlenecks in machine learning:

  1. Optimizes Gradient Descent Condition Numbers: Restores isotropic circular loss contours, accelerating gradient descent convergence by 10x to 100x.
  2. Balances Distance-Based Algorithms: Ensures kNN, SVM, K-Means, and PCA give equal geometric importance to all features.
  3. Enforces Fair L1/L2 Regularization: Prevents regularization penalties from unfairly penalizing features with small physical units.
  4. Tames High-Cardinality Categories: Replaces 40,000 sparse OHE columns with a single smoothed target-encoded feature.
  5. Normalizes Skewed Heavy Tails: Power transformations (Yeo-Johnson) reshape skewed financial distributions into well-behaved bell curves.

How it works

Let us formulate the mathematics of feature scaling algorithms and categorical encoding strategies.

1. The Condition Number Problem in Gradient Descent

Consider a linear regression model with loss:

L(w) = (1 / 2) * ||X w - y||_2^2

The Hessian matrix of second derivatives is H = X^T X.

Let lambda_{max} and lambda_{min} be the maximum and minimum eigenvalues of H. The Condition Number is:

kappa = lambda_{max} / lambda_{min}


2. The Numerical Scaling Taxonomy

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      FEATURE SCALING ALGORITHMS                        β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 1. StandardScaler:   z = (x - mu) / sigma  [Mean=0, Std=1, Gaussian]   β”‚
β”‚ 2. MinMaxScaler:     z = (x - min) / (max - min)  [Bounded in [0, 1]]  β”‚
β”‚ 3. RobustScaler:     z = (x - Median) / IQR  [Outlier-Resilient]       β”‚
β”‚ 4. MaxAbsScaler:     z = x / max(|x|)  [Preserves Zero Sparsity]       β”‚
β”‚ 5. PowerTransformer: Yeo-Johnson non-linear variance stabilization     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

A. StandardScaler (Z-Score)

Centers data to mean 0 and unit variance 1:

z = (x - mu) / sigma

Where mu = (1/N) sum x_i and sigma = sqrt( (1/N) sum (x_i - mu)^2 ). Weakness: Extreme outliers distort mu and inflate sigma, compressing inliers.

B. RobustScaler (Median & IQR)

Uses rank-based robust statistics:

z = (x - text{Median}(x)) / (Q_{75}(x) - Q_{25}(x))

Where IQR = Q_{75} - Q_{25} is the Interquartile Range. Advantage: 100% resilient against extreme outliers.


3. Categorical Encoding Taxonomy

A. One-Hot Encoding (OHE)

For a categorical variable with k distinct nominal categories { c_1, ..., c_k }: Maps category c_j to binary vector e_j in {0, 1}^k.

To prevent linear multicollinearity (the β€œdummy variable trap”), drop one reference category (drop='first'), producing k - 1 columns. Best Used For: Low-cardinality nominal features (k <= 10).

B. Ordinal Encoding

Maps ordered categories to integers 0, 1, ..., k - 1. Mandatory Condition: Must only be used when an intrinsic mathematical ordering exists (Small < Medium < Large).

C. Out-of-Fold Smoothed Target Encoding (Micci-Barreca, 2001)

For high-cardinality nominal features (e.g. ZipCode), replaces category c with the regularized target mean.

For category c with sample count n_c and category target mean bar{y}_c:

S_c = (n_c * bar{y}_c + m * bar{y}_{text{global}}) / (n_c + m)

Where:

The Leak-Free Out-of-Fold Rule: To prevent target leakage, bar{y}_c and n_c for validation fold k must be calculated strictly on the other K - 1 training folds.


4. Scaling and Encoding Rules by Model Family

Model FamilyScaling RequirementPreferred EncodingRationale
Linear / Logistic RegressionStrictly MandatoryOne-Hot / Target EncodingCondition number, isotropic loss, fair L1/L2 penalties.
Support Vector Machines (SVM)Strictly MandatoryOne-Hot / Target EncodingEuclidean distance and RBF kernel geometry.
k-Nearest Neighbors (kNN)Strictly MandatoryOne-Hot EncodingEuclidean distance metric equality.
Neural Networks (MLP / TabNet)Strictly MandatoryEntity Embeddings / TargetPrevents gradient explosion; smooth activation saturation.
Tree Ensembles (GBDT / RF)Not Required (Invariant)Target Encoding / Native BinsAxis-aligned orthogonal splits depend only on rank order.

An everyday analogy

Think of feature scaling and encoding as translating international currencies and trade goods at a global commodities exchange:

  1. Unscaled Data (The Chaos): Trader A bids in Japanese Yen (Β₯1,000,000), Trader B bids in Kuwaiti Dinar (3 KD), and Trader C bids in Gold Bars. Adding up raw numbers creates total confusion.
  2. StandardScaler (The Standard Currency): Converts all bids into standardized SDRs (Special Drawing Rights) centered at zero, so every currency has equal purchasing power.
  3. RobustScaler (The Outlier-Protected Bank): When a billionaire walks in and bids Β₯100,000,000,000, the bank centers prices using the median merchant rather than letting the billionaire distort the entire exchange rate.
  4. One-Hot Encoding (The Specific Barcodes): Labeling distinct goods (Coffee, Oil, Wheat) with distinct binary barcodes.
  5. Target Encoding (The Market Historical Value): Replaces 40,000 obscure village names with the average historical crop yield of each village, shrinking tiny unknown villages to the national average.

Examples in practice

Let us visualize the distribution impacts of StandardScaler vs MinMaxScaler vs RobustScaler:

Comparison diagram showing original skewed distribution with outlier transformed by StandardScaler, MinMaxScaler, and RobustScaler.

Below is the execution flow of leak-free Out-of-Fold Target Encoding:

Animated flow chart showing K-fold partition, category mean calculation on training folds, Bayesian shrinkage formula, and leak-free encoding.

Let us examine real Python code demonstrating leak-free Out-of-Fold Target Encoding and StandardScaler:

import numpy as np
from sklearn.model_selection import KFold
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import Ridge
from sklearn.metrics import mean_squared_error

# 1. Generate Synthetic Data with High-Cardinality Category
rng = np.random.default_rng(42)
n_samples = 600

# Continuous Feature (e.g. Square Footage: 500 to 5000)
sqft = rng.uniform(500, 5000, size=n_samples)

# High-Cardinality Category (e.g. 30 Neighborhoods)
neighborhoods = np.array([f"Neigh_{i % 30}" for i in range(n_samples)])

# Target Price: Base + Neighborhood Effect + SqFt Effect + Noise
neighborhood_effect = {f"Neigh_{i}": i * 10000 for i in range(30)}
target = np.array([50000 + neighborhood_effect[n] + 150 * s + rng.normal(0, 5000) for n, s in zip(neighborhoods, sqft)])

# 2. Out-of-Fold Smoothed Target Encoding Function
def oof_target_encode(cats, y, n_splits=5, smoothing=10.0):
    encoded = np.zeros(len(cats))
    kf = KFold(n_splits=n_splits, shuffle=True, random_state=42)
    for tr, va in kf.split(cats, y):
        cat_tr, y_tr = cats[tr], y[tr]
        glob_mean = np.mean(y_tr)
        u_cats, counts = np.unique(cat_tr, return_counts=True)
        sums = {c: np.sum(y_tr[cat_tr == c]) for c in u_cats}
        counts_dict = dict(zip(u_cats, counts))
        for idx in va:
            c = cats[idx]
            if c in counts_dict:
                n_c = counts_dict[c]
                encoded[idx] = (sums[c] + smoothing * glob_mean) / (n_c + smoothing)
            else:
                encoded[idx] = glob_mean
    return encoded

# 3. Apply Preprocessing
encoded_neigh = oof_target_encode(neighborhoods, target)
X = np.column_stack([sqft, encoded_neigh])

# Standardize features for Ridge Regression
scaler = StandardScaler()
X_scaled = scaler.fit_transform(X)

# 4. Fit Model
model = Ridge(alpha=1.0).fit(X_scaled, target)
preds = model.predict(X_scaled)
print("=== Preprocessing Pipeline Verification ===")
print(f"Standardized Feature Means: {np.round(np.mean(X_scaled, axis=0), 4)}")
print(f"Standardized Feature Stds:  {np.round(np.std(X_scaled, axis=0), 4)}")
print(f"Model Root Mean Squared Error: ${np.sqrt(mean_squared_error(target, preds)):.2f}")

Implications: security, privacy, performance, scalability, and cost

DimensionCharacteristicPractical Implication
Target Leakage VulnerabilityIn-sample target statistics leak labels.Never compute target encodings globally before splitting; strict out-of-fold cross-validation is mandatory.
Privacy Inversion RiskRare categories expose individual labels.If a category has n_c = 1, target encoding directly exposes the individual’s target value. Apply Bayesian smoothing m >= 10.
Memory Footprint ScalingHigh-cardinality OHE memory explosion.One-hot encoding 100,000 categories creates billions of matrix entries; use Target Encoding or Feature Hashing.
Streaming Production InferencePreprocessing parameter persistence.The production serving engine must load the exact mean_, scale_, and category lookup tables saved during training.

Alternatives: free, open source, and commercial

Scaler / EncoderMechanismBest Used For
StandardScalerZ-score normalization (x - mu) / sigmaGeneral Gaussian continuous features.
RobustScalerMedian and IQR scalingFinancial/sensor data contaminated with extreme outliers.
TargetEncoder (scikit-learn 1.3+)Out-of-fold smoothed category meanHigh-cardinality categorical features in tabular models.
HashingVectorizer / FeatureHasherMurmurHash3 hashing trickHigh-cardinality text/categorical streaming data.

Preprocessing TechniqueOutlier ResiliencePreserves SparsityOutput BoundPrimary Use Case
StandardScalerLow (Outliers distort mu, sigma)NoUnboundedGaussian linear/SVM models
MinMaxScalerVery Low (Outliers squish range)NoStrict [0, 1]Neural networks / Images
RobustScalerUltra-High (Median & IQR)NoUnboundedOutlier-heavy tabular data
MaxAbsScalerLowYes (Zeros untouched)[-1, +1]Sparse text matrices (TF-IDF)
Target EncodingHigh (With Bayesian smoothing)N/ATarget scaleHigh-cardinality nominal categories

When to use it β€” and when not to

When to USE Rigorous Scaling and Encoding:

When NOT to use Heavy Scaling:


Knowledge check

  1. Condition Number: Disparate feature scales create elongated elliptical loss contours that slow gradient descent.
  2. RobustScaler: Uses Median and IQR to scale data without distortion from extreme outliers.
  3. Target Encoding Leakage: Target encodings must be generated Out-of-Fold across cross-validation splits.
  4. Tree Invariance: Decision trees are completely invariant to monotonic feature scaling.

Hands-on exercise

In this hands-on exercise, you will implement StandardScaler and RobustScaler from scratch and compare their behavior on data with extreme outliers.

import numpy as np

# Step 1: Implement StandardScaler and RobustScaler
class StandardScalerScratch:
    def fit_transform(self, X):
        self.mean_ = np.mean(X, axis=0)
        self.scale_ = np.std(X, axis=0)
        return (X - self.mean_) / self.scale_

class RobustScalerScratch:
    def fit_transform(self, X):
        self.median_ = np.median(X, axis=0)
        q25 = np.percentile(X, 25, axis=0)
        q75 = np.percentile(X, 75, axis=0)
        self.iqr_ = q75 - q25
        return (X - self.median_) / self.iqr_

# Step 2: Create Data with 1 Extreme Outlier
# 5 Inliers clustered around 10-20, 1 Outlier at 10,000
X = np.array([[10.0], [12.0], [14.0], [16.0], [18.0], [10000.0]])

std_scaled = StandardScalerScratch().fit_transform(X)
rob_scaled = RobustScalerScratch().fit_transform(X)

print("=== Scaling Outlier Resilience Comparison ===")
print("Raw Inlier Values (first 3):", X[:3].flatten())
print("StandardScaler Inliers (Squashed to near zero!):", np.round(std_scaled[:3].flatten(), 4))
print("RobustScaler Inliers (Rich, preserved spread!):   ", np.round(rob_scaled[:3].flatten(), 4))

Expected output

=== Scaling Outlier Resilience Comparison ===
Raw Inlier Values (first 3): [10. 12. 14.]
StandardScaler Inliers (Squashed to near zero!): [-0.4199 -0.4194 -0.4189]
RobustScaler Inliers (Rich, preserved spread!):    [-1. -0.5  0. ]

Validate your work

  1. Confirm that StandardScaler squashes inliers into a tiny range [-0.4199, -0.4189] due to the outlier inflating variance.
  2. Confirm that RobustScaler preserves rich inlier variation [-1.0, -0.5, 0.0].
  3. Verify that np.median(rob_scaled, axis=0) == 0.0.

Troubleshooting

Common mistakes

  1. Fitting Scalers on the Full Dataset: Leaks validation statistics into training folds. Always call .fit() strictly on training data.
  2. One-Hot Encoding High-Cardinality IDs: Generates massive sparse matrices that exhaust memory.

Practice assignment

  1. Implement Min-Max Scaler with Custom Ranges: Write MinMaxScalerScratch(feature_range=(-1, 1)) implementing fit() and transform() to scale features into arbitrary bounds [a, b].
  2. Implement Weight of Evidence (WoE) Encoding: Write a categorical encoder computing WoE_c = ln( P(Y=1|c) / P(Y=0|c) ) for credit underwriting applications.

Extension challenge

Build an Automated Data Hygiene & Preprocessing Engine:

  1. Ingest an arbitrary dirty Pandas DataFrame with continuous, discrete, nominal, ordinal, and missing columns.
  2. Automatically profile each column: compute skewness, detect outliers via IQR, calculate cardinality, and select the optimal scaler (RobustScaler for skewed, StandardScaler for Gaussian) and encoder (OHE for k <= 5, Out-of-Fold Target Encoding for k > 5).
  3. Output a production-ready scikit-learn ColumnTransformer object.

Quiz

Q1. Why does training a Linear Regression or Support Vector Machine on unscaled features (e.g. Feature 1 in [0, 1] and Feature 2 in [1000, 1000000]) degrade optimization?

  1. The loss function Hessian matrix has a severe condition number kappa = lambda_max / lambda_min, creating elongated elliptical contours that cause gradient descent to oscillate wildly; L2 regularization also penalizes weights unfairly
  2. Unscaled features crash the Python interpreter
  3. Linear models cannot multiply numbers greater than 100
  4. Feature scale only affects decision trees
Show answer

Answer: A. The loss function Hessian matrix has a severe condition number kappa = lambda_max / lambda_min, creating elongated elliptical contours that cause gradient descent to oscillate wildly; L2 regularization also penalizes weights unfairly

Disparate feature scales create steep elliptical loss surfaces where gradient steps bounce back and forth perpendicular to the shortest path, slowing convergence by orders of magnitude.

Q2. What is the primary advantage of RobustScaler over StandardScaler when preprocessing real-world tabular data?

  1. RobustScaler centers data using the Median and scales using the Interquartile Range (IQR = Q75 - Q25), preventing extreme outliers from distorting the calculated mean and variance
  2. RobustScaler converts continuous features to integers
  3. RobustScaler uses GPU acceleration
  4. RobustScaler does not require calculating statistics
Show answer

Answer: A. RobustScaler centers data using the Median and scales using the Interquartile Range (IQR = Q75 - Q25), preventing extreme outliers from distorting the calculated mean and variance

StandardScaler computes the sample mean and standard deviation, which are heavily distorted by extreme outliers. RobustScaler uses rank-based median and IQR, remaining robust against extreme anomalies.

Q3. When is One-Hot Encoding (OHE) appropriate, and when does it fail?

  1. OHE is ideal for low-cardinality nominal categories (e.g. Blood Type, Color with <= 10 levels); it fails on high-cardinality categories (e.g. ZipCode with 40,000 levels) due to the curse of dimensionality and memory exhaustion
  2. OHE is only for text classification
  3. OHE should never be used on nominal features
  4. OHE is mandatory for all integer columns
Show answer

Answer: A. OHE is ideal for low-cardinality nominal categories (e.g. Blood Type, Color with <= 10 levels); it fails on high-cardinality categories (e.g. ZipCode with 40,000 levels) due to the curse of dimensionality and memory exhaustion

One-hot encoding creates a binary column per category. When cardinality k is high, it creates massive sparse matrices, slows tree splitting, and overfits small subsets.

Q4. What is the mathematical formulation of Smoothed Target Encoding with Bayesian shrinkage (Micci-Barreca, 2001)?

  1. S_c = (n_c * mean_c + m * global_mean) / (n_c + m), where m is the smoothing weight pulling rare categories (small n_c) towards the global dataset prior
  2. S_c = n_c * mean_c * global_mean
  3. S_c = count(c) / total_rows
  4. S_c = log(n_c + 1)
Show answer

Answer: A. S_c = (n_c * mean_c + m * global_mean) / (n_c + m), where m is the smoothing weight pulling rare categories (small n_c) towards the global dataset prior

Smoothed target encoding computes the weighted average between a category empirical mean and the global mean, preventing rare categories with 1 sample from generating extreme overfitted target signals.

Q5. Why MUST Target Encoding be computed strictly Out-of-Fold (OOF) across cross-validation splits?

  1. Calculating target means on the full training dataset causes severe target leakage: the model memorizes the exact label of single-sample categories rather than learning generalizable category relationships
  2. OOF target encoding runs faster than in-sample encoding
  3. Out-of-fold encoding removes categorical columns
  4. OOF encoding is only required for deep neural networks
Show answer

Answer: A. Calculating target means on the full training dataset causes severe target leakage: the model memorizes the exact label of single-sample categories rather than learning generalizable category relationships

In-sample target encoding leaks the target label into the feature value. If Category X appears once with y=1, its target encoded feature is exactly 1.0, giving the model a trivial leaky cheat code.

Q6. Which family of machine learning algorithms is completely INVARIANT to monotonic feature scaling?

  1. Tree-based models (Decision Trees, Random Forests, XGBoost, LightGBM)
  2. Linear and Logistic Regression
  3. Support Vector Machines
  4. k-Nearest Neighbors
Show answer

Answer: A. Tree-based models (Decision Trees, Random Forests, XGBoost, LightGBM)

Decision trees evaluate split thresholds based strictly on ordinal rank ordering (x_i <= theta). Multiplying a feature by 1,000,000 or taking its logarithm leaves the tree split sequence completely unchanged.

Q7. When is Ordinal Encoding (mapping categories to 0, 1, 2, 3...) strictly valid?

  1. Only when the categorical feature has a true, natural mathematical ordering (e.g. Education Level: High School = 1, Bachelors = 2, Masters = 3, PhD = 4)
  2. On all categorical columns regardless of meaning
  3. Only for telephone numbers
  4. Only when the target is continuous
Show answer

Answer: A. Only when the categorical feature has a true, natural mathematical ordering (e.g. Education Level: High School = 1, Bachelors = 2, Masters = 3, PhD = 4)

Ordinal encoding imposes an artificial numerical distance (e.g. PhD is 4x High School). If applied to nominal categories like Country (USA=1, France=2, Japan=3), linear models and distance metrics will learn nonsensical linear relations.

Q8. What is the purpose of the Yeo-Johnson Power Transformation?

  1. To transform skewed, heavy-tailed continuous distributions into approximately symmetric Gaussian normal distributions, supporting both positive and negative values
  2. To convert text strings into numbers
  3. To remove missing values
  4. To encode categorical variables
Show answer

Answer: A. To transform skewed, heavy-tailed continuous distributions into approximately symmetric Gaussian normal distributions, supporting both positive and negative values

The Yeo-Johnson transformation stabilizes variance and removes skewness for features with arbitrary real values (unlike Box-Cox which requires strictly positive x > 0).

Glossary

Feature Scaling
The process of normalizing or standardizing the range of independent variables to ensure uniform contribution across distance metrics and optimization routines.
StandardScaler (Z-Score)
A transformation z = (x - mu) / sigma that centers data to zero mean and scales to unit variance.
MinMaxScaler
A linear transformation scaling features to a fixed closed interval, typically [0, 1].
RobustScaler
A scaling transformation using the median and Interquartile Range (IQR) that is robust against extreme numerical outliers.
One-Hot Encoding (OHE)
A representation where categorical variables are converted into binary indicator vectors with mutually exclusive active bits.
Target Encoding
A categorical encoding method that replaces each category with the average target value of that category, regularized by global Bayesian smoothing.
Out-of-Fold (OOF) Target Encoding
Computing target encodings strictly on complementary cross-validation folds to eliminate target leakage.
Bayesian Shrinkage
A regularization technique that pulls small-sample category estimates toward the global prior distribution mean.
Condition Number (kappa)
The ratio of the largest to smallest eigenvalue of the Hessian matrix, dictating the convergence speed of gradient descent.
Yeo-Johnson Transformation
A parametric power transformation that normalizes continuous features with positive, zero, or negative values.

Sources and further reading


Kept in this browser, no account needed. Your progress page turns the whole record into one link you can bookmark or open on another device.