scikit-learn का KFold()
आपने अभी एक सहकर्मी का कोड चलाया है जो एक random forest मॉडल बनाता है और out-of-sample accuracy निकालता है. आपने देखा कि आपके सहकर्मी के कोड में random state सेट नहीं था, और जिन errors को आपने पाया, वे आपके सहकर्मी द्वारा रिपोर्ट की गई errors से बिल्कुल अलग थे.
यह बेहतर आकलन करने के लिए कि यह random forest मॉडल नए डेटा पर कितना सटीक होगा, आपने KFold cross-validation के लिए उपयोग करने हेतु कुछ indices जेनरेट करने का निर्णय लिया है.
यह अभ्यास पाठ्यक्रम का हिस्सा है
Python में Model Validation
अभ्यास निर्देश
- डेटा को पाँच splits, shuffling, और random state 1111 के साथ split करने के लिए
KFold()कॉल करें. XपरKFoldकेsplit()मेथड का उपयोग करें.- train और validation indices की सूचियों में indices की संख्या प्रिंट करें.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
from sklearn.model_selection import KFold
# Use KFold
kf = KFold(____, ____, ____)
# Create splits
splits = kf.____(____)
# Print the number of indices
for train_index, val_index in splits:
print("Number of training indices: %s" % len(____))
print("Number of validation indices: %s" % len(____))