commit the fix

This commit is contained in:
tqchen 2014-05-08 19:31:32 -07:00
parent 06327ff8d0
commit a0c0fbbb61
3 changed files with 20 additions and 13 deletions

View File

@ -200,11 +200,6 @@ namespace xgboost{
fprintf(fo, "[%d]", iter);
for (size_t i = 0; i < evals.size(); ++i){
this->PredictRaw(preds_, *evals[i]);
for( size_t j = 0 ; j < preds_.size(); ++ j){
if( fabsf(preds_[j]- 0.5f)>1e-6f){
printf("p[%lu]=%f\n", j,preds_[j]);
}
}
obj_->PredTransform(preds_);
evaluator_.Eval(fo, evname[i].c_str(), preds_, evals[i]->info);
}
@ -288,10 +283,7 @@ namespace xgboost{
#pragma omp parallel for schedule( static )
for (unsigned j = 0; j < ndata; ++j){
preds[j] = mparam.base_score + base_gbm.Predict(data.data, j, buffer_offset + j, data.info.GetRoot(j), bst_group );
if( preds[j] != 0.5f ){
printf("pred[%d:%u]=%f\n", bst_group, j, preds[j]);
}
utils::Assert( preds[j] == 0.5f, "BUG");
}
}else
#pragma omp parallel for schedule( static )

View File

@ -102,14 +102,22 @@ namespace xgboost{
/*! \brief Error */
struct EvalMatchError : public IEvaluator{
public:
EvalMatchError(const char *name){
name_ = name;
abs_ = 0;
if(!strcmp("mabserror", name)) abs_ =1;
}
virtual float Eval(const std::vector<float> &preds,
const DMatrix::Info &info) const {
const unsigned ndata = static_cast<unsigned>(preds.size());
float sum = 0.0f, wsum = 0.0f;
#pragma omp parallel for reduction(+:sum,wsum) schedule( static )
for (unsigned i = 0; i < ndata; ++i){
const float wt = info.GetWeight(i);
if (static_cast<int>(preds[i]) != static_cast<int>(info.labels[i]) ){
const float wt = info.GetWeight(i);
int label = static_cast<int>(info.labels[i]);
if( label < 0 && abs_ != 0 ) label = -label-1;
if (static_cast<int>(preds[i]) != label ){
sum += wt;
}
wsum += wt;
@ -117,10 +125,13 @@ namespace xgboost{
return sum / wsum;
}
virtual const char *Name(void) const{
return "merror";
return name_.c_str();
}
int abs_;
std::string name_;
};
/*! \brief Area under curve, for both classification and rank */
struct EvalAuc : public IEvaluator{
virtual float Eval(const std::vector<float> &preds,
@ -303,7 +314,8 @@ namespace xgboost{
}
if (!strcmp(name, "rmse")) evals_.push_back(new EvalRMSE());
if (!strcmp(name, "error")) evals_.push_back(new EvalError());
if (!strcmp(name, "merror")) evals_.push_back(new EvalMatchError());
if (!strcmp(name, "merror")) evals_.push_back(new EvalMatchError("merror"));
if (!strcmp(name, "mabserror")) evals_.push_back(new EvalMatchError("mabserror"));
if (!strcmp(name, "logloss")) evals_.push_back(new EvalLogLoss());
if (!strcmp(name, "auc")) evals_.push_back(new EvalAuc());
if (!strncmp(name, "pre@", 4)) evals_.push_back(new EvalPrecision(name));

View File

@ -134,6 +134,9 @@ namespace xgboost{
}
Softmax( rec );
int label = static_cast<int>(info.labels[j]);
if( label < 0 ){
label = -label - 1;
}
utils::Assert( label < nclass, "SoftmaxMultiClassObj: label exceed num_class" );
for( int k = 0; k < nclass; ++ k ){
float p = rec[ k ];