การสเกลข้อมูลและ KNN Regression

Machine Learning สำหรับการเงินด้วย Python

Nathan George

Data Science Professor

ความสำคัญของฟีเจอร์

Machine Learning สำหรับการเงินด้วย Python

การคัดเลือกฟีเจอร์: ตัดวันในสัปดาห์ออก

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']
Machine Learning สำหรับการเงินด้วย Python

ตัดวันในสัปดาห์ออก

train_features = train_features.iloc[:, :-4]
test_features = test_features.iloc[:, :-4]
Machine Learning สำหรับการเงินด้วย Python

กราฟฟีเจอร์ 2 มิติ

Machine Learning สำหรับการเงินด้วย Python

KNN ทำนายค่าที่ไม่รู้จัก

Machine Learning สำหรับการเงินด้วย Python

KNN ทำนายด้วย 2 จุดใกล้ที่สุด

Machine Learning สำหรับการเงินด้วย Python

สมการระยะทาง Minkowski

Machine Learning สำหรับการเงินด้วย Python

ฟีเจอร์ขนาดใหญ่และเล็ก

Machine Learning สำหรับการเงินด้วย Python

ตัวเลือกการสเกล

ตัวเลือกการสเกล:

  • min-max
  • standardization
  • median-MAD
  • แมปกับฟังก์ชันตามต้องการ (เช่น sigmoid, tanh)
Machine Learning สำหรับการเงินด้วย Python

กราฟฟีเจอร์ 2 มิติก่อนและหลังการสเกล

Machine Learning สำหรับการเงินด้วย Python

scale ของ sklearn

from sklearn.preprocessing import scale

sc = scale()
scaled_train_features = sc.fit_transform(train_features)
scaled_test_features = sc.transform(test_features)
Machine Learning สำหรับการเงินด้วย Python

ก่อนและหลัง Standardization

Machine Learning สำหรับการเงินด้วย Python

การสร้าง Subplot

# 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()
Machine Learning สำหรับการเงินด้วย Python

มาสเกลข้อมูลและใช้ KNN กันเถอะ!

Machine Learning สำหรับการเงินด้วย Python

Preparing Video For Download...