from sklearn.ensemble import GradientBoostingClassifier
加载模型
gbm0 = GradientBoostingClassifier(random_state=10)
训练
gbm0.fit(X, y)
训练开始使用默认值,后边用GridSearchCV搜索参数
from sklearn.model_selection import GridSearchCV
以迭代次数为例
param_test1 = {'n_estimators': range(20, 81, 10)}
gsearch1 = GridSearchCV(
estimator=GradientBoostingClassifier(learning_rate=0.1, min_samples_split=300, min_samples_leaf=20, max_depth=8,
max_features='sqrt', subsample=0.8, random_state=10),
param_grid=param_test1, scoring='roc_auc', cv=5)
输出最优参数
print(gsearch1.best_params_)
效果如下: