## S3 method for class 'factor'
prROC(actual, response, thresholds = NULL, ...)
## S3 method for class 'factor'
weighted.prROC(actual, response, w, thresholds = NULL, ...)
prROC(...)
weighted.prROC(...)
Precision-Recall curve
prROC.factor | R Documentation |
Description
The prROC()
-function computes the precision()
and recall()
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
|
|
recall
|
|
precision
|
|
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
<- prROC(
roc actual = actual,
response = response
)
# 5) plot by species
plot(roc)
# 5.1) summarise
summary(roc)
# 6) provide custom
# threholds
<- prROC(
roc actual = actual,
response = response,
thresholds = seq(0, 1, length.out = 4)
)
# 5) plot by species
plot(roc)