keep builtin evaluations while using customized evaluation function (#1624)
* keep builtin evaluations while using customized evaluation function * fix concat bytes to str
This commit is contained in:
parent
8b9d9669bb
commit
55bfc29942
@ -864,23 +864,21 @@ class Booster(object):
|
|||||||
result: str
|
result: str
|
||||||
Evaluation result string.
|
Evaluation result string.
|
||||||
"""
|
"""
|
||||||
if feval is None:
|
for d in evals:
|
||||||
for d in evals:
|
if not isinstance(d[0], DMatrix):
|
||||||
if not isinstance(d[0], DMatrix):
|
raise TypeError('expected DMatrix, got {}'.format(type(d[0]).__name__))
|
||||||
raise TypeError('expected DMatrix, got {}'.format(type(d[0]).__name__))
|
if not isinstance(d[1], STRING_TYPES):
|
||||||
if not isinstance(d[1], STRING_TYPES):
|
raise TypeError('expected string, got {}'.format(type(d[1]).__name__))
|
||||||
raise TypeError('expected string, got {}'.format(type(d[1]).__name__))
|
self._validate_features(d[0])
|
||||||
self._validate_features(d[0])
|
|
||||||
|
|
||||||
dmats = c_array(ctypes.c_void_p, [d[0].handle for d in evals])
|
dmats = c_array(ctypes.c_void_p, [d[0].handle for d in evals])
|
||||||
evnames = c_array(ctypes.c_char_p, [c_str(d[1]) for d in evals])
|
evnames = c_array(ctypes.c_char_p, [c_str(d[1]) for d in evals])
|
||||||
msg = ctypes.c_char_p()
|
msg = ctypes.c_char_p()
|
||||||
_check_call(_LIB.XGBoosterEvalOneIter(self.handle, iteration,
|
_check_call(_LIB.XGBoosterEvalOneIter(self.handle, iteration,
|
||||||
dmats, evnames, len(evals),
|
dmats, evnames, len(evals),
|
||||||
ctypes.byref(msg)))
|
ctypes.byref(msg)))
|
||||||
return msg.value
|
res = msg.value.decode()
|
||||||
else:
|
if feval is not None:
|
||||||
res = '[%d]' % iteration
|
|
||||||
for dmat, evname in evals:
|
for dmat, evname in evals:
|
||||||
feval_ret = feval(self.predict(dmat), dmat)
|
feval_ret = feval(self.predict(dmat), dmat)
|
||||||
if isinstance(feval_ret, list):
|
if isinstance(feval_ret, list):
|
||||||
@ -889,7 +887,7 @@ class Booster(object):
|
|||||||
else:
|
else:
|
||||||
name, val = feval_ret
|
name, val = feval_ret
|
||||||
res += '\t%s-%s:%f' % (evname, name, val)
|
res += '\t%s-%s:%f' % (evname, name, val)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def eval(self, data, name='eval', iteration=0):
|
def eval(self, data, name='eval', iteration=0):
|
||||||
"""Evaluate the model on mat.
|
"""Evaluate the model on mat.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user