Grid search आउटपुट समझना

Python में Hyperparameter Tuning

Alex Scriven

Data Scientist

आउटपुट का विश्लेषण

आइए GridSearchCV के आउटपुट का विश्लेषण करें.

GridSearchCV प्रॉपर्टीज़ के तीन समूह:

  • एक परिणाम लॉग
    • cv_results_
  • सर्वश्रेष्ठ परिणाम
    • best_index_, best_params_ & best_score_
  • 'अतिरिक्त जानकारी'
    • scorer_, n_splits_ & refit_time_
Python में Hyperparameter Tuning

ऑब्जेक्ट प्रॉपर्टी एक्सेस करना

 

प्रॉपर्टीज़ को dot notation से एक्सेस करते हैं.

उदाहरण:

grid_search_object.property

जहाँ property वह असली प्रॉपर्टी है जिसे आप प्राप्त करना चाहते हैं

Python में Hyperparameter Tuning

.cv_results_ प्रॉपर्टी

cv_results_ प्रॉपर्टी:

इसे प्रिंट और विश्लेषण करने के लिए DataFrame में पढ़ें:

cv_results_df = pd.DataFrame(grid_rf_class.cv_results_)

print(cv_results_df.shape)

(12, 23)

  • 12 पंक्तियाँ हमारे ग्रिड के 12 squares या चलाए गए 12 मॉडलों के लिए
Python में Hyperparameter Tuning

.cv_results_ के 'time' कॉलम

time कॉलम उस समय को दर्शाते हैं जो मॉडल fit (और score) करने में लगा.

याद है हमने 5-fold cross-validation किया था? यह 5 बार चला और सेकंड में लगे समय का औसत और standard deviation स्टोर किया.

time columns

Python में Hyperparameter Tuning

.cv_results_ के 'param_' कॉलम

 

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

param columns

Python में Hyperparameter Tuning

.cv_results_ का 'param' कॉलम

params कॉलम में सभी parameters की dictionary होती है:

pd.set_option("display.max_colwidth", -1)
print(cv_results_df.loc[:, "params"])

params column

Python में Hyperparameter Tuning

.cv_results_ के 'test_score' कॉलम

 

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

test score

Python में Hyperparameter Tuning

.cv_results_ का 'rank_test_score' कॉलम

 

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

rank test score

Python में Hyperparameter Tuning

सर्वश्रेष्ठ row निकालना

 

हम cv_results_ से rank_test_score कॉलम का उपयोग करके आसानी से best grid square चुन सकते हैं

best_row = cv_results_df[cv_results_df["rank_test_score"] == 1]
print(best_row)

best row

Python में Hyperparameter Tuning

.cv_results_ के 'train_score' कॉलम

test_score कॉलम फिर training_scores के लिए दोहराए जाते हैं.

कुछ बातों का ध्यान रखें:

  • training score कॉलम शामिल करने के लिए return_train_score True होना चाहिए.

  • training scores के लिए कोई ranking कॉलम नहीं होता, क्योंकि हमें test set प्रदर्शन की परवाह है

Python में Hyperparameter Tuning

सर्वश्रेष्ठ grid square

 

best grid square की जानकारी इन तीन प्रॉपर्टीज़ में साफ-सुथरे रूप में मिलती है:

  • best_params_, वह parameters की dictionary जिसने best score दिया.

  • best_score_, वास्तविक best score.

  • best_index_, हमारी cv_results_.rank_test_score में best वाली row.

Python में Hyperparameter Tuning

best_estimator_ प्रॉपर्टी

 

best_estimator_ प्रॉपर्टी वह estimator है जो grid search के best parameters से बना है.

हमारे लिए यह Random Forest estimator है:

type(grid_rf_class.best_estimator_)

sklearn.ensemble.forest.RandomForestClassifier

आप चाहें तो इस ऑब्जेक्ट को सीधे estimator की तरह भी उपयोग कर सकते हैं!

Python में Hyperparameter Tuning

best_estimator_ प्रॉपर्टी

print(grid_rf_class.best_estimator_)

best estimator कोड का प्रिंट आउट

Python में Hyperparameter Tuning

अतिरिक्त जानकारी

कुछ अतिरिक्त जानकारी निम्न प्रॉपर्टीज़ में मिलती है:

  • scorer_

held-out डेटा पर कौन सा scorer फंक्शन उपयोग हुआ. (हमने AUC सेट किया)

  • n_splits_

कितने cross-validation splits. (हमने 5 सेट किया)

  • refit_time_

पूरे डेटासेट पर best मॉडल को refit करने में लगे सेकंड.

Python में Hyperparameter Tuning

अभ्यास करते हैं!

Python में Hyperparameter Tuning

Preparing Video For Download...