I've the following code
eval_set = [(X_train, y_train), (X_test, y_test)]
eval_metric = ["auc","error"]
In the following part, I'm training the XGBClassifier
model
model = XGBClassifier()
%time model.fit(X_train, y_train, eval_set=eval_set, eval_metric=eval_metric, verbose=True)
This gives me the metrics in the following format
[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
I made a DataFrame out of this and plotted between time (0-99) and the other metrics. Is there any other way to plot directly feeding the output?
eval_metric [default according to objective] Evaluation metrics for validation data, a default metric will be assigned according to objective (rmse for regression, and logloss for classification, mean average precision for ranking)
To understand the power of XGBoost, we need to compare it with another algorithm. We first use the decision tree classifier algorithm to build the model. After that, we build the same model using XGBoost and compare the results to see if XGBoost has improved the model performance.
The XGBoost objective function used when predicting numerical values is the “reg:squarederror” loss function. “reg:squarederror”: Loss function for regression predictive modeling problems.
I'll continue from your code to show the example of plotting your AUC score.
results = model.evals_result()
epochs = len(results['validation_0']['error'])
x_axis = range(0, epochs)
results is your y-axis values, and epochs is your 'n_estimators' value. Code below plots these results:
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()
This will then give the following output:
If you want to look at classification error, change ['auc'] to ['error'] within ax.plot
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With