metric.cpp 2.1 KB
Newer Older
Guolin Ke's avatar
Guolin Ke committed
1
2
3
4
#include <LightGBM/metric.h>
#include "regression_metric.hpp"
#include "binary_metric.hpp"
#include "rank_metric.hpp"
Guolin Ke's avatar
Guolin Ke committed
5
#include "map_metric.hpp"
6
#include "multiclass_metric.hpp"
7
#include "xentropy_metric.hpp"
Guolin Ke's avatar
Guolin Ke committed
8
9
10
11

namespace LightGBM {

Metric* Metric::CreateMetric(const std::string& type, const MetricConfig& config) {
12
  if (type == std::string("l2") || type == std::string("mean_squared_error") || type == std::string("mse")) {
Guolin Ke's avatar
Guolin Ke committed
13
    return new L2Metric(config);
14
15
  } else if (type == std::string("l2_root") || type == std::string("root_mean_squared_error") || type == std::string("rmse")) {
    return new RMSEMetric(config);
16
  } else if (type == std::string("l1") || type == std::string("mean_absolute_error") || type == std::string("mae")) {
Guolin Ke's avatar
Guolin Ke committed
17
    return new L1Metric(config);
18
19
  } else if (type == std::string("quantile")) {
    return new QuantileMetric(config);
Tsukasa OMOTO's avatar
Tsukasa OMOTO committed
20
21
  } else if (type == std::string("huber")) {
    return new HuberLossMetric(config);
Tsukasa OMOTO's avatar
Tsukasa OMOTO committed
22
23
  } else if (type == std::string("fair")) {
    return new FairLossMetric(config);
24
25
  } else if (type == std::string("poisson")) {
    return new PoissonMetric(config);
Guolin Ke's avatar
Guolin Ke committed
26
  } else if (type == std::string("binary_logloss")) {
Guolin Ke's avatar
Guolin Ke committed
27
    return new BinaryLoglossMetric(config);
Guolin Ke's avatar
Guolin Ke committed
28
  } else if (type == std::string("binary_error")) {
Guolin Ke's avatar
Guolin Ke committed
29
    return new BinaryErrorMetric(config);
Guolin Ke's avatar
Guolin Ke committed
30
  } else if (type == std::string("auc")) {
Guolin Ke's avatar
Guolin Ke committed
31
    return new AUCMetric(config);
Guolin Ke's avatar
Guolin Ke committed
32
  } else if (type == std::string("ndcg")) {
Guolin Ke's avatar
Guolin Ke committed
33
    return new NDCGMetric(config);
Guolin Ke's avatar
Guolin Ke committed
34
35
  } else if (type == std::string("map")) {
    return new MapMetric(config);
Guolin Ke's avatar
Guolin Ke committed
36
  } else if (type == std::string("multi_logloss")) {
Guolin Ke's avatar
Guolin Ke committed
37
    return new MultiSoftmaxLoglossMetric(config);
Guolin Ke's avatar
Guolin Ke committed
38
  } else if (type == std::string("multi_error")) {
39
    return new MultiErrorMetric(config);
40
41
42
43
44
45
  } else if (type == std::string("xentropy") || type == std::string("cross_entropy")) {
    return new CrossEntropyMetric(config);
  } else if (type == std::string("xentlambda")) {
    return new CrossEntropyLambdaMetric(config);
  } else if (type == std::string("kldiv") || type == std::string("kullback_leibler")) {
    return new KullbackLeiblerDivergence(config);
Guolin Ke's avatar
Guolin Ke committed
46
47
48
49
50
  }
  return nullptr;
}

}  // namespace LightGBM