始める無料で始める

新しい特徴量の相関関係を確認する

出来高と日時に関する特徴量を作成したので、次は new_features リストに格納されている新しい特徴量と目的変数(5d_close_future_pct)との相関関係を確認し、どの程度関連しているかを見てみましょう。pandas の DataFrame には組み込みの .corr() メソッドがあり、seaborn の heatmap() 関数を使うと相関関係をわかりやすく可視化できます。

この演習はコースの一部です

Python による金融のための Machine Learning

コースを見る

演習の手順

  • 'weekday_' という文字列に曜日の番号を結合して、weekday_1 のような列名を new_features 変数に追加しましょう。
  • 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()
コードを編集して実行