XGBoost Constraint
- pyscipopt_ml.xgboost.add_xgbregressor_constr(scip_model, xgboost_regressor, input_vars, output_vars=None, unique_naming_prefix='', epsilon=0.0, **kwargs)
Formulate xgboost_regressor (gradient boosting decision tree) as constraints into a pyscipopt Model.
The formulation predicts the values of output_vars using input_vars according to xgboost_regressor.
- Parameters:
scip_model (PySCIPOpt Model) – The pyscipopt Model where the predictor should be inserted.
xgboost_regressor (
xgboost.XGBRegressor) – 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:
XGBoostRegressorConstr
Note
See
add_predictor_constrfor acceptable values for input_vars and output_vars- Raises:
NoModel – If the booster is not of type “gbtree”.
- pyscipopt_ml.xgboost.add_xgbclassifier_constr(scip_model, xgboost_classifier, input_vars, output_vars=None, unique_naming_prefix='', epsilon=0.0, **kwargs)
Formulate xgboost_classifier (gradient boosting decision tree) as constraints into a pyscipopt Model.
The formulation predicts the values of output_vars using input_vars according to xgboost_classifier.
- Parameters:
scip_model (PySCIPOpt Model) – The pyscipopt Model where the predictor should be inserted.
xgboost_classifier (
xgboost.XGBClassifier) – The gradient boosting classifier 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_classifier.
- Return type:
XGBoostClassifierConstr
Note
See
add_predictor_constrfor acceptable values for input_vars and output_vars- Raises:
NoModel – If the booster is not of type “gbtree”.
- pyscipopt_ml.xgboost.add_xgbregressor_rf_constr(scip_model, xgboost_regressor, input_vars, output_vars=None, unique_naming_prefix='', epsilon=0.0, **kwargs)
Formulate xgboost_regressor (random forest) as constraints into a pyscipopt Model.
The formulation predicts the values of output_vars using input_vars according to xgboost_regressor.
- Parameters:
scip_model (PySCIPOpt Model) – The pyscipopt Model where the predictor should be inserted.
xgboost_regressor (
xgboost.XGBRFRegressor) – 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:
XGBoostRegressorConstr
Note
See
add_predictor_constrfor acceptable values for input_vars and output_vars- Raises:
NoModel – If the booster is not of type “gbtree”.
- pyscipopt_ml.xgboost.add_xgbclassifier_rf_constr(scip_model, xgboost_classifier, input_vars, output_vars=None, unique_naming_prefix='', epsilon=0.0, **kwargs)
Formulate xgboost_classifier (random forest) as constraints into a pyscipopt Model.
The formulation predicts the values of output_vars using input_vars according to xgboost_classifier.
- Parameters:
scip_model (PySCIPOpt Model) – The pyscipopt Model where the predictor should be inserted.
xgboost_classifier (
xgboost.XGBClassifier) – The gradient boosting classifier 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_classifier.
- Return type:
XGBoostClassifierConstr
Note
See
add_predictor_constrfor acceptable values for input_vars and output_vars- Raises:
NoModel – If the booster is not of type “gbtree”.
- class pyscipopt_ml.xgboost.xgboost_constr.XGBoostConstr(scip_model, predictor, input_vars, output_vars, unique_naming_prefix='', epsilon=0.0, aggr='sum', classification=False, **kwargs)
Class to model trained
xgboost.XGBRegressororxgboost.XGBClassifierwith constraints in a pyscipopt Model.Stores the changes to the SCIP Model for representing an instance into it. Inherits from
AbstractPredictorConstr.
- class pyscipopt_ml.xgboost.xgbgetter.XGBgetter(predictor, input_vars, output_type='regular', **kwargs)
Utility class for xgboost models convertors.
Implement some common functionalities: check predictor is fitted, output dimension, get error
- predictor
Xgboost predictor embedded into SCIP model.
- extract_raw_data_and_create_tree_vars(epsilon=0.0)
Function for extracting information from xgb.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
constant (float) – A constant value that is added to all regression output of the decision trees
tree_vars (np.ndarray) – A numpy array filled with variables that represent output of trees from the trained XGBoost 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).