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

## 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(...)

Arguments

actual

A vector of <factor>- of length \(n\), and \(k\) levels.

response

A <numeric>-vector of length \(n\). The estimated response probabilities.

thresholds

An optional <numeric>-vector of non-zero length (default: NULL).

Arguments passed into other methods.

w

A <numeric>-vector of length \(n\). NULL by default.

Value

A data.frame on the following form,

threshold

<numeric> Thresholds used to determine recall() and precision()

level

<character> The level of the actual <factor>

label

<character> The levels of the actual <factor>

recall

<numeric> The recall

precision

<numeric> The precision

Examples

# 1) recode Iris
# to binary classification
# problem
iris$species_num <- as.numeric(
  iris$Species == "virginica"
)

# 2) fit the logistic
# regression
model <- glm(
  formula = species_num ~ Sepal.Length + Sepal.Width,
  data    = iris,
  family  = binomial(
    link = "logit"
  )
)

# 3) generate predicted
# classes
response <- predict(model, type = "response")

# 3.1) generate actual
# classes
actual <- factor(
  x = iris$species_num,
  levels = c(1,0),
  labels = c("Virginica", "Others")
)



# 4) generate reciever
# operator characteristics
roc <- prROC(
  actual   = actual,
  response = response
)


# 5) plot by species
plot(roc)

# 5.1) summarise
summary(roc)

# 6) provide custom
# threholds
roc <- prROC(
  actual     = actual,
  response   = response,
  thresholds = seq(0, 1, length.out = 4)
)


# 5) plot by species
plot(roc)