Engenharia de features

Machine Learning para Finanças em Python

Nathan George

Data Science Professor

correlação não linear entre feature e alvo

Machine Learning para Finanças em Python

Um problema dos modelos lineares

# add non-linear interaction term for a linear model
SMAxRSI = amd_df['14-day SMA'] * amd_df['14-day RSI']

Alguns modelos que não exigem criar interações manualmente:

Modelos baseados em árvores de decisão

  • Random forests
  • Gradient boosting

Outros

  • redes neurais
Machine Learning para Finanças em Python

volume vs. variação de preço

Machine Learning para Finanças em Python

preço e volume

Machine Learning para Finanças em Python

Features de volume

amd_df['Adj_Volume_1d_change'] = amd_df['Adj_Volume'].pct_change()

one_day_change = amd_df['Adj_Volume_1d_change'].values amd_df['Adj_Volume_1d_change_SMA'] = talib.SMA(one_day_change, timeperiod=10)
Machine Learning para Finanças em Python

Engenharia de features de datetime

gráfico de datetime com setas para dia da semana, mês, ano

Machine Learning para Finanças em Python

Extraindo o dia da semana

print(amd_df.index.dayofweek)
Int64Index([2, 3, 4, 0, 1, 2, 3, 4, 0, 1,
            ...
            1, 2, 3, 4, 0, 1, 2, 3, 4, 0],
           dtype='int64', name='Date', length=4807)
Machine Learning para Finanças em Python

Dummies

days_of_week = pd.get_dummies(amd_df.index.dayofweek,
                                prefix='weekday',
                                drop_first=True)

print(days_of_week.head())
            weekday_1  weekday_2  weekday_3  weekday_4
Date
2018-04-10          1          0          0          0
2018-04-11          0          1          0          0
2018-04-12          0          0          1          0
2018-04-13          0          0          0          1
2018-04-16          0          0          0          0
Machine Learning para Finanças em Python

gráfico de correlação das novas features

Machine Learning para Finanças em Python

Crie algumas features!

Machine Learning para Finanças em Python

Preparing Video For Download...