ColumnTransformerConstr#
- class gurobi_ml.sklearn.column_transformer.ColumnTransformerConstr(gp_model, column_transformer, input_vars, **kwargs)#
Bases:
SKtransformer
Class to formulate a fitted
sklearn.compose.ColumnTransformer
in a gurobipy model.Notes
This object differs from all the other object in the Gurobi Machine Learning package in that it may not be possible to write all of its input with Gurobi variables. Specifically some input may consist of categorical features to be encoded using the column transformer.
Then such input cannot be directly represented in Gurobi but the result of the encoding may be represented. If the categorical features are fixed for the optimization model, we can use it so it is allowed by the ColumnTransormerConstr class.
The rule we use to apply the ColumnTransformer to the input is that if the set of columns to which a preprocessing transformation is constant in the input we use directly the scikit learn preprocessing object. It at least one of the columns is made of gurobipy variables, we use the gurobi-ml object (if it exists).
- 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
Input variables of embedded predictor.
input_values
Values for the input variables if a solution is known.
output
Output variables of embedded predictor.
output_values
Values for the output variables if a solution is known.
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 preprocessing from input.
is_passthrough
(trans)Check if transformation is passthrough
print_stats
([abbrev, 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 preprocessing 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 transformer.transform(x) and y. Where transformer is the prepocessing 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).
- static is_passthrough(trans)#
Check if transformation is passthrough
Before scikilearn 1.4 was the string passthrough, after it is a function transformer object with None function.
- print_stats(abbrev=False, 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.
Usually derived classes reimplement this function to provide more details about the structure of the additions (type of ML model, layers if it’s a neural network,…)
- 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#
Input variables of embedded predictor.
- Returns:
output
- Return type:
- property input_values#
Values for the input variables if a solution is known.
- Returns:
output_value
- Return type:
ndarray or pandas dataframe with values
- Raises:
NoSolution – If the Gurobi model has no solution (either was not optimized or is infeasible).
- property output#
Output variables of embedded predictor.
- Returns:
output
- Return type:
- property output_values#
Values for the output variables if a solution is known.
- Returns:
output_value
- Return type:
ndarray or pandas dataframe with values
- Raises:
NoSolution – If the Gurobi model has no solution (either was not optimized or is infeasible).
- property qconstrs#
List of quadratic constraints added.
- property sos#
List of SOS constraints added.
- property vars#
List of variables added.