ROC (Receiver Operating Characteristic) curve data from a classification forest.
Source:R/gg_roc.R
gg_roc.rfsrc.RdComputes sensitivity (true positive rate) and specificity (1 - false positive
rate) across all prediction thresholds for one class of a classification
rfsrc or
randomForest object.
Arguments
- object
A classification
rfsrcorrandomForestobject. Only forests withfamily == "class"(rfsrc) ortype == "classification"(randomForest) are supported.- which_outcome
Integer index or character name of the class for which the ROC curve is computed. For binary forests this is typically
1or2; for multi-class forests any valid class index. Usewhich_outcome = 0to obtain the overall (averaged) ROC.- oob
Logical; if
TRUE(default) use out-of-bag predicted probabilities for the curve. Set toFALSEto use full in-bag predictions.- ...
Extra arguments (currently unused).
Value
A gg_roc data.frame with one row per unique prediction
threshold and columns:
- sens
Sensitivity (true positive rate) at each threshold.
- spec
Specificity (true negative rate) at each threshold.
- yvar
The observed class label for each observation.
Pass to calc_auc for the area under the curve.
Examples
## ------------------------------------------------------------
## classification example
## ------------------------------------------------------------
## -------- iris data
rfsrc_iris <- rfsrc(Species ~ ., data = iris)
# ROC for setosa
gg_dta <- gg_roc(rfsrc_iris, which_outcome = 1)
plot(gg_dta)
# ROC for versicolor
gg_dta <- gg_roc(rfsrc_iris, which_outcome = 2)
plot(gg_dta)
# ROC for virginica
gg_dta <- gg_roc(rfsrc_iris, which_outcome = 3)
plot(gg_dta)
## -------- iris data
rf_iris <- randomForest::randomForest(Species ~ ., data = iris)
# ROC for setosa
gg_dta <- gg_roc(rf_iris, which_outcome = 1)
plot(gg_dta)
# ROC for versicolor
gg_dta <- gg_roc(rf_iris, which_outcome = 2)
plot(gg_dta)
# ROC for virginica
gg_dta <- gg_roc(rf_iris, which_outcome = 3)
plot(gg_dta)