From 2c7c27e297044697b634cc07b31809cb8133ed26 Mon Sep 17 00:00:00 2001 From: Zheng RuiFeng Date: Wed, 24 Feb 2016 11:15:31 +0800 Subject: [PATCH] create mae --- doc/parameter.md | 1 + src/metric/elementwise_metric.cc | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/doc/parameter.md b/doc/parameter.md index b22a20df5..7548532d6 100644 --- a/doc/parameter.md +++ b/doc/parameter.md @@ -80,6 +80,7 @@ Specify the learning task and the corresponding learning objective. The objectiv - User can add multiple evaluation metrics, for python user, remember to pass the metrics in as list of parameters pairs instead of map, so that latter 'eval_metric' won't override previous one - The choices are listed below: - "rmse": [root mean square error](http://en.wikipedia.org/wiki/Root_mean_square_error) + - "mae": [mean absolute error](https://en.wikipedia.org/wiki/Mean_absolute_error) - "logloss": negative [log-likelihood](http://en.wikipedia.org/wiki/Log-likelihood) - "error": Binary classification error rate. It is calculated as #(wrong cases)/#(all cases). For the predictions, the evaluation will regard the instances with prediction value larger than 0.5 as positive instances, and the others as negative instances. - "merror": Multiclass classification error rate. It is calculated as #(wrong cases)/#(all cases). diff --git a/src/metric/elementwise_metric.cc b/src/metric/elementwise_metric.cc index e0086c9c9..5c599f619 100644 --- a/src/metric/elementwise_metric.cc +++ b/src/metric/elementwise_metric.cc @@ -72,6 +72,15 @@ struct EvalRMSE : public EvalEWiseBase { } }; +struct EvalMAE : public EvalEWiseBase { + const char *Name() const override { + return "mae"; + } + inline static float EvalRow(float label, float pred) { + return std::abs(label - pred); + } +}; + struct EvalLogLoss : public EvalEWiseBase { const char *Name() const override { return "logloss"; @@ -114,6 +123,10 @@ XGBOOST_REGISTER_METRIC(RMSE, "rmse") .describe("Rooted mean square error.") .set_body([](const char* param) { return new EvalRMSE(); }); +XGBOOST_REGISTER_METRIC(MAE, "mae") +.describe("Mean absolute error.") +.set_body([](const char* param) { return new EvalMAE(); }); + XGBOOST_REGISTER_METRIC(LogLoss, "logloss") .describe("Negative loglikelihood for logistic regression.") .set_body([](const char* param) { return new EvalLogLoss(); });