開始使用免費開始

檢視新特徵的相關性

現在我們已經有成交量與日期時間特徵,想檢查新特徵(存放在 new_features 串列)與目標(5d_close_future_pct)之間的相關性,看看它們關聯程度有多強。回想一下,pandas 對 DataFrame 提供內建的 .corr() 方法,而 seaborn 有好用的 heatmap() 函式可以視覺化相關性。

本練習屬於課程

Python 金融 Machine Learning

檢視課程

練習說明

  • 擴充 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()
編輯並執行程式碼