数値をスケーリングして正規化する
特徴量を公平に比較できる尺度にそろえる
「数値をスケーリングして正規化する」はCoddyKit上の無料Data Science Academyレッスンです。 これはレッスン3/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応の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. 🎉
よくある質問
「数値をスケーリングして正規化する」レッスンは無料ですか?
はい。「数値をスケーリングして正規化する」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Data Science Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Data Science Academyコースには全4レッスンが含まれています。
「数値をスケーリングして正規化する」で何を学びますか?
特徴量を公平に比較できる尺度にそろえる ブラウザで直接実行するハンズオンコードでData Science Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Data Science Academyを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのData Science Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン3/4です。
「数値をスケーリングして正規化する」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このData Science Academyレッスンでコードを書いて実行できますか?
はい。すべてのData Science Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- 数値をカテゴリに分ける
- カテゴリ列をエンコードする
- 数値をスケーリングして正規化する
- 日付とテキストから特徴量を作る