標準化
正規化は、列を2つの基準点の間にスケーリングするのに便利ですが、どちらか一方でも外れ値の影響を強く受けていると、スケーリング後の2つの列を比較するのは難しくなります。これに対する一般的な解決策が標準化です。標準化では厳密な上下限を設ける代わりに、データを平均値の周りに中心化し、各データ点が平均から何標準偏差離れているかを計算します。
この演習はコースの一部です
Python で学ぶ Machine Learning のための特徴量エンジニアリング
演習の手順
sklearnのpreprocessingモジュールからStandardScalerをインポートします。StandardScaler()をSS_scalerとしてインスタンス化します。so_numeric_dfのAge列に対してStandardScalerを fit します。- 直前に fit したスケーラーで同じ列を transform します。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
# Import StandardScaler
____
# Instantiate StandardScaler
SS_scaler = ____()
# Fit SS_scaler to the data
____.____(so_numeric_df[['Age']])
# Transform the data using the fitted scaler
so_numeric_df['Age_SS'] = ____.____(so_numeric_df[['Age']])
# Compare the origional and transformed column
print(so_numeric_df[['Age_SS', 'Age']].head())