rocelib.models.pytorch_models package
Submodules
rocelib.models.pytorch_models.TrainableCustomPyTorchModel module
- class rocelib.models.pytorch_models.TrainableCustomPyTorchModel.TrainableCustomPyTorchModel(model, criterion=CrossEntropyLoss(), optimizer_class=<class 'torch.optim.adam.Adam'>, learning_rate=0.001)[source]
Bases:
TrainableModelA custom PyTorch model that can be trained, used for predictions, and evaluated for performance.
- model
The PyTorch model architecture.
- Type:
nn.Module
- criterion
The loss function used for training.
- Type:
nn.CrossEntropyLoss
- optimizer
The optimizer used for training the model.
- Type:
optim.Adam
- train(X: pd.DataFrame, y: pd.DataFrame, epochs: int = 10, batch_size: int = 32) None:[source]
Trains the model on the provided data for a specified number of epochs and batch size.
- predict(X: pd.DataFrame) pd.DataFrame:
Predicts outcomes for multiple instances of the provided feature data.
- predict_single(X: pd.DataFrame) int:
Predicts the outcome for a single instance of the provided feature data.
- predict_proba(X: pd.DataFrame) pd.DataFrame:
Predicts the probability of each outcome for multiple instances.
- evaluate(X: pd.DataFrame, y: pd.DataFrame) float:
Evaluates the model’s accuracy on the provided feature and target data.
- train(X, y, epochs=10, batch_size=32, **kwargs)[source]
Train the PyTorch model using the provided data.
@param dataset_loader: Feature and target variables as a DatasetLoader @param epochs: Number of training epochs, default is 10. @param batch_size: Size of each mini-batch, default is 32.
- Return type:
TrainedModel
rocelib.models.pytorch_models.TrainablePyTorchModel module
- class rocelib.models.pytorch_models.TrainablePyTorchModel.TrainablePyTorchModel(input_dim, hidden_dim, output_dim)[source]
Bases:
TrainableModelA simple neural network model using PyTorch. This model can be customized with different numbers of hidden layers and units.
- input_dim
The number of input features for the model.
- Type:
int
The number of units in each hidden layer. An empty list means no hidden layers.
- Type:
list of int
- output_dim
The number of output units for the model.
- Type:
int
- criterion
The loss function used for training.
- Type:
nn.BCELoss
- optimizer
The optimizer used for training the model.
- Type:
optim.Adam
- __create_model() nn.Sequential:
Creates and returns the PyTorch model architecture.
- train(X: pd.DataFrame, y: pd.DataFrame, epochs: int = 100) None:[source]
Trains the model on the provided data for a specified number of epochs.
- predict(X: pd.DataFrame) pd.DataFrame:
Predicts the outcomes for the provided instances.
- predict_single(x: pd.DataFrame) int:
Predicts the outcome of a single instance and returns an integer.
- evaluate(X: pd.DataFrame, y: pd.DataFrame) float:
Evaluates the model’s accuracy on the provided data.
- predict_proba(x: torch.Tensor) pd.DataFrame:
Predicts the probability of outcomes for the provided instances.
- predict_proba_tensor(x: torch.Tensor) torch.Tensor:
Predicts the probability of outcomes for the provided instances using tensor input.