检查新特征的相关性
现在我们已经有了成交量和日期时间特征,接下来要检查新特征(保存在 new_features 列表中)与目标(5d_close_future_pct)之间的相关性,看看它们的关联程度。回顾一下,pandas 的 DataFrame 提供了内置的 .corr() 方法,而 seaborn 提供了漂亮的 heatmap() 函数来展示相关性。
本练习是课程的一部分
Python 金融机器学习
练习说明
- 扩展
new_features变量以包含工作日的列名(如weekday_1),方法是将工作日编号与字符串'weekday_'拼接。 - 使用 Seaborn 的
heatmap绘制new_features与目标5d_close_future_pct的相关性图。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Add the weekday labels to the new_features list
new_features.extend([____ + ____ for i in range(1, 5)])
# Plot the correlations between the new features and the targets
sns.____(lng_df[____ + ['5d_close_future_pct']].corr(), annot=True)
plt.yticks(rotation=0) # ensure y-axis ticklabels are horizontal
plt.xticks(rotation=90) # ensure x-axis ticklabels are vertical
plt.tight_layout()
plt.show()