Python में Hyperparameter Tuning
Alex Scriven
Data Scientist
यह कोर्स क्यों पढ़ें?
आपको "अंदर" कई चौंकाने वाली बातें मिलेंगी!
यह डेटासेट क्रेडिट कार्ड डिफॉल्ट्स से जुड़ा है.
इसमें ताइवान के कुछ उपभोक्ताओं के वित्तीय इतिहास से जुड़े वैरिएबल हैं. इसमें 30,000 यूज़र और 24 एट्रिब्यूट हैं.
हमारा मॉडलिंग टारगेट है कि क्या उन्होंने अपना लोन डिफॉल्ट किया
इसे पहले से प्रीप्रोसेस किया गया है और कभी-कभी हम कोई कॉन्सेप्ट दिखाने के लिए छोटे सैंपल लेंगे
डेटासेट की अतिरिक्त जानकारी यहाँ उपलब्ध है:
https://archive.ics.uci.edu/ml/datasets/default+of+credit+card+clients
पैरामीटर क्या है?
एक सरल लॉजिस्टिक रिग्रेशन मॉडल:
log_reg_clf = LogisticRegression() log_reg_clf.fit(X_train, y_train)print(log_reg_clf.coef_)
array([[-2.88651273e-06, -8.23168511e-03, 7.50857018e-04,
3.94375060e-04, 3.79423562e-04, 4.34612046e-04,
4.37561467e-04, 4.12107102e-04, -6.41089138e-06,
-4.39364494e-06, cont... ]])
कोएफिशिएंट्स को सहेजें:
# Get the original variable names original_variables = list(X_train.columns)# Zip together the names and coefficients zipped_together = list(zip(original_variables, log_reg_clf.coef_[0])) coefs = [list(x) for x in zipped_together]# Put into a DataFrame with column labels coefs = pd.DataFrame(coefs, columns=["Variable", "Coefficient"])
अब शीर्ष तीन कोएफिशिएंट्स को sort करके प्रिंट करें
coefs.sort_values(by=["Coefficient"], axis=0, inplace=True, ascending=False)
print(coefs.head(3))

पैरामीटर्स खोजने के लिए हमें चाहिए:
पैरामीटर्स 'parameters' सेक्शन में नहीं, 'Attributes' सेक्शन में मिलेंगे!
ट्री-आधारित एल्गोरिदम का क्या?
Random forest में कोएफिशिएंट्स नहीं होते, बल्कि नोड निर्णय होते हैं (किस फीचर पर और किस वैल्यू पर स्प्लिट करना).
# A simple random forest estimator rf_clf = RandomForestClassifier(max_depth=2) rf_clf.fit(X_train, y_train)# Pull out one tree from the forest chosen_tree = rf_clf.estimators_[7]
सरलता के लिए हम डिसीजन ट्री का अंतिम आउटपुट (एक इमेज) दिखाएँगे. आप चाहें तो इसके लिए उपयोग पैकेज (graphviz & pydotplus) खुद एक्सप्लोर करें.

हम ऊपर से दूसरे बाएँ नोड के विवरण निकाल सकते हैं:
# Get the column it split on split_column = chosen_tree.tree_.feature[1] split_column_name = X_train.columns[split_column]# Get the level it split on split_value = chosen_tree.tree_.threshold[1]print("This node split on feature {}, at a value of {}" .format(split_column_name, split_value))
"This node split on feature PAY_0, at a value of 1.5"
Python में Hyperparameter Tuning