backbone_learn.exact_solvers package
Submodules
backbone_learn.exact_solvers.benders_oct_decision_tree module
- class backbone_learn.exact_solvers.benders_oct_decision_tree.BendersOCTDecisionTree(depth=3, time_limit=1000, _lambda=0.5, num_threads=None, obj_mode='acc', n_bins=2, is_data_fit=False)[source]
Bases:
ExactSolverBaseImplements the BendersOCT model for Optimal Classification Trees.
- model
The BendersOCT model.
- Type
BendersOCT
- accuracy_score
The accuracy score of the trained model.
- Type
float
- est_X
The KBinsDiscretizer instance for discretizing features.
- Type
KBinsDiscretizer
- enc
The OneHotEncoder instance for encoding categorical variables.
- Type
OneHotEncoder
- fit(X, y) None[source]
Fits the BendersOCT model to the preprocessed data.
- Parameters
X (np.ndarray or pd.DataFrame) – The input features.
y (np.ndarray or pd.Series) – The target variable.
- fit_preprocessors(X_train)[source]
Fits preprocessors to the training data.
- Parameters
X_train (np.ndarray or pd.DataFrame) – The training features.
- property model
Returns the BendersOCT model instance.
backbone_learn.exact_solvers.exact_solver_base module
- class backbone_learn.exact_solvers.exact_solver_base.ExactSolverBase[source]
Bases:
ABCAbstract class for solving subproblems in various contexts.
This class provides a framework for defining solvers that can fit models to data and make predictions. Derived classes need to implement the fit and predict methods according to the specifics of the solver.
- abstract fit(X: ndarray, y: ndarray)[source]
Fits a model to the given data.
This method should be implemented to solve a subproblem using the input data matrix X and the target vector y. It should fit a model based on the specific algorithm implemented in the derived class.
- Parameters
X (np.ndarray) – The input feature matrix.
y (np.ndarray) – The target vector.
- Returns
The method should fit the model to the data, with the results stored internally within the class instance.
- Return type
None
- property model
This property should be implemented by subclasses to return the model instance used in the exact approach.
- abstract predict(X: ndarray) ndarray[source]
Makes predictions using the fitted model.
This method should be implemented to provide predictions based on the model fitted using the fit method. It should process the input feature matrix X and return predictions.
- Parameters
X (np.ndarray) – The input feature matrix for which predictions are to be made.
- Returns
An array of predictions made by the model.
- Return type
np.ndarray
backbone_learn.exact_solvers.lobnb_regression module
- class backbone_learn.exact_solvers.lobnb_regression.L0BnBRegression(lambda_2: float = 0.01, max_nonzeros: int = 10, time_limit: int = 1000)[source]
Bases:
ExactSolverBaseImplements a regression solver using the L0BnB method for feature selection.
This class is designed to provide an easy-to-use interface for the L0BnB regression model, allowing for fitting and predictions on datasets.
- model
An instance of the L0BnBRegressionModel class.
- Type
- fit(X: ndarray, y: ndarray) None[source]
Fits the L0BnB regression model to the provided data.
- Parameters
X (np.ndarray) – The feature matrix for the regression model.
y (np.ndarray) – The target values for the regression model.
- predict(X: ndarray) ndarray[source]
Generates predictions using the fitted L0BnB regression model.
This method delegates the prediction task to the predict method of the L0BnBRegressionModel instance. It requires the model to be already fitted.
- Parameters
X (np.ndarray) – The feature matrix for which predictions are to be made.
- Returns
Predicted values based on the fitted model.
- Return type
np.ndarray
backbone_learn.exact_solvers.lobnb_regression_model module
- class backbone_learn.exact_solvers.lobnb_regression_model.L0BnBRegressionModel(lambda_2: float, max_nonzeros: int, time_limit: int)[source]
Bases:
objectA wrapper class for the L0BnB regression model, facilitating model fitting and predictions.
This class serves as a convenient interface for the L0BnB feature selection method, specifically tailored for regression tasks. It stores the regression coefficients and intercept after fitting the model to the provided data.
- coefficients
Coefficients of the regression model. None before the model is fitted.
- Type
np.ndarray or None
- intercept
Intercept of the regression model. None before the model is fitted.
- Type
float or None
- lambda_2
Regularization parameter lambda_2 in the L0BnB model, controlling the trade-off between the model’s complexity and fit.
- Type
float
- max_nonzeros
Maximum number of non-zero coefficients the model is allowed to have, enforcing sparsity.
- Type
int
- fit(X: ndarray, y: ndarray) None[source]
Fits the L0BnB regression model to the given dataset.
The method uses the L0BnB algorithm to find a sparse set of coefficients that best fit the data.
- Parameters
X (np.ndarray) – The feature matrix for the regression model.
y (np.ndarray) – The target values for the regression model.
backbone_learn.exact_solvers.mio_clustering module
- class backbone_learn.exact_solvers.mio_clustering.MIOClustering(n_clusters: Optional[int] = None, time_limit: float = 1200, ls_pairs_diff_cluster: Optional[List[Tuple[int, int]]] = None, ls_pairs_same_cluster: Optional[List[Tuple[int, int]]] = None)[source]
Bases:
objectClass for solving clustering problems using Mixed-Integer Optimization.
- extract_cluster_means(X: ndarray) ndarray[source]
Extract cluster means after fitting the model.
- Parameters
X (np.ndarray) – The input feature matrix.
- Returns
An array of cluster means.
- Return type
np.ndarray