Correlations
मशीन लर्निंग मॉडल बनाने से पहले correlations देख लेना अच्छा रहता है, क्योंकि इससे हम समझते हैं कि कौन-से फीचर टार्गेट से सबसे मज़बूती से जुड़े हैं. अक्सर Pearson का correlation coefficient इस्तेमाल होता है, जो सिर्फ़ linear relationships पकड़ता है. आम तौर पर यह माना जाता है कि हमारा डेटा normal distribution में है, जिसे हम histograms से "eyeball" कर सकते हैं. बहुत अधिक correlated वैरिएबल्स का Pearson correlation coefficient 1 (positively correlated) या -1 (negatively correlated) के क़रीब होता है. 0 के क़रीब वैल्यू का मतलब है कि दोनों वैरिएबल्स में linear correlation नहीं है.
अगर हम पिछले और भविष्य के price changes के लिए एक ही time period लें, तो हम देख सकते हैं कि stock price mean-reverting है (इधर-उधर उछलता है) या trend-following है (यदि हाल में बढ़ा है तो आगे भी बढ़ता है).
यह अभ्यास पाठ्यक्रम का हिस्सा है
Python में Finance के लिए Machine Learning
अभ्यास निर्देश
lng_df DataFrame और इसके Adj_Close का उपयोग करते हुए:
- pandas की
.shift(-5)से 5-दिन का future price (5d_future_close) बनाएँ. 5d_future_closeऔरAdj_Closeपरpct_change(5)का उपयोग करके future 5-दिन का % price change (5d_close_future_pct) और current 5-दिन का % price change (5d_close_pct) बनाएँ.lng_dfपर.corr()चलाकर इन दोनों 5-दिन के percent price change कॉलम्स के बीच correlations जाँचें.plt.scatter()का उपयोग करके5d_close_pctबनाम5d_close_future_pctका एक scatterplot बनाएँ.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# Create 5-day % changes of Adj_Close for the current day, and 5 days in the future
lng_df['5d_future_close'] = lng_df['Adj_Close'].shift(____)
lng_df['5d_close_future_pct'] = lng_df['5d_future_close'].pct_change(5)
lng_df['5d_close_pct'] = lng_df['Adj_Close'].pct_change(____)
# Calculate the correlation matrix between the 5d close pecentage changes (current and future)
corr = lng_df[['5d_close_pct', '5d_close_future_pct']].____
print(corr)
# Scatter the current 5-day percent change vs the future 5-day percent change
plt.scatter(lng_df['5d_close_pct'], lng_df[____])
plt.show()