R/svmodt_predict_tree.R
svm_predict_tree.RdPredicts class labels or class probabilities for new data using a tree constructed with SVM splits. Handles leaf nodes, internal nodes, recursive traversal, and fallback mechanisms when SVM predictions or scaling fail.
svm_predict_tree(tree, newdata, return_probs = FALSE, calibrate_probs = TRUE)A tree node object (leaf or internal) created by svm_split or svm_split_enhanced.
A data frame of new predictor values. **Must contain the same features** as those used to fit the tree. Any additional columns (including responses) are ignored.
Logical; if TRUE, returns both predicted class labels and class probabilities.
Logical; if TRUE, converts SVM decision values to probabilities using logistic
calibration (sigmoid) based on the distance from the hyperplane. If FALSE, fallback probabilities
are computed from class frequencies at the leaf node.
If return_probs = FALSE, a character vector of predicted class labels.
If return_probs = TRUE, a list with elements:
predictions: Character vector of predicted class labels.
probabilities: Numeric matrix of class probabilities
(rows = samples, columns = classes).
The function traverses the SVM-based oblique decision tree recursively and predicts class labels or probabilities. Key behaviors:
Leaf nodes: Return the majority class stored in the node, along with class probabilities.
Internal nodes:
Scale features according to the node's scaling parameters.
Compute SVM decision values.
Recursively traverse left and right children depending on the sign of the decision value.
Binary support:
Binary SVMs produce a single decision value per node.
Fallback predictions: If scaling fails, SVM predictions are unavailable, or child nodes are missing, predictions are generated in this order:
SVM-provided probabilities (if available).
Calibrated decision values using a logistic/sigmoid function (if calibrate_probs = TRUE).
Leaf node class distribution (empirical frequencies) or uniform probabilities as a last resort.
Probability normalization: All returned probabilities are normalized so that each row sums to 1.
Feature requirement: newdata must contain exactly the features used to train the tree; any extra columns, including responses, are ignored.
Calibration behavior:
calibrate_probs = FALSE returns class frequencies at the leaf node.
calibrate_probs = TRUE uses the distance from the hyperplane for logistic post-processing into probabilities.