Predict method for svmodt_node objects

# S3 method for class 'svmodt_node'
predict(object, newdata, return_probs = FALSE, calibrate_probs = TRUE, ...)

Arguments

object

An object of class svmodt_node.

newdata

A data frame of new predictor values.

return_probs

Logical; if TRUE, returns predictions and probabilities.

calibrate_probs

Logical; if TRUE, uses logistic calibration on decision values.

...

Currently unused.

Value

If return_probs = FALSE (the default), a character vector of predicted class labels, one element per row of newdata.

If return_probs = TRUE, a named list with two elements:

predictions

Character vector of predicted class labels (length = nrow(newdata)).

probabilities

Numeric matrix of class probabilities with nrow(newdata) rows and one column per class. Column names are the class labels; each row sums to 1. When calibrate_probs = TRUE, probabilities are derived from the SVM decision value via logistic calibration; otherwise empirical class frequencies at the leaf node are used.

Examples

# \donttest{
# Train DTSVM tree
tree <- svm_split(
  data = wdbc,
  response = "diagnosis",
  max_depth = 3,
  max_features = 2,
  feature_method = "cor"
)

# Predict on WDBC data (returns a character vector of class labels)
preds <- predict(tree, newdata = wdbc)

# Predict with probabilities and logistic calibration
result <- predict(tree, newdata = wdbc,
  return_probs = TRUE, calibrate_probs = TRUE
)
head(result$predictions)
#> [1] "M" "M" "M" "M" "M" "M"
head(result$probabilities)
#>               B         M
#> [1,] 0.02538071 0.9746193
#> [2,] 0.02538071 0.9746193
#> [3,] 0.02538071 0.9746193
#> [4,] 0.02538071 0.9746193
#> [5,] 0.02538071 0.9746193
#> [6,] 0.02538071 0.9746193
# }