add dump statistics
This commit is contained in:
@@ -368,13 +368,15 @@ class Booster:
|
||||
None
|
||||
"""
|
||||
xglib.XGBoosterLoadModel( self.handle, ctypes.c_char_p(fname.encode('utf-8')) )
|
||||
def dump_model(self, fo, fmap=''):
|
||||
def dump_model(self, fo, fmap='', with_stats = False):
|
||||
"""dump model into text file
|
||||
Args:
|
||||
fo: string
|
||||
file name to be dumped
|
||||
fmap: string, optional
|
||||
file name of feature map names
|
||||
with_stats: bool, optional
|
||||
whether output statistics of the split
|
||||
Returns:
|
||||
None
|
||||
"""
|
||||
@@ -383,16 +385,18 @@ class Booster:
|
||||
need_close = True
|
||||
else:
|
||||
need_close = False
|
||||
ret = self.get_dump(fmap)
|
||||
ret = self.get_dump(fmap, with_stats)
|
||||
for i in range(len(ret)):
|
||||
fo.write('booster[%d]:\n' %i)
|
||||
fo.write( ret[i] )
|
||||
if need_close:
|
||||
fo.close()
|
||||
def get_dump(self, fmap=''):
|
||||
def get_dump(self, fmap='', with_stats=False):
|
||||
"""get dump of model as list of strings """
|
||||
length = ctypes.c_ulong()
|
||||
sarr = xglib.XGBoosterDumpModel(self.handle, ctypes.c_char_p(fmap.encode('utf-8')), ctypes.byref(length))
|
||||
sarr = xglib.XGBoosterDumpModel(self.handle,
|
||||
ctypes.c_char_p(fmap.encode('utf-8')),
|
||||
int(with_stats), ctypes.byref(length))
|
||||
res = []
|
||||
for i in range(length.value):
|
||||
res.append( str(sarr[i]) )
|
||||
|
||||
@@ -293,11 +293,11 @@ extern "C"{
|
||||
void XGBoosterSaveModel(const void *handle, const char *fname) {
|
||||
static_cast<const Booster*>(handle)->SaveModel(fname);
|
||||
}
|
||||
const char** XGBoosterDumpModel(void *handle, const char *fmap, bst_ulong *len){
|
||||
const char** XGBoosterDumpModel(void *handle, const char *fmap, int with_stats, bst_ulong *len){
|
||||
utils::FeatMap featmap;
|
||||
if (strlen(fmap) != 0) {
|
||||
featmap.LoadText(fmap);
|
||||
}
|
||||
return static_cast<Booster*>(handle)->GetModelDump(featmap, false, len);
|
||||
return static_cast<Booster*>(handle)->GetModelDump(featmap, with_stats != 0, len);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -200,11 +200,12 @@ extern "C" {
|
||||
* \brief dump model, return array of strings representing model dump
|
||||
* \param handle handle
|
||||
* \param fmap name to fmap can be empty string
|
||||
* \param with_stats whether to dump with statistics
|
||||
* \param out_len length of output array
|
||||
* \return char *data[], representing dump of each model
|
||||
*/
|
||||
XGB_DLL const char **XGBoosterDumpModel(void *handle, const char *fmap,
|
||||
bst_ulong *out_len);
|
||||
int with_stats, bst_ulong *out_len);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user