0Pricing
Data Science Academy · 课时

缩放和标准化数值

让各个特征处于公平的比较基础上

缩放和标准化数值 是 CoddyKit 上的免费 Data Science Academy 课时。 这是第 3 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Data Science Academy 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Data Science Academy 课程共包含 4 节课。

本课时的部分内容尚未翻译,以英文显示。

Why Scale Numbers

Age ranges 0 to 90 while income ranges to millions. Without scaling, the bigger numbers dominate and quietly drown out the smaller ones. ⚖️

Distance-Based Models Care

Models that measure distance, like k-NN and k-means, are very sensitive to scale. Unscaled features hand all the power to the largest column.

Standardization

Standardization rescales a column to mean 0 and standard deviation 1. Values become how many standard deviations they sit from the average.

StandardScaler

The StandardScaler applies standardization for you. Fit it on your data, then transform any column into z-scores.

from sklearn.preprocessing import StandardScaler
z = StandardScaler().fit_transform(df[['age']])

Normalization

Normalization squeezes values into a fixed range, usually 0 to 1. The smallest value maps to 0 and the largest to 1.

MinMaxScaler

Reach for MinMaxScaler to rescale into 0 to 1. It keeps the shape of your data while bounding the range.

from sklearn.preprocessing import MinMaxScaler
m = MinMaxScaler().fit_transform(df[['age']])

Standardize or Normalize

Use standardization when data is roughly bell-shaped or has outliers. Pick normalization when you need a strict 0 to 1 bound.

Outliers Hurt MinMax

A single huge value can squash everything else near zero under MinMax. When outliers dominate, RobustScaler resists them better.

from sklearn.preprocessing import RobustScaler
r = RobustScaler().fit_transform(df[['income']])

Fit on Train Only

Fit the scaler on training data alone, then transform the test set. Fitting on everything leaks test information into your model.

scaler.fit(X_train)
X_test_scaled = scaler.transform(X_test)

Scale Inside a Pipeline

Bundle the scaler with your model in a Pipeline. It then fits only on the training fold during cross-validation, blocking leakage for free.

from sklearn.pipeline import make_pipeline
pipe = make_pipeline(StandardScaler(), model)

Trees Do Not Need It

Tree-based models like random forests split on thresholds, so scaling rarely changes results. Save scaling for distance and linear methods.

Quick Check

You need every feature rescaled to a strict 0-to-1 range. Which scaler fits?

Recap: Scaling

You put features on a fair footing: StandardScaler for z-scores, MinMaxScaler for 0 to 1, RobustScaler for outliers. Always fit on train only. 🎉

常见问题解答

「缩放和标准化数值」课时是免费的吗?

是的 — 「缩放和标准化数值」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Data Science Academy 课程的其余内容,请升级到 CoddyKit PRO。 Data Science Academy 课程共包含 4 节课。

「缩放和标准化数值」这节课中我会学到什么?

让各个特征处于公平的比较基础上 你通过在浏览器中直接运行的动手代码来练习 Data Science Academy,全天候 AI 导师会在你学习这节课的过程中回答你的问题。

学习 Data Science Academy 需要有经验吗?

无需任何先前经验。CoddyKit 上的 Data Science Academy 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 3 节课,共 4 节。

「缩放和标准化数值」课时需要多长时间?

大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。

我能在这节 Data Science Academy 课中编写并运行代码吗?

能。每节 Data Science Academy 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。

此课程中的所有课时

  1. 将数字区间划分为类别
  2. 编码分类列
  3. 缩放和标准化数值
  4. 从日期和文本构建特征
← 返回 Data Science Academy