Scalare i dati e KNN Regression

Machine Learning per la finanza in Python

Nathan George

Data Science Professor

importanza delle feature

Machine Learning per la finanza in Python

Selezione feature: rimuovere i giorni della settimana

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 per la finanza in Python

Rimuovere i giorni della settimana

train_features = train_features.iloc[:, :-4]
test_features = test_features.iloc[:, :-4]
Machine Learning per la finanza in Python

grafico 2D delle feature

Machine Learning per la finanza in Python

previsione knn sconosciuta

Machine Learning per la finanza in Python

previsione knn con 2 punti più vicini

Machine Learning per la finanza in Python

distanza di Minkowski

Machine Learning per la finanza in Python

feature grandi e piccole

Machine Learning per la finanza in Python

Opzioni di scaling

Opzioni di scaling:

  • min-max
  • standardizzazione
  • mediana-MAD
  • mappare a funzione arbitraria (es. sigmoid, tanh)
Machine Learning per la finanza in Python

grafici 2D delle feature prima e dopo lo scaling

Machine Learning per la finanza in Python

scale di 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 per la finanza in Python

prima e dopo la standardizzazione

Machine Learning per la finanza in Python

Creare 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 per la finanza in Python

Scala i dati e usa KNN!

Machine Learning per la finanza in Python

Preparing Video For Download...