Skip to contents

Create a unified classifier object that wraps various ML algorithms

Usage

create_classifier(
  type = "LR",
  penalty = "l1",
  alpha = NULL,
  lambda = NULL,
  n_trees = 500,
  max_depth = NULL,
  kernel = "radial",
  seed = NULL,
  ...
)

Arguments

type

Classifier type: "LR", "RF", "SVM", "NB", "DT", "XGB", "RANGER"

penalty

For LR: "l1" (lasso), "l2" (ridge), or "elasticnet"

alpha

For LR: elasticnet mixing parameter (1=lasso, 0=ridge). Default: 1 for L1

lambda

For LR: regularization strength (smaller = more regularization). If NULL, uses cross-validation to select

n_trees

For RF/RANGER/XGB: number of trees

max_depth

For DT/XGB: maximum tree depth

kernel

For SVM: kernel type ("linear", "radial", "polynomial")

seed

Random seed for reproducibility

...

Additional arguments passed to the underlying classifier

Value

A classifier object with fit, predict, and predict_prob methods

Details

The returned classifier object has the following methods:

$fit(X, y)

Train the classifier on data

$predict(X)

Get class predictions

$predict_prob(X)

Get class probabilities

$get_coefficients()

Get model coefficients (for LR)

$get_importance()

Get feature importance (for tree-based)

Examples

if (FALSE) { # \dontrun{
# Create a logistic regression classifier
clf <- create_classifier("LR", penalty = "l1")

# Train
clf$fit(X_train, y_train)

# Predict
predictions <- clf$predict(X_test)
probabilities <- clf$predict_prob(X_test)
} # }