我有以下代码
eval_set = [(X_train, y_train), (X_test, y_test)]
eval_metric = ["auc","error"]
在以下部分中,我正在训练XGBClassifier
模型
model = XGBClassifier()
%time model.fit(X_train, y_train, eval_set=eval_set, eval_metric=eval_metric, verbose=True)
这给我以下格式的指标
[0] validation_0-auc:0.840532 validation_0-error:0.187758 validation_1-auc:0.84765 validation_1-error:0.17672
[1] validation_0-auc:0.840536 validation_0-error:0.187758 validation_1-auc:0.847665 validation_1-error:0.17672
....
[99] validation_0-auc:0.917587 validation_0-error:0.13846 validation_1-auc:0.918747 validation_1-error:0.137714
Wall time: 5 s
我由此制作了一个DataFrame,并在时间(0-99)与其他指标之间进行了绘制。还有其他方法可以直接绘制输出图吗?
我将从您的代码继续,以显示绘制AUC分数的示例。
results = model.evals_result()
epochs = len(results['validation_0']['error'])
x_axis = range(0, epochs)
结果是您的y轴值,epochs是您的“ n_estimators”值。下面的代码绘制了这些结果:
fig, ax = pyplot.subplots()
ax.plot(x_axis, results['validation_0']['auc'], label='Train')
ax.plot(x_axis, results['validation_1']['auc'], label='Test')
ax.legend()
pyplot.ylabel('AUC')
pyplot.title('XGBoost AUC')
pyplot.show()
然后将提供以下输出:
<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS92NllwOS5wbmcifQ==” alt =“ AUC XGBoost评估指标图”>“>
如果要查看分类错误,请在ax.plot中将['auc
']更改为['error']