Fixes for multiple and default metric (#1239)

* fix multiple evaluation metrics

* create DefaultEvalMetric only when really necessary

* py test for #1239

* make travis happy
This commit is contained in:
Vadim Khotilovich
2016-06-05 00:17:35 -05:00
committed by Tianqi Chen
parent 9ef86072f4
commit 9a48a40cf1
3 changed files with 17 additions and 7 deletions

View File

@@ -33,7 +33,10 @@ class Booster {
inline void SetParam(const std::string& name, const std::string& val) {
auto it = std::find_if(cfg_.begin(), cfg_.end(),
[&name](decltype(*cfg_.begin()) &x) {
[&name, &val](decltype(*cfg_.begin()) &x) {
if (name == "eval_metric") {
return x.first == name && x.second == val;
}
return x.first == name;
});
if (it == cfg_.end()) {

View File

@@ -256,9 +256,6 @@ class LearnerImpl : public Learner {
attributes_ = std::map<std::string, std::string>(
attr.begin(), attr.end());
}
if (metrics_.size() == 0) {
metrics_.emplace_back(Metric::Create(obj_->DefaultEvalMetric()));
}
this->base_score_ = mparam.base_score;
gbm_->ResetPredBuffer(pred_buffer_size_);
cfg_["num_class"] = common::ToString(mparam.num_class);
@@ -307,6 +304,9 @@ class LearnerImpl : public Learner {
std::ostringstream os;
os << '[' << iter << ']'
<< std::setiosflags(std::ios::fixed);
if (metrics_.size() == 0) {
metrics_.emplace_back(Metric::Create(obj_->DefaultEvalMetric()));
}
for (size_t i = 0; i < data_sets.size(); ++i) {
this->PredictRaw(data_sets[i], &preds_);
obj_->EvalTransform(&preds_);
@@ -445,9 +445,6 @@ class LearnerImpl : public Learner {
// reset the base score
mparam.base_score = obj_->ProbToMargin(mparam.base_score);
if (metrics_.size() == 0) {
metrics_.emplace_back(Metric::Create(obj_->DefaultEvalMetric()));
}
this->base_score_ = mparam.base_score;
gbm_->ResetPredBuffer(pred_buffer_size_);