PipelineConstr#

class gurobi_ml.sklearn.pipeline.PipelineConstr(gp_model, pipeline, input_vars, output_vars=None, **kwargs)#

Bases: SKgetter, AbstractPredictorConstr

Class to formulate a trained sklearn.pipeline.Pipeline in a gurobipy model.

Stores the changes to gurobipy model for formulating the predictor.

Attributes:
constrs

List of linear constraints added.

default_name

Default base name base used for automatic name generation.

genconstrs

List of general constraints added.

gp_model

Access gurobipy model this is a part of.

input

Returns input variables of pipeline, i.e.

input_values

Returns input values of pipeline in solution, i.e.

output

Returns output variables of pipeline, i.e.

output_values

Returns output values of pipeline in solution, i.e.

qconstrs

List of quadratic constraints added.

sos

List of SOS constraints added.

vars

List of variables added.

Methods

get_error([eps])

Return error in Gurobi's solution with respect to prediction from input.

print_stats([file])

Print statistics on model additions stored by this class.

remove()

Remove from gp_model everything that was added to embed predictor.

get_error(eps=None)#

Return error in Gurobi’s solution with respect to prediction from input.

Returns:

error – Assuming that we have a solution for the input and output variables x, y. Returns the absolute value of the differences between predictor.predict(x) and y. Where predictor is the regression this object is modeling.

Return type:

ndarray of same shape as gurobi_ml.modeling.base_predictor_constr.AbstractPredictorConstr.output

Raises:

NoSolution – If the Gurobi model has no solution (either was not optimized or is infeasible).

print_stats(file=None)#

Print statistics on model additions stored by this class.

This function prints detailed statistics on the variables and constraints that where added to the model.

The pipeline version includes a summary of the steps that it contains.

Parameters:

file (None, optional) – Text stream to which output should be redirected. By default sys.stdout.

remove()#

Remove from gp_model everything that was added to embed predictor.

property constrs#

List of linear constraints added.

property default_name#

Default base name base used for automatic name generation.

property genconstrs#

List of general constraints added.

property gp_model#

Access gurobipy model this is a part of.

property input#

Returns input variables of pipeline, i.e. input of its first step.

property input_values#

Returns input values of pipeline in solution, i.e. input of its first step.

property output#

Returns output variables of pipeline, i.e. output of its last step.

property output_values#

Returns output values of pipeline in solution, i.e. output of its last step.

property qconstrs#

List of quadratic constraints added.

property sos#

List of SOS constraints added.

property vars#

List of variables added.