## S3 method for class 'factor'
ROC(actual, response, thresholds = NULL, ...)
## S3 method for class 'factor'
weighted.ROC(actual, response, w, thresholds = NULL, ...)
ROC(...)
weighted.ROC(...)
receiver operator characteristics
ROC.factor | R Documentation |
Description
The ROC()
-function computes the tpr()
and fpr()
at thresholds provided by the \(response\)- or \(thresholds\)-vector. The function constructs a data.frame()
grouped by \(k\)-classes where each class is treated as a binary classification problem.
Usage
Arguments
actual
|
A vector of |
response
|
A |
thresholds
|
An optional |
…
|
Arguments passed into other methods. |
w
|
A |
Value
A data.frame on the following form,
threshold
|
|
level
|
|
label
|
|
fpr
|
|
tpr
|
|
Examples
# 1) recode Iris
# to binary classification
# problem
$species_num <- as.numeric(
iris$Species == "virginica"
iris
)
# 2) fit the logistic
# regression
<- glm(
model formula = species_num ~ Sepal.Length + Sepal.Width,
data = iris,
family = binomial(
link = "logit"
)
)
# 3) generate predicted
# classes
<-predict(model, type = "response")
response
# 3.1) generate actual
# classes
<- factor(
actual x = iris$species_num,
levels = c(1,0),
labels = c("Virginica", "Others")
)
# 4) generate reciever
# operator characteristics
<- ROC(
roc actual = actual,
response = response
)
# 5) plot by species
plot(roc)
# 5.1) summarise
summary(roc)
# 6) provide custom
# threholds
<- ROC(
roc actual = actual,
response = response,
thresholds = seq(0, 1, length.out = 4)
)
# 5) plot by species
plot(roc)