Advice: Please illustrate the 'feval' argument


#1

I’m a new user of either xgboost python package or this forum. When using xgboost.train() function, I find it’s weird that there are only ‘eval_metric’=[‘mlogloss’,‘merror’] for multiclassification instead of ‘maccuracy’ (or there may be one but I don’t see). Anyway, after reading xgboost/core.py,

        if feval is not None:
            for dmat, evname in evals:
                feval_ret = feval(self.predict(dmat), dmat)
                if isinstance(feval_ret, list):
                    for name, val in feval_ret:
                        res += '\t%s-%s:%f' % (evname, name, val)
                else:
                    name, val = feval_ret
                    res += '\t%s-%s:%f' % (evname, name, val)
        return res

I find it’s vary easy to write a evaluation function for xgboost, but there are little words about this. For example, if I want to get a multiclass accuracy,

def maccuracy(predict,Dpair):
    label=Dpair.get_label()
    return ('maccuracy',sum(predict==label)/len(predict))

this is enough for me. Maybe a more usable method is to modify the xgboost/src/metric/multiclass_metric.cc, but I’m poor in C or CPP language.

I think it will be better if there are some examples and explanation about this ‘feval’ argument in documentation and code annotation.