LoginSignup
0
1

More than 1 year has passed since last update.

機械学習勉強記録 データの標準化

Posted at

1 標準化

標準化を行うことにより、単位や平均値などが異なるデータ同士を単純に比較できるようになります。
標準化した後の数値が高いほど、偏差値が高いということで、
異なる基準のデータ同士を比較することができるようになります。
(例)国語のテストと数学のテストの結果を比べて、自分がどっちの教科が得意なのかを知ることができる。

以下の式で、標準化できます。

\hat{x}=\frac{x-\bar{x}}{\sigma}

$\sigma$ : 標準偏差
$\bar{x}$ : 平均

1.1 Scikit-learnを用いて実装

# StandardScalerをインポート
from sklearn.preprocessing import StandardScaler
# モデルをstd_scalerに代入
std_scaler = StandardScaler()
# x_trainに適用 平均と標準偏差を算出
std_scaler.fit(x_train)

# データセットの値を変換する
x_train_std = std_scaler.transform(x_train)
x_test_std = std_scaler.transform(x_test)
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1