robustx.lib.models package

Subpackages

Submodules

robustx.lib.models.BaseModel module

class robustx.lib.models.BaseModel.BaseModel(model)[source]

Bases: ABC

Abstract base class to define the essential methods that all model types must implement, providing template for training, predicting, and evaluating models in a standardized way.

_model

The underlying model object (e.g., a scikit-learn model or a PyTorch model) that this class wraps.

Type:

object

train(X: pd.DataFrame, y: pd.DataFrame) None:[source]

Trains the model using the provided feature and target data.

predict(X: pd.DataFrame) pd.DataFrame:[source]

Predicts the outcomes for the given instances.

predict_single(X: pd.DataFrame) int:[source]

Predicts the outcome for a single instance and returns an integer.

predict_proba(X: pd.DataFrame) pd.DataFrame:[source]

Predicts the probabilities of outcomes for the given instances.

predict_proba_tensor(X: torch.Tensor) torch.Tensor:[source]

Predicts the probabilities of outcomes for tensor inputs.

evaluate(X: pd.DataFrame, y: pd.DataFrame):

Evaluates the model’s performance on the provided feature and target data.

Properties()
----------
model:

Returns the underlying model object.

abstract evaluate(X, y)[source]

Evaluates the model’s performance on the provided feature and target data.

@param X: pd.DataFrame, The feature variables. @param y: pd.DataFrame, The target variable.

@return: Evaluation result of the model.

property model

Returns the underlying model object.

@return: The model object.

abstract predict(X)[source]

Uses the model to predict the outcomes for any number of instances.

@param X: pd.DataFrame, Instances to predict.

@return: pd.DataFrame, Predictions for each instance.

Return type:

DataFrame

abstract predict_proba(X)[source]

Predicts the probabilities of outcomes.

@param X: pd.DataFrame, Instances to predict.

@return: pd.DataFrame, Probabilities of each outcome.

Return type:

DataFrame

abstract predict_proba_tensor(X)[source]

Predicts the probabilities of outcomes for tensor inputs.

@param X: torch.Tensor, Instances to predict.

@return: torch.Tensor, Probabilities of each outcome.

Return type:

Tensor

abstract predict_single(X)[source]

Predicts the outcome of a single instance and returns an integer.

@param X: pd.DataFrame, Instance to predict.

@return: int, Prediction as an integer.

Return type:

int

abstract train(X, y, **kwargs)[source]

Trains the model using X feature variables and y target variable. Each implementing class can decide how to train their model and can add additional parameters, but X and y must be of type DataFrame.

@param X: pd.DataFrame, The feature variables. @param y: pd.DataFrame, The target variable.

@return: None

Return type:

None

robustx.lib.models.Models module

robustx.lib.models.Models.get_sklearn_model(name)[source]

Retrieves an instance of a scikit-learn model based on the provided name.

@param name: The name of the desired model. Options are:
  • “log_reg” for Logistic Regression

  • “decision_tree” for Decision Tree

  • “svm” for Support Vector Machine

@return: An instance of the requested scikit-learn model. The model class should be a subclass of BaseModel.

@raises ValueError: If the provided model name does not match any of the predefined options.

Module contents