Logistic Regression Constraint

Module for formulating a sklearn.linear_model.LogisticRegression in a PySCIPOpt Model.

pyscipopt_ml.sklearn.add_logistic_regression_constr(scip_model, logistic_regression, input_vars, output_vars=None, unique_naming_prefix='', output_type='classification', **kwargs)

Formulate logistic_regression in a SCIP Model.

The formulation predicts the values of output_vars using input_vars according to logistic_regression.

Parameters:
  • scip_model (PySCIPOpt Model) – The PySCIPOpt model where the predictor will be inserted.

  • logistic_regression (sklearn.linear_model.LogisticRegression) – The logistic regression model to insert.

  • input_vars (:list or dict) – Decision variables used as input for logistic regression in model.

  • output_vars (list or dict) – Decision variables used as output for logistic regression 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.

  • output_type ({'classification', 'regression'}, default='classification') – If the option chosen is ‘classification’ the output is 1 for exactly one class and 0 for all others. If the option ‘regression’ is chosen the output is the probability of each class.

Returns:

Object containing information about what was added to scip_model to formulate logistic_regression.

Return type:

LogisticRegressionConstr

Raises:
  • NoModel – If the logistic regression is not a binary label regression

  • ParameterError – If the value of output_type is set to a non-conforming value (see above).

Warning

When there is a (near) tie for the most likely class, users should be aware that SCIP tolerances will allow either of the two classes to be selected. In a scenario where there are two classes, and the logistic regression model assigns probability of class 1 as 0.5000000001. Naturally this is larger than 0.4999999999 assigned to class 2, however from a numerics point of view in SCIP both can be selected.

Note

See add_predictor_constr for acceptable values for input_vars and output_vars

class pyscipopt_ml.sklearn.logistic_regression.LogisticRegressionConstr(scip_model, predictor, input_vars, output_vars=None, unique_naming_prefix='', output_type='classification', **kwargs)

Class to model trained sklearn.linear_model.LogisticRegression with SCIP

Stores the changes to the SCIP Model for representing an instance into it. Inherits from AbstractPredictorConstr..