EDA and Feature Engineeringpandas 3.0 · scikit-learn 1.9 · seaborn 0.13 · Python 3.12+
Dashboard
0%
1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
72 small wins to finish your pathNext lesson →

Which algorithms need scaling

A model needs feature scaling when it combines columns into a single number, through a distance or a gradient; a model that splits one column at a time does not.

Last updated: 12 Oct, 2026 · pandas 3.0 · scikit-learn 1.9 · scipy 1.18

Why features are scaled showed one column taking over a distance. The next question is which models that reaches. The answer is a short list, and the video treats it as an interview question worth memorising.

Which algorithms need scaling · from the Live Feature Engineering sessions · 14:22 to 19:12

The two reasons a model cares about scale

  • Gradient descent. Linear regression, logistic regression and neural networks search for the lowest point of a cost surface by stepping downhill. Columns of unequal width turn that surface into a long narrow valley, so the walk zig zags and needs more rounds.
  • Euclidean distance. k nearest neighbours, k means and hierarchical clustering rank rows by distance, and the widest column supplies most of it.
  • Neither applies to a tree. A decision tree asks one question at a time, ram <= 2100, and a question like that gives the same answer whatever units ram is written in. Random forest, AdaBoost and gradient boosting are built from such trees and inherit the same indifference.

Measuring the change on four models

The mobile price dataset makes the point at full size. It holds 2000 phones with 20 features whose ranges run from 0 and 1 up to ram at 256 to 3998, and a target with four price bands. Each model is scored twice on the same five folds: once on the raw columns, once inside a pipeline that standardises first.

python
import pandas as pd

URL = "https://raw.githubusercontent.com/krishnaik06/Feature-Engineering-Live-sessions/master/mobile_dataset.csv"
mobile = pd.read_csv(URL)                 # 2000 phones, 20 features
X = mobile.drop(columns='price_range')    # battery_power 501-1998, ram 256-3998
y = mobile['price_range']                 # four price bands, 500 phones each
python
from sklearn.model_selection import cross_val_score, StratifiedKFold
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler

# the same five folds for every model, so the comparison is fair
cv = StratifiedKFold(n_splits=5, shuffle=True, random_state=0)
python
# make_pipeline fits the scaler on each training fold only, never on the test fold
scaled_model = make_pipeline(StandardScaler(), model)
score = cross_val_score(scaled_model, X, y, cv=cv).mean()

Scoring four models with and without a scaler

ExampleFive fold accuracy on the mobile price dataset, run on scikit-learn 1.9.1
from sklearn.model_selection import cross_val_score, StratifiedKFold
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression
from sklearn.neighbors import KNeighborsClassifier
from sklearn.tree import DecisionTreeClassifier
from sklearn.ensemble import RandomForestClassifier

cv = StratifiedKFold(n_splits=5, shuffle=True, random_state=0)
models = [("Logistic regression", LogisticRegression(max_iter=200)),
          ("KNN", KNeighborsClassifier()),
          ("Decision tree", DecisionTreeClassifier(random_state=0)),
          ("Random forest", RandomForestClassifier(n_estimators=50, random_state=0))]

for name, model in models:
    plain = cross_val_score(model, X, y, cv=cv).mean()
    scaled = cross_val_score(make_pipeline(StandardScaler(), model), X, y, cv=cv).mean()
    print(f"{name:20s} unscaled {plain:.3f}   scaled {scaled:.3f}   change {scaled - plain:+.3f}")

Reading the four changes

  • Logistic regression gains 0.311. This is the gradient descent case. On raw columns the solver never reaches the minimum inside its iteration budget.
  • KNN loses 0.406. This is the distance case, and it moves in the other direction. On this dataset ram is both the widest column and the one that predicts the price band, so letting it dominate happens to help. On a table where the widest column is noise, the same arithmetic hurts instead.
  • The decision tree moves by 0.001 and the forest by 0.002. Scaling a column is a monotonic rewrite, so the ordering of values, and therefore every split a tree can make, is unchanged. The tiny difference is floating point rounding changing which of two equally good splits is picked.
  • The lesson is not that scaling raises accuracy. It is that the first two models give a different answer with and without it, so for them scaling is a decision; for the last two it is wasted work.

Counting the solver's rounds

The logistic regression result has a visible cause. n_iter_ reports how many rounds the solver used, and max_iter is the cap it is allowed.

ExampleThe same solver on the same data, scaled and unscaled
from sklearn.linear_model import LogisticRegression
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler

raw_fit = LogisticRegression(max_iter=200).fit(X, y)
scaled_fit = make_pipeline(StandardScaler(), LogisticRegression(max_iter=200)).fit(X, y)

print("rounds on raw columns   :", raw_fit.n_iter_[0])
print("rounds on scaled columns:", scaled_fit[-1].n_iter_[0])
  • 200 rounds on the raw columns is the cap, not a stopping point. The solver was still moving when it ran out and prints a convergence warning.
  • 23 rounds on the scaled columns is a real stop: the cost stopped improving. The same model, the same data, nine times fewer rounds.

Models that need scaling and models that do not

ModelNeeds scalingWhy
Linear regression, logistic regressionyesgradient descent over a cost surface
Neural networks, including CNN and RNNyesgradient descent, and pixel inputs divided by 255
k nearest neighboursyesranks rows by Euclidean distance
k means, hierarchical clusteringyescluster membership is a distance
Support vector machinesyesthe kernel is a distance or a dot product
Principal component analysisyescomponents follow the largest variance, which units decide
Decision treenosplits one column at a time, on an ordering
Random forest, AdaBoost, gradient boostingnobuilt from such trees
Naive Bayesnofits one distribution per column separately

Where this decision shows up

  • Choosing what goes in a pipeline. A pipeline ending in a forest does not need a scaler step. Adding one costs fitting time on every fold and buys nothing.
  • Comparing models fairly. Scoring KNN on raw columns against a forest on raw columns is not a model comparison, because only one of them was given a fair chance.
  • Reading a convergence warning. A solver that hits max_iter is usually reporting unscaled inputs rather than a hard problem.
Watch out. The video says that scaling usually raises accuracy. The run above shows it raising one model's score and lowering another's. What is reliable is the direction of the effect, not its sign: distance and gradient models change, tree models do not. Measure the change on your own data before keeping it.
Try it yourself
  • Raise max_iter to 5000 on the unscaled logistic regression and score it again. The gap narrows, and the run takes far longer.
  • Add SVC() from sklearn.svm to the model list. It belongs with KNN, not with the trees.
  • Drop ram from X and rerun. KNN's two scores move much closer together, because the widest column is gone.

Little by little, you're building something great.