_InnerPredictor of LightGBM. Not exposed to user. Used only for prediction, usually used for continued training. .. note:: Can be converted from Booster, but cannot be converted to Booster.
| 405 | |
| 406 | |
| 407 | class _InnerPredictor(object): |
| 408 | """_InnerPredictor of LightGBM. |
| 409 | |
| 410 | Not exposed to user. |
| 411 | Used only for prediction, usually used for continued training. |
| 412 | |
| 413 | .. note:: |
| 414 | |
| 415 | Can be converted from Booster, but cannot be converted to Booster. |
| 416 | """ |
| 417 | |
| 418 | def __init__(self, model_file=None, booster_handle=None, pred_parameter=None): |
| 419 | """Initialize the _InnerPredictor. |
| 420 | |
| 421 | Parameters |
| 422 | ---------- |
| 423 | model_file : string or None, optional (default=None) |
| 424 | Path to the model file. |
| 425 | booster_handle : object or None, optional (default=None) |
| 426 | Handle of Booster. |
| 427 | pred_parameter: dict or None, optional (default=None) |
| 428 | Other parameters for the prediciton. |
| 429 | """ |
| 430 | self.handle = ctypes.c_void_p() |
| 431 | self.__is_manage_handle = True |
| 432 | if model_file is not None: |
| 433 | """Prediction task""" |
| 434 | out_num_iterations = ctypes.c_int(0) |
| 435 | _safe_call(_LIB.LGBM_BoosterCreateFromModelfile( |
| 436 | c_str(model_file), |
| 437 | ctypes.byref(out_num_iterations), |
| 438 | ctypes.byref(self.handle))) |
| 439 | out_num_class = ctypes.c_int(0) |
| 440 | _safe_call(_LIB.LGBM_BoosterGetNumClasses( |
| 441 | self.handle, |
| 442 | ctypes.byref(out_num_class))) |
| 443 | self.num_class = out_num_class.value |
| 444 | self.num_total_iteration = out_num_iterations.value |
| 445 | self.pandas_categorical = _load_pandas_categorical(file_name=model_file) |
| 446 | elif booster_handle is not None: |
| 447 | self.__is_manage_handle = False |
| 448 | self.handle = booster_handle |
| 449 | out_num_class = ctypes.c_int(0) |
| 450 | _safe_call(_LIB.LGBM_BoosterGetNumClasses( |
| 451 | self.handle, |
| 452 | ctypes.byref(out_num_class))) |
| 453 | self.num_class = out_num_class.value |
| 454 | out_num_iterations = ctypes.c_int(0) |
| 455 | _safe_call(_LIB.LGBM_BoosterGetCurrentIteration( |
| 456 | self.handle, |
| 457 | ctypes.byref(out_num_iterations))) |
| 458 | self.num_total_iteration = out_num_iterations.value |
| 459 | self.pandas_categorical = None |
| 460 | else: |
| 461 | raise TypeError('Need model_file or booster_handle to create a predictor') |
| 462 | |
| 463 | pred_parameter = {} if pred_parameter is None else pred_parameter |
| 464 | self.pred_parameter = param_dict_to_str(pred_parameter) |
no outgoing calls
no test coverage detected