A wrapper for integrating the B-cell Hybrid Immune Variant Engine
(bHIVE) algorithm with the caret package. Supports both classification
and regression tasks, providing compatibility with caret::train()
for model training and validation.
Details
The bHIVEmodel wrapper facilitates the use of bHIVE for classification
and regression. It defines the model label, parameter grid, fitting function,
and prediction methods to conform to the caret model specification.
Components
labelCharacter string. Identifies the model as "B-cell-based Hybrid Immune Virtual Evolution".
libraryCharacter string. Specifies the R package containing the bHIVE implementation. Default is "customPackage".
typeCharacter vector. Specifies the supported tasks: "Classification" and "Regression".
parametersA
data.framedescribing the tunable parameters:parameter: Name of the parameter.class: Data type of the parameter ("numeric").label: Short description of the parameter.
gridFunction. Generates a grid of tuning parameters for hyperparameter optimization.
fitFunction. Trains the bHIVE model using specified hyperparameters and task type.
predictFunction. Generates predictions for new data (classification labels or regression values).
probFunction. Calculates class probabilities for classification tasks.
Parameters
nAntibodiesNumber of initial antibodies in the bHIVE algorithm.
betaClone multiplier. Controls the number of clones generated for top-matching antibodies.
epsilonSimilarity threshold for antibody suppression. Smaller values encourage more diversity in the repertoire.
Functions
grid(x, y, len): Generates a grid of tuning parameters. Accepts:x: Feature matrix or data frame.y: Target vector (factor for classification, numeric for regression).len: Number of grid points for each parameter.
fit(x, y, wts, param, lev, last, classProbs, ...): Trains the bHIVE model. Key arguments:x: Feature matrix or data frame.y: Target vector.param: List of hyperparameters (nAntibodies,beta,epsilon)....: Additional arguments passed to the bHIVE function.
predict(modelFit, newdata, submodels): Generates predictions for new data.modelFit: Trained bHIVE model.newdata: New feature data for prediction.
prob(modelFit, newdata, submodels): Calculates class probabilities (classification only).
Example Usage
library(caret)
# Simulated classification dataset
set.seed(123)
X <- matrix(rnorm(100 * 5), ncol = 5)
y <- factor(sample(c("Class1", "Class2"), 100, replace = TRUE))
# Train bHIVE model using caret
trainControl <- trainControl(method = "cv", number = 5, classProbs = TRUE)
tunedModel <- train(
x = X,
y = y,
method = bHIVEmodel,
trControl = trainControl,
tuneLength = 3
)
# Predictions
predictions <- predict(tunedModel, newdata = X)
probabilities <- predict(tunedModel, newdata = X, type = "prob")