特徵工程

Python 金融 Machine Learning

Nathan George

Data Science Professor

非線性特徵相關

Python 金融 Machine Learning

線性模型的一個問題

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

不需手動建立交互特徵的模型:

以決策樹為基礎的模型

  • 隨機森林
  • 梯度提升

其他

  • 類神經網路
Python 金融 Machine Learning

成交量與價格變動

Python 金融 Machine Learning

價格與成交量

Python 金融 Machine Learning

成交量特徵

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)
Python 金融 Machine Learning

日期時間特徵工程

日期時間圖,箭頭指向星期、月份、年份

Python 金融 Machine Learning

擷取星期幾

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)
Python 金融 Machine Learning

虛擬變數

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
Python 金融 Machine Learning

新特徵的相關性圖

Python 金融 Machine Learning

動手做些特徵吧!

Python 金融 Machine Learning

Preparing Video For Download...