開始使用免費開始

檢查相關性

在我們擬合第一個機器學習模型之前,先看看特徵與目標之間的相關性。理想情況下,我們希望特徵與目標之間的相關性係數接近 1 或 -1。檢視相關性可以幫助你調整特徵來最大化相關性(例如,調整 talib 函式中的 timeperiod 參數)。也能幫助我們移除與目標沒有相關性的特徵。

若要輕鬆繪製相關矩陣,你可以使用 seabornheatmap() 函式。它將相關矩陣作為第一個引數,並且還有許多其他選項。看看 annot 選項——這能幫助我們開啟標註。

本練習屬於課程

Python 金融 Machine Learning

檢視課程

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Plot heatmap of correlation matrix
sns.heatmap(____, annot= ____, annot_kws = {"size": 14})
plt.yticks(rotation=0, size = 14); plt.xticks(rotation=90, size = 14)  # fix ticklabel directions and size
plt.tight_layout()  # fits plot area to the plot, "tightly"
plt.____  # show the plot
編輯並執行程式碼