metric.cpp 3.14 KB
Newer Older
1
2
3
4
/*!
 * Copyright (c) 2016 Microsoft Corporation. All rights reserved.
 * Licensed under the MIT License. See LICENSE file in the project root for license information.
 */
Guolin Ke's avatar
Guolin Ke committed
5
#include <LightGBM/metric.h>
6

Guolin Ke's avatar
Guolin Ke committed
7
#include "binary_metric.hpp"
Guolin Ke's avatar
Guolin Ke committed
8
#include "map_metric.hpp"
9
#include "multiclass_metric.hpp"
10
11
#include "rank_metric.hpp"
#include "regression_metric.hpp"
12
#include "xentropy_metric.hpp"
Guolin Ke's avatar
Guolin Ke committed
13
14
15

namespace LightGBM {

Guolin Ke's avatar
Guolin Ke committed
16
Metric* Metric::CreateMetric(const std::string& type, const Config& config) {
17
  if (type == std::string("regression") || type == std::string("regression_l2") || type == std::string("l2") || type == std::string("mean_squared_error") || type == std::string("mse")) {
Guolin Ke's avatar
Guolin Ke committed
18
    return new L2Metric(config);
19
20
  } else if (type == std::string("l2_root") || type == std::string("root_mean_squared_error") || type == std::string("rmse")) {
    return new RMSEMetric(config);
21
  } else if (type == std::string("regression_l1") || type == std::string("l1") || type == std::string("mean_absolute_error") || type == std::string("mae")) {
Guolin Ke's avatar
Guolin Ke committed
22
    return new L1Metric(config);
23
24
  } else if (type == std::string("quantile")) {
    return new QuantileMetric(config);
Tsukasa OMOTO's avatar
Tsukasa OMOTO committed
25
26
  } else if (type == std::string("huber")) {
    return new HuberLossMetric(config);
Tsukasa OMOTO's avatar
Tsukasa OMOTO committed
27
28
  } else if (type == std::string("fair")) {
    return new FairLossMetric(config);
29
30
  } else if (type == std::string("poisson")) {
    return new PoissonMetric(config);
31
  } else if (type == std::string("binary_logloss") || type == std::string("binary")) {
Guolin Ke's avatar
Guolin Ke committed
32
    return new BinaryLoglossMetric(config);
Guolin Ke's avatar
Guolin Ke committed
33
  } else if (type == std::string("binary_error")) {
Guolin Ke's avatar
Guolin Ke committed
34
    return new BinaryErrorMetric(config);
Guolin Ke's avatar
Guolin Ke committed
35
  } else if (type == std::string("auc")) {
Guolin Ke's avatar
Guolin Ke committed
36
    return new AUCMetric(config);
37
  } else if (type == std::string("ndcg") || type == std::string("lambdarank")) {
Guolin Ke's avatar
Guolin Ke committed
38
    return new NDCGMetric(config);
39
  } else if (type == std::string("map") || type == std::string("mean_average_precision")) {
Guolin Ke's avatar
Guolin Ke committed
40
    return new MapMetric(config);
Nikita Titov's avatar
Nikita Titov committed
41
  } else if (type == std::string("multi_logloss") || type == std::string("multiclass") || type == std::string("softmax") || type == std::string("multiclassova") || type == std::string("multiclass_ova") || type == std::string("ova") || type == std::string("ovr")) {
Guolin Ke's avatar
Guolin Ke committed
42
    return new MultiSoftmaxLoglossMetric(config);
Guolin Ke's avatar
Guolin Ke committed
43
  } else if (type == std::string("multi_error")) {
44
    return new MultiErrorMetric(config);
45
46
  } else if (type == std::string("xentropy") || type == std::string("cross_entropy")) {
    return new CrossEntropyMetric(config);
47
  } else if (type == std::string("xentlambda") || type == std::string("cross_entropy_lambda")) {
48
49
50
    return new CrossEntropyLambdaMetric(config);
  } else if (type == std::string("kldiv") || type == std::string("kullback_leibler")) {
    return new KullbackLeiblerDivergence(config);
51
52
  } else if (type == std::string("mean_absolute_percentage_error") || type == std::string("mape")) {
    return new MAPEMetric(config);
Guolin Ke's avatar
Guolin Ke committed
53
54
  } else if (type == std::string("gamma")) {
    return new GammaMetric(config);
Nikita Titov's avatar
Nikita Titov committed
55
  } else if (type == std::string("gamma_deviance")) {
Guolin Ke's avatar
Guolin Ke committed
56
57
58
    return new GammaDevianceMetric(config);
  } else if (type == std::string("tweedie")) {
    return new TweedieMetric(config);
Guolin Ke's avatar
Guolin Ke committed
59
60
61
62
63
  }
  return nullptr;
}

}  // namespace LightGBM