The binaryClass package provides a comprehensive toolkit for binary classification tasks in R. It implements powerful functions for model training, evaluation, and prediction, with a focus on comparing different classification approaches.
# Install the released version from GitHub
install.packages("https://codoom1.github.io/binaryClass/binaryClass_1.0.0.tar.gz", repos = NULL)# Install development version
remotes::install_github("codoom1/binaryClass")-
OptimalModelSearch: Automatically compares multiple binary classification models and selects the best model based on AUC, Accuracy, or AIC. Models compared include:
- Full Logistic Regression
- Backward Stepwise Selection
- Forward Stepwise Selection
- GAM (Generalized Additive Model)
- Lasso Regression
- Ridge Regression
-
Visualization Options:
- ROC Curves: For AUC criterion - visualize model discrimination ability
- Automatic plotting with
OptimalModelSearch(..., criterion="AUC", plot_roc=TRUE) - Comparison plotting with
plot_model_rocs()
- Automatic plotting with
- Confusion Matrices: For Accuracy criterion - visualize classification performance
- Automatic plotting with
OptimalModelSearch(..., criterion="Accuracy", plot_cm=TRUE) - Manual plotting with
plot_model_cm()
- Automatic plotting with
- ROC Curves: For AUC criterion - visualize model discrimination ability
-
Additional Tools:
compare_model_rocs: Standalone function to compare ROC curves for stepwise, lasso, and ridge modelsplot_descrip: Create descriptive visualizations for binary classification datasets
# Load example data
library(binaryClass)
library(mlbench)
data(PimaIndiansDiabetes)
df <- PimaIndiansDiabetes
df$diabetes <- ifelse(df$diabetes=="neg", 0, 1)
# Find best model using AUC criterion with ROC curve
result_auc <- OptimalModelSearch(formula=diabetes~., data=df,
criterion="AUC", plot_roc=TRUE,
suppress_warnings=TRUE)
# Find best model using Accuracy criterion with confusion matrix
result_acc <- OptimalModelSearch(formula=diabetes~., data=df,
criterion="Accuracy", plot_cm=TRUE)
# Find best model using AIC criterion
result_aic <- OptimalModelSearch(formula=diabetes~., data=df,
criterion="AIC")# Get the best model from results
best_model <- extract_best_model(result_auc)
# Use it for predictions on new data
new_pred <- predict(best_model, newdata=new_data)# ROC curves for AUC criterion
plot_model_rocs(result_auc, comparison=TRUE)
# Confusion matrix for Accuracy criterion
plot_model_cm(result_acc)
# Standalone ROC curve comparison
compare_model_rocs(formula=diabetes~., data=df)statsMASSgamglmnetpROCcarete1071graphicsgrDevices
This package is licensed under the MIT License.
Contributions to improve binaryClass are welcome. Please feel free to submit a pull request or open an issue on GitHub.