データのスケーリングとKNN回帰

Python による金融のための Machine Learning

Nathan George

Data Science Professor

特徴量の重要度

Python による金融のための Machine Learning

特徴量選択:曜日の除去

print(feature_names)
['10d_close_pct',
 '14-day SMA',
 '14-day RSI',
 '200-day SMA',
 '200-day RSI',
 'Adj_Volume_1d_change',
 'Adj_Volume_1d_change_SMA',
 'weekday_1',
 'weekday_2',
 'weekday_3',
 'weekday_4']
print(feature_names[:-4])
['10d_close_pct',
 '14-day SMA',
 '14-day RSI',
 '200-day SMA',
 '200-day RSI',
 'Adj_Volume_1d_change',
 'Adj_Volume_1d_change_SMA']
Python による金融のための Machine Learning

曜日の除去

train_features = train_features.iloc[:, :-4]
test_features = test_features.iloc[:, :-4]
Python による金融のための Machine Learning

2次元特徴量プロット

Python による金融のための Machine Learning

KNN予測(未知点)

Python による金融のための Machine Learning

KNN予測(最近傍2点)

Python による金融のための Machine Learning

ミンコフスキー距離

Python による金融のための Machine Learning

大きい特徴量と小さい特徴量

Python による金融のための Machine Learning

スケーリングの方法

スケーリングの方法:

  • min-max
  • 標準化
  • メディアン-MAD
  • 任意の関数へのマッピング(例:sigmoid、tanh)
Python による金融のための Machine Learning

スケーリング前後の2次元特徴量プロット

Python による金融のための Machine Learning

sklearnのscale

from sklearn.preprocessing import scale

sc = scale()
scaled_train_features = sc.fit_transform(train_features)
scaled_test_features = sc.transform(test_features)
Python による金融のための Machine Learning

標準化の前後

Python による金融のための Machine Learning

サブプロットの作成

# create figure and list containing axes
f, ax = plt.subplots(nrows=2, ncols=1)

# plot histograms of before and after scaling train_features.iloc[:, 2].hist(ax=ax[0]) ax[1].hist(scaled_train_features[:, 2]) plt.show()
Python による金融のための Machine Learning

データをスケーリングしてKNNを使おう!

Python による金融のための Machine Learning

Preparing Video For Download...