ตรวจสอบความสัมพันธ์ของฟีเจอร์ใหม่
เมื่อได้ฟีเจอร์ด้านปริมาณการซื้อขายและวันที่แล้ว ขั้นตอนต่อไปคือตรวจสอบความสัมพันธ์ระหว่างฟีเจอร์ใหม่ (ที่เก็บไว้ใน list new_features) กับ target (5d_close_future_pct) เพื่อดูว่ามีความสัมพันธ์กันมากน้อยเพียงใด โดย pandas มีเมธอด .corr() ในตัวสำหรับ DataFrame และ seaborn มีฟังก์ชัน heatmap() ที่ช่วยแสดงความสัมพันธ์เหล่านี้ได้อย่างชัดเจน
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
Machine Learning สำหรับการเงินด้วย Python
คำแนะนำการฝึกหัด
- ขยาย
new_featuresให้ครอบคลุมชื่อคอลัมน์วันในสัปดาห์ เช่นweekday_1โดยเชื่อมหมายเลขวันกับสตริง'weekday_' - ใช้
heatmapของ Seaborn เพื่อพล็อตความสัมพันธ์ของnew_featuresและ target5d_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()