हमारे नतीजों का मूल्यांकन करें
जब हमारे पास linear fit और predictions हों, तो हमें देखना होता है कि वे कितने अच्छे हैं ताकि हम तय कर सकें कि हमारा मॉडल काम का है या नहीं. आदर्श रूप से, हम किसी भी तरह की ट्रेडिंग स्ट्रैटेजी को back-test करना चाहेंगे. हालाँकि, यह जटिल और आमतौर पर समय लेने वाली प्रक्रिया है.
मॉडल के प्रदर्शन को जल्दी समझने का एक तरीका है regression evaluation metrics जैसे R\(^2\) देखना, और predictions को targets के वास्तविक मानों के मुकाबले plot करना. परफेक्ट predictions ऐसे plot में एक सीधी, तिरछी रेखा बनाएँगी, जिससे अलग-अलग price change क्षेत्रों में हमारे predictions के प्रदर्शन को आँखों से आँकना आसान हो जाएगा. हम matplotlib के .scatter() फंक्शन का उपयोग करके predictions और वास्तविक मानों के scatter plots बना सकते हैं.
यह अभ्यास पाठ्यक्रम का हिस्सा है
Python में Finance के लिए Machine Learning
अभ्यास निर्देश
test_predictionsबनामtest_targetsको एक scatterplot में दिखाएँ, और बिंदुओं के लिए 20% opacity रखें (opacity सेट करने के लिएalphaपैरामीटर का उपयोग करें).- परफेक्ट prediction लाइन को
np.arange()और x-axis के न्यूनतम व अधिकतम मान (xmin,xmax) से plot करें. - plot पर legend को
plt.legend()से दिखाएँ.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# Scatter the predictions vs the targets with 20% opacity
plt.scatter(train_predictions, train_targets, alpha=0.2, color='b', label='train')
plt.scatter(____, ____, ____, color='r', label='test')
# Plot the perfect prediction line
xmin, xmax = plt.xlim()
plt.plot(np.arange(xmin, xmax, 0.01), np.arange(____, ____, 0.01), c='k')
# Set the axis labels and show the plot
plt.xlabel('predictions')
plt.ylabel('actual')
____ # show the legend
plt.show()