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)
查看逻辑回归的超参数:
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 中的超参数调优