数据变换、特征与目标

Python 金融机器学习

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 金融机器学习

价格与移动平均

Python 金融机器学习

移动平均

移动平均:

  • 用过去 n 天求均值
  • 常用 n:14、50、200
Python 金融机器学习

价格与 SMA

Python 金融机器学习

RSI 与价格图

Python 金融机器学习

RSI 公式

RS 公式

Python 金融机器学习

计算 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 金融机器学习

最终的特征

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 金融机器学习

检查相关性

import seaborn as sns

corr = feature_target_df.corr()
sns.heatmap(corr, annot=True)
Python 金融机器学习

特征与目标的相关性图

Python 金融机器学习

让我们创建特征与目标!

Python 金融机器学习

Preparing Video For Download...