xgboost
metric.h
Go to the documentation of this file.
1 
7 #ifndef XGBOOST_METRIC_H_
8 #define XGBOOST_METRIC_H_
9 
10 #include <dmlc/registry.h>
11 #include <xgboost/model.h>
13 #include <xgboost/data.h>
14 #include <xgboost/base.h>
16 
17 #include <vector>
18 #include <string>
19 #include <functional>
20 #include <utility>
21 
22 namespace xgboost {
27 class Metric : public Configurable {
28  protected:
30 
31  public:
36  virtual void Configure(
37  const std::vector<std::pair<std::string, std::string> >&) {}
44  void LoadConfig(Json const&) override {}
51  void SaveConfig(Json* p_out) const override {
52  auto& out = *p_out;
53  out["name"] = String(this->Name());
54  }
55 
61  virtual double Eval(const HostDeviceVector<bst_float>& preds, const MetaInfo& info) = 0;
63  virtual const char* Name() const = 0;
65  ~Metric() override = default;
74  static Metric* Create(const std::string& name, GenericParameter const* tparam);
75 };
76 
82 struct MetricReg
83  : public dmlc::FunctionRegEntryBase<MetricReg,
84  std::function<Metric* (const char*)> > {
85 };
86 
100 #define XGBOOST_REGISTER_METRIC(UniqueId, Name) \
101  ::xgboost::MetricReg& __make_ ## MetricReg ## _ ## UniqueId ## __ = \
102  ::dmlc::Registry< ::xgboost::MetricReg>::Get()->__REGISTER__(Name)
103 } // namespace xgboost
104 #endif // XGBOOST_METRIC_H_
defines configuration macros of xgboost.
Data structure representing JSON format.
Definition: json.h:356
Meta information about dataset, always sit in memory.
Definition: data.h:46
interface of evaluation metric used to evaluate model performance. This has nothing to do with traini...
Definition: metric.h:27
void SaveConfig(Json *p_out) const override
Save configuration to JSON object By default, metric has no internal configuration; override this fun...
Definition: metric.h:51
virtual void Configure(const std::vector< std::pair< std::string, std::string > > &)
Configure the Metric with the specified parameters.
Definition: metric.h:36
void LoadConfig(Json const &) override
Load configuration from JSON object By default, metric has no internal configuration; override this f...
Definition: metric.h:44
virtual const char * Name() const =0
GenericParameter const * tparam_
Definition: metric.h:29
virtual double Eval(const HostDeviceVector< bst_float > &preds, const MetaInfo &info)=0
evaluate a specific metric
~Metric() override=default
virtual destructor
static Metric * Create(const std::string &name, GenericParameter const *tparam)
create a metric according to name.
The input data structure of xgboost.
A device-and-host vector abstraction layer.
Defines the abstract interface for different components in XGBoost.
namespace of xgboost
Definition: base.h:110
JsonString String
Definition: json.h:594
Definition: model.h:31
Definition: generic_parameters.h:15
Registry entry for Metric factory functions. The additional parameter const char* param gives the val...
Definition: metric.h:84