Python में Hyperparameter Tuning
Alex Scriven
Data Scientist
आइए GridSearchCV के आउटपुट का विश्लेषण करें.
GridSearchCV प्रॉपर्टीज़ के तीन समूह:
cv_results_best_index_, best_params_ & best_score_scorer_, n_splits_ & refit_time_
प्रॉपर्टीज़ को dot notation से एक्सेस करते हैं.
उदाहरण:
grid_search_object.property
जहाँ property वह असली प्रॉपर्टी है जिसे आप प्राप्त करना चाहते हैं
cv_results_ प्रॉपर्टी:
इसे प्रिंट और विश्लेषण करने के लिए DataFrame में पढ़ें:
cv_results_df = pd.DataFrame(grid_rf_class.cv_results_)
print(cv_results_df.shape)
(12, 23)
time कॉलम उस समय को दर्शाते हैं जो मॉडल fit (और score) करने में लगा.
याद है हमने 5-fold cross-validation किया था? यह 5 बार चला और सेकंड में लगे समय का औसत और standard deviation स्टोर किया.

param_ कॉलम उस row पर टेस्ट किए गए parameters रखते हैं, प्रति parameter एक कॉलम.

params कॉलम में सभी parameters की dictionary होती है:
pd.set_option("display.max_colwidth", -1)
print(cv_results_df.loc[:, "params"])

test_score कॉलम में प्रत्येक cross-fold के लिए हमारे test set के स्कोर और कुछ summary statistics होते हैं:

rank कॉलम mean_test_score को best से worst क्रम में रखता है:

हम cv_results_ से rank_test_score कॉलम का उपयोग करके आसानी से best grid square चुन सकते हैं
best_row = cv_results_df[cv_results_df["rank_test_score"] == 1]
print(best_row)

test_score कॉलम फिर training_scores के लिए दोहराए जाते हैं.
कुछ बातों का ध्यान रखें:
training score कॉलम शामिल करने के लिए return_train_score True होना चाहिए.
training scores के लिए कोई ranking कॉलम नहीं होता, क्योंकि हमें test set प्रदर्शन की परवाह है
best grid square की जानकारी इन तीन प्रॉपर्टीज़ में साफ-सुथरे रूप में मिलती है:
best_params_, वह parameters की dictionary जिसने best score दिया.
best_score_, वास्तविक best score.
best_index_, हमारी cv_results_.rank_test_score में best वाली row.
best_estimator_ प्रॉपर्टी वह estimator है जो grid search के best parameters से बना है.
हमारे लिए यह Random Forest estimator है:
type(grid_rf_class.best_estimator_)
sklearn.ensemble.forest.RandomForestClassifier
आप चाहें तो इस ऑब्जेक्ट को सीधे estimator की तरह भी उपयोग कर सकते हैं!
print(grid_rf_class.best_estimator_)

कुछ अतिरिक्त जानकारी निम्न प्रॉपर्टीज़ में मिलती है:
scorer_held-out डेटा पर कौन सा scorer फंक्शन उपयोग हुआ. (हमने AUC सेट किया)
n_splits_कितने cross-validation splits. (हमने 5 सेट किया)
refit_time_पूरे डेटासेट पर best मॉडल को refit करने में लगे सेकंड.
Python में Hyperparameter Tuning