資料轉換、特徵與目標

Python 金融 Machine Learning

Nathan George

Data Science Professor

建立特徵與目標

features = amd_df[['10d_close_pct', 'Adj_Volume']]

targets = amd_df['10d_future_close_pct']
print(type(features))
pandas.core.series.DataFrame
print(type(targets))
pandas.core.series.Series
Python 金融 Machine Learning

價格與移動平均

Python 金融 Machine Learning

移動平均

移動平均:

  • 取過去 n 天平均
  • 常見 n:14、50、200
Python 金融 Machine Learning

價格與簡單移動平均

Python 金融 Machine Learning

RSI 與價格圖

Python 金融 Machine Learning

RSI 公式

RS 公式

Python 金融 Machine Learning

計算 SMA 與 RSI

import talib

amd_df['ma200'] = talib.SMA(amd_df['Adj_Close'].values, timeperiod=200)
amd_df['rsi200'] = talib.RSI(amd_df['Adj_Close'].values, timeperiod=200)
Python 金融 Machine Learning

最後,整理特徵

feature_names = ['10d_close_pct', 'ma200', 'rsi200']
features = amd_df[feature_names]
targets = amd_df['10d_future_close_pct']

feature_target_df = amd_df[feature_names + '10d_future_close_pct']
Python 金融 Machine Learning

檢查相關性

import seaborn as sns

corr = feature_target_df.corr()
sns.heatmap(corr, annot=True)
Python 金融 Machine Learning

特徵與目標的相關性圖

Python 金融 Machine Learning

一起來建立特徵與目標!

Python 金融 Machine Learning

Preparing Video For Download...