데이터 스케일링과 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

2D 특성 플롯

Python으로 배우는 금융 분야 Machine Learning

KNN 예측 미지점

Python으로 배우는 금융 분야 Machine Learning

가장 가까운 2개 점을 이용한 KNN 예측

Python으로 배우는 금융 분야 Machine Learning

민코프스키 거리

Python으로 배우는 금융 분야 Machine Learning

크고 작은 특성

Python으로 배우는 금융 분야 Machine Learning

스케일링 방법

스케일링 방법:

  • 최소-최대
  • 표준화
  • 중앙값-MAD
  • 임의 함수 매핑 (예: sigmoid, tanh)
Python으로 배우는 금융 분야 Machine Learning

스케일링 전후 2D 특성 플롯

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...