Python 超參數調校
Alex Scriven
Data Scientist
超參數:

建立一個簡單的隨機森林分類器並印出:
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)
以 n_estimators 為例。
資料型別與預設值:
n_estimators : integer, optional (default=10)
定義:
森林中的樹數量。
在建立估計器時設定部分超參數:
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)
此演算法可調的超參數較少!
有些超參數比其他更重要。
有些對模型效能沒有幫助:
以隨機森林分類器為例:
n_jobsrandom_state verbose不是所有超參數都適合「訓練」。
一些重要的超參數:
n_estimators(取較大值)max_features(嘗試不同值)max_depth 與 min_sample_leaf(與過擬合相關)criterion記住:這只是指引
學習資源:
Python 超參數調校