การปรับ Hyperparameter ใน Python
Alex Scriven
Data Scientist
ไฮเปอร์พารามิเตอร์:

สร้าง random forest estimator อย่างง่ายแล้วพิมพ์ผลออกมา:
rf_clf = RandomForestClassifier() print(rf_clf)RandomForestClassifier(n_estimators='warn', criterion='gini', max_depth=None, max_features='auto', max_leaf_nodes=None, min_impurity_decrease=0.0, min_impurity_split=None, min_samples_leaf=1, min_samples_split=2, min_weight_fraction_leaf=0.0, n_jobs=None, oob_score=False, random_state=None, verbose=0,bootstrap=True, class_weight=None, warm_start=False)
ข้อมูลเพิ่มเติม: http://scikit-learn.org
ลองดูพารามิเตอร์ n_estimators
ชนิดข้อมูลและค่าเริ่มต้น:
n_estimators : integer, optional (default=10)
ความหมาย:
The number of trees in the forest.
กำหนดไฮเปอร์พารามิเตอร์บางค่าตอนสร้าง estimator:
rf_clf = RandomForestClassifier(n_estimators=100, criterion='entropy')
print(rf_clf)
RandomForestClassifier(n_estimators=100, criterion='entropy',
max_depth=None, max_features='auto', max_leaf_nodes=None,
min_impurity_decrease=0.0, min_impurity_split=None,
min_samples_leaf=1, min_samples_split=2,
min_weight_fraction_leaf=0.0, n_jobs=None,
oob_score=False, random_state=None, verbose=0,bootstrap=True,
class_weight=None, warm_start=False)
ค้นหาไฮเปอร์พารามิเตอร์ของ Logistic Regression:
log_reg_clf = LogisticRegression()print(log_reg_clf) LogisticRegression(C=1.0, class_weight=None, dual=False, fit_intercept=True, intercept_scaling=1, max_iter=100, multi_class='warn', n_jobs=None, penalty='l2', random_state=None, solver='warn', tol=0.0001, verbose=0, warm_start=False)
อัลกอริทึมนี้มีไฮเปอร์พารามิเตอร์ให้ปรับน้อยกว่า!
ไฮเปอร์พารามิเตอร์บางตัวสำคัญกว่าตัวอื่น
บางตัวไม่ช่วยให้ประสิทธิภาพโมเดลดีขึ้น:
สำหรับ random forest classifier:
n_jobsrandom_state verboseไม่ใช่ทุกไฮเปอร์พารามิเตอร์ที่ควรนำมา "ปรับจูน"
ไฮเปอร์พารามิเตอร์สำคัญที่ควรพิจารณา:
n_estimators (ค่าสูง)max_features (ลองหลายค่า)max_depth & min_sample_leaf (สำคัญสำหรับการ overfitting)criterionจำไว้ว่านี่เป็นเพียงแนวทางเท่านั้น
แหล่งข้อมูลสำหรับศึกษาเพิ่มเติม:
การปรับ Hyperparameter ใน Python