LightGBM Constraint
- pyscipopt_ml.lightgbm.add_lgbregressor_constr(scip_model, lightgbm_regressor, input_vars, output_vars=None, unique_naming_prefix='', epsilon=0.0, **kwargs)
Formulate lightgbm_regressor as constraints into a pyscipopt Model. Accommodates both Gradient Boosting Decision Trees and Random Forests as boosting types.
The formulation predicts the values of output_vars using input_vars according to lightgbm_regressor.
- Parameters:
scip_model (PySCIPOpt Model) – The pyscipopt Model where the predictor should be inserted.
lightgbm_regressor (
lightgbm.LGBMRegressor) – The gradient boosting regressor to insert as predictor.input_vars (list or dict) – Decision variables used as input for gradient boosting regressor in model.
output_vars (list or dict, optional) – Decision variables used as output for gradient boosting regressor in model.
unique_naming_prefix (str, optional) – A unique naming prefix that is used before all variable and constraint names. This parameter is important if the SCIP model is later printed to file and many predictors are added to the same SCIP model.
epsilon (float, optional) – Small value used to impose strict inequalities for splitting nodes in MIP formulations.
- Returns:
Object containing information about what was added to scip_model to formulate gradient_boosting_regressor.
- Return type:
LightGBMRegressorConstr
- Raises:
NoModel – If the boosting type is not “gbdt” or “rf”.
Note
See
add_predictor_constrfor acceptable values for input_vars and output_vars
- pyscipopt_ml.lightgbm.add_lgbclassifier_constr(scip_model, lightgbm_classifier, input_vars, output_vars=None, unique_naming_prefix='', epsilon=0.0, **kwargs)
Formulate lightgbm_classifier as constraints into a pyscipopt Model. Accommodates both Gradient Boosting Decision Trees and Random Forests as boosting types.
The formulation predicts the values of output_vars using input_vars according to lightgbm_classifier.
- Parameters:
scip_model (PySCIPOpt Model) – The pyscipopt Model where the predictor should be inserted.
lightgbm_classifier (
lightgbm.LGBMClassifier) – The gradient boosting classifier to insert as predictor.input_vars (list or dict) – Decision variables used as input for gradient boosting classifier in model.
output_vars (list or dict, optional) – Decision variables used as output for gradient boosting classifier in model.
unique_naming_prefix (str, optional) – A unique naming prefix that is used before all variable and constraint names. This parameter is important if the SCIP model is later printed to file and many predictors are added to the same SCIP model.
epsilon (float, optional) – Small value used to impose strict inequalities for splitting nodes in MIP formulations.
- Returns:
Object containing information about what was added to scip_model to formulate gradient_boosting_classifier.
- Return type:
LightGBMClassifierConstr
- Raises:
NoModel – If the boosting type is not “gbdt” or “rf”.
Note
See
add_predictor_constrfor acceptable values for input_vars and output_vars
- class pyscipopt_ml.lightgbm.lightgbm_constr.LightGBMConstr(scip_model, predictor, input_vars, output_vars, unique_naming_prefix='', epsilon=0.0, classification=False, **kwargs)
- Class to model trained
lightgbm.LGBMRegressoror lightgbm.LGBMClassifierwith constraints in a pyscipopt Model.
Stores the changes to the SCIP Model for representing an instance into it. Inherits from
AbstractPredictorConstr.- Class to model trained
- class pyscipopt_ml.lightgbm.lgbgetter.LGBgetter(predictor, input_vars, output_type='regular', **kwargs)
Utility class for lightgbm models convertors.
Implement some common functionalities: check predictor is fitted, output dimension, get error
- predictor
Lightgbm predictor embedded into SCIP model.
- extract_raw_data_and_create_tree_vars(epsilon=0.0)
Function for extracting information from lgb._Booster and creating additional modelling variables.
- Parameters:
epsilon (float, optional) – Small value used to impose strict inequalities for splitting nodes in MIP formulations.
- Returns:
trees (list) – A list of tree dictionaries similar in structure to that provided by SKlearn
tree_vars (np.ndarray) – A numpy array filled with variables that represent output of trees from the trained LightGBM model
- get_error(eps=None)
Returns error in SCIP’s solution with respect to the actual output of the trained predictor
- Parameters:
eps (float or int or None, optional) – The maximum allowed tolerance for a mismatch between the actual predictive model and SCIP. If the error is larger than eps an appropriate warning is printed
- Returns:
error – The absolute values of the difference between SCIP’s solution and the trained ML model’s output given the input as defined by SCIP. The matrix is the same dimension as the output of the trained predictor. Using sklearn / pyscipopt, the absolute difference between model.predict(input) and scip.getVal(output).
- Return type:
np.ndarray
- Raises:
NoSolution – If SCIP has no solution (either was not optimized or is infeasible).