fix base score, and print message

This commit is contained in:
tqchen@graphlab.com
2014-08-18 10:53:15 -07:00
parent 04e04ec5a0
commit f6c763a2a7
7 changed files with 39 additions and 14 deletions

View File

@@ -85,15 +85,22 @@ class BoostLearner {
if (!strcmp(name, "booster")) name_gbm_ = val;
mparam.SetParam(name, val);
}
if (gbm_ != NULL) gbm_->SetParam(name, val);
if (obj_ != NULL) obj_->SetParam(name, val);
cfg_.push_back(std::make_pair(std::string(name), std::string(val)));
}
/*!
* \brief initialize the model
*/
inline void InitModel(void) {
// initialize model
this->InitObjGBM();
// adapt the base score
// reset the base score
mparam.base_score = obj_->ProbToMargin(mparam.base_score);
char tmp[32];
snprintf(tmp, sizeof(tmp), "%g", mparam.base_score);
this->SetParam("base_score", tmp);
// initialize GBM model
gbm_->InitModel();
}
/*!

View File

@@ -124,7 +124,7 @@ class RegLossObj : public IObjFunction{
loss.SecondOrderGradient(p, info.labels[j]) * w);
}
}
virtual const char* DefaultEvalMetric(void) {
virtual const char* DefaultEvalMetric(void) const {
return loss.DefaultEvalMetric();
}
virtual void PredTransform(std::vector<float> *io_preds) {
@@ -135,6 +135,9 @@ class RegLossObj : public IObjFunction{
preds[j] = loss.PredTransform(preds[j]);
}
}
virtual float ProbToMargin(float base_score) const {
return loss.ProbToMargin(base_score);
}
protected:
float scale_pos_weight;
@@ -192,7 +195,7 @@ class SoftmaxMultiClassObj : public IObjFunction {
virtual void EvalTransform(std::vector<float> *io_preds) {
this->Transform(io_preds, 0);
}
virtual const char* DefaultEvalMetric(void) {
virtual const char* DefaultEvalMetric(void) const {
return "merror";
}
@@ -320,7 +323,7 @@ class LambdaRankObj : public IObjFunction {
}
}
}
virtual const char* DefaultEvalMetric(void) {
virtual const char* DefaultEvalMetric(void) const {
return "map";
}

View File

@@ -32,7 +32,7 @@ class IObjFunction{
int iter,
std::vector<bst_gpair> *out_gpair) = 0;
/*! \return the default evaluation metric for the objective */
virtual const char* DefaultEvalMetric(void) = 0;
virtual const char* DefaultEvalMetric(void) const = 0;
// the following functions are optional, most of time default implementation is good enough
/*!
* \brief transform prediction values, this is only called when Prediction is called
@@ -53,7 +53,7 @@ class IObjFunction{
* used by gradient boosting
* \return transformed value
*/
virtual float ProbToMargin(float base_score) {
virtual float ProbToMargin(float base_score) const {
return base_score;
}
};