ok
This commit is contained in:
parent
301685e0a4
commit
e77df13815
@ -76,8 +76,15 @@ def logregobj(preds, dtrain):
|
|||||||
return grad, hess
|
return grad, hess
|
||||||
|
|
||||||
# user defined evaluation function, return a pair metric_name, result
|
# user defined evaluation function, return a pair metric_name, result
|
||||||
|
# NOTE: when you do customized loss function, the default prediction value is margin
|
||||||
|
# this may make buildin evalution metric not function properly
|
||||||
|
# for example, we are doing logistic loss, the prediction is score before logistic transformation
|
||||||
|
# the buildin evaluation error assumes input is after logistic transformation
|
||||||
|
# Take this in mind when you use the customization, and maybe you need write customized evaluation function
|
||||||
def evalerror(preds, dtrain):
|
def evalerror(preds, dtrain):
|
||||||
labels = dtrain.get_label()
|
labels = dtrain.get_label()
|
||||||
|
# return a pair metric_name, result
|
||||||
|
# since preds are margin(before logistic transformation, cutoff at 0)
|
||||||
return 'error', float(sum(labels != (preds > 0.0))) / len(labels)
|
return 'error', float(sum(labels != (preds > 0.0))) / len(labels)
|
||||||
|
|
||||||
# training with customized objective, we can also do step by step training
|
# training with customized objective, we can also do step by step training
|
||||||
|
|||||||
@ -226,9 +226,6 @@ def train(params, dtrain, num_boost_round = 10, evals = [], obj=None, feval=None
|
|||||||
if len(evals) != 0:
|
if len(evals) != 0:
|
||||||
sys.stderr.write(evaluate(bst, evals, i, feval)+'\n')
|
sys.stderr.write(evaluate(bst, evals, i, feval)+'\n')
|
||||||
else:
|
else:
|
||||||
if len(evals) != 0 and feval == None:
|
|
||||||
print 'you need to provide your own evaluation function'
|
|
||||||
|
|
||||||
# try customized objective function
|
# try customized objective function
|
||||||
for i in range(num_boost_round):
|
for i in range(num_boost_round):
|
||||||
pred = bst.predict( dtrain )
|
pred = bst.predict( dtrain )
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user