Best results का उपयोग
हमारे grid search के नतीजों का विश्लेषण दिलचस्प है, लेकिन हमारा अंतिम लक्ष्य व्यावहारिक है: हम अपने test set पर अपने estimator ऑब्जेक्ट से predictions करना चाहते हैं.
हम इस ऑब्जेक्ट तक अपने grid search ऑब्जेक्ट की best_estimator_ property के ज़रिए पहुँच सकते हैं.
आइए best_estimator_ property के अंदर देखें, predictions बनाएँ, और evaluation स्कोर जनरेट करें. पहले हम डिफ़ॉल्ट predict का उपयोग करेंगे (जो class predictions देता है), लेकिन उसके बाद roc-auc स्कोर निकालने के लिए हमें predict की बजाय predict_proba का उपयोग करना होगा, क्योंकि roc-auc की गणना के लिए probability scores चाहिए होते हैं. Positive class की probabilities पाने के लिए हम slice [:,1] का उपयोग करते हैं.
आपके पास उपयोग के लिए X_test और y_test डेटासेट मौजूद हैं और पिछले अभ्यासों से grid_rf_class ऑब्जेक्ट भी उपलब्ध है.
यह अभ्यास पाठ्यक्रम का हिस्सा है
Python में Hyperparameter Tuning
अभ्यास निर्देश
best_estimator_property का टाइप जाँचें.- Test set पर predictions बनाने के लिए
best_estimator_property का उपयोग करें. - अपनी predictions से confusion matrix और ROC_AUC स्कोर जनरेट करें.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# See what type of object the best_estimator_ property is
print(____(____.____))
# Create an array of predictions directly using the best_estimator_ property
predictions = grid_rf_class.____._____(X_test)
# Take a look to confirm it worked, this should be an array of 1's and 0's
print(predictions[0:5])
# Now create a confusion matrix
print("Confusion Matrix \n", confusion_matrix(y_test, ______))
# Get the ROC-AUC score
predictions_proba = grid_rf_class.best_estimator_.predict_proba(X_test)[:,1]
print("ROC-AUC Score \n", roc_auc_score(y_test, _____))