MCPcopy Create free account
hub / github.com/antmachineintelligence/mtgbmcode / dump_model

Method dump_model

python-package/lightgbmmt/basic.py:2390–2435  ·  view source on GitHub ↗

Dump Booster to JSON format. Parameters ---------- num_iteration : int or None, optional (default=None) Index of the iteration that should be dumped. If None, if the best iteration exists, it is dumped; otherwise, all iterations are dumped.

(self, num_iteration=None, start_iteration=0)

Source from the content-addressed store, hash-verified

2388 return ret
2389
2390 def dump_model(self, num_iteration=None, start_iteration=0):
2391 """Dump Booster to JSON format.
2392
2393 Parameters
2394 ----------
2395 num_iteration : int or None, optional (default=None)
2396 Index of the iteration that should be dumped.
2397 If None, if the best iteration exists, it is dumped; otherwise, all iterations are dumped.
2398 If <= 0, all iterations are dumped.
2399 start_iteration : int, optional (default=0)
2400 Start index of the iteration that should be dumped.
2401
2402 Returns
2403 -------
2404 json_repr : dict
2405 JSON format of Booster.
2406 """
2407 if num_iteration is None:
2408 num_iteration = self.best_iteration
2409 buffer_len = 1 << 20
2410 tmp_out_len = ctypes.c_int64(0)
2411 string_buffer = ctypes.create_string_buffer(buffer_len)
2412 ptr_string_buffer = ctypes.c_char_p(*[ctypes.addressof(string_buffer)])
2413 _safe_call(_LIB.LGBM_BoosterDumpModel(
2414 self.handle,
2415 ctypes.c_int(start_iteration),
2416 ctypes.c_int(num_iteration),
2417 ctypes.c_int64(buffer_len),
2418 ctypes.byref(tmp_out_len),
2419 ptr_string_buffer))
2420 actual_len = tmp_out_len.value
2421 # if buffer length is not long enough, reallocate a buffer
2422 if actual_len > buffer_len:
2423 string_buffer = ctypes.create_string_buffer(actual_len)
2424 ptr_string_buffer = ctypes.c_char_p(*[ctypes.addressof(string_buffer)])
2425 _safe_call(_LIB.LGBM_BoosterDumpModel(
2426 self.handle,
2427 ctypes.c_int(start_iteration),
2428 ctypes.c_int(num_iteration),
2429 ctypes.c_int64(actual_len),
2430 ctypes.byref(tmp_out_len),
2431 ptr_string_buffer))
2432 ret = json.loads(string_buffer.value.decode())
2433 ret['pandas_categorical'] = json.loads(json.dumps(self.pandas_categorical,
2434 default=json_default_with_numpy))
2435 return ret
2436
2437 def predict(self, data, num_iteration=None,
2438 raw_score=False, pred_leaf=False, pred_contrib=False,

Callers 2

create_tree_digraphFunction · 0.80

Calls 1

_safe_callFunction · 0.85

Tested by

no test coverage detected