Title: | Evaluation of Binary Classifiers |
---|---|
Description: | Evaluates the performance of binary classifiers. Computes confusion measures (TP, TN, FP, FN), derived measures (TPR, FDR, accuracy, F1, DOR, ..), and area under the curve. Outputs are well suited for nested dataframes. |
Authors: | Antoine Bichat [aut, cre] |
Maintainer: | Antoine Bichat <[email protected]> |
License: | GPL-3 |
Version: | 0.1.1 |
Built: | 2024-11-08 02:45:43 UTC |
Source: | https://github.com/abichat/evabic |
Add names to a vector, with default names.
add_names(x, names = NULL, prefix = "x")
add_names(x, names = NULL, prefix = "x")
x |
A vector. |
names |
Vector of names to add. If |
prefix |
The prefix to add before default names. Useful only if
|
A named vector
add_names(month.name)
add_names(month.name)
Available measures in evabic
ebc_allmeasures
ebc_allmeasures
An object of class character
of length 18.
True Positive
False Positive
False Negative
True Negative
True Positive Rate or Sensitivity or Recall or Power
True Negative Rate or Specificity
Positive Predictive Value or Precision
Negative Predictive Value
False Negative Rate or Type II Error Rate or Miss Rate
False Positive Rate or Type I Errors Rate or Fall-out
False Discovery Rate
False Omission Rate
Accuracy
Balanced Accuracy
F1 Score
Positive Likelihood Ratio or LR+ or Likelihood Ratio for Positive Results
Negative Likelihood Ratio or LR- or Likelihood Ratio for Negative Results
Diagnostic Odds Ratio
https://en.wikipedia.org/wiki/Evaluation_of_binary_classifiers
ebc_allmeasures
ebc_allmeasures
Compute the Area Under the Curve for a classification.
ebc_AUC( detection_values, true, all, m = length(all), direction = c("<", ">", "<=", ">=") ) ebc_AUC_from_measures(df_measures)
ebc_AUC( detection_values, true, all, m = length(all), direction = c("<", ">", "<=", ">=") ) ebc_AUC_from_measures(df_measures)
detection_values |
Values corresponding to elements that are detected. Must be named. |
true |
Vector of element that are supposed to be detected. |
all |
Vector of all elements. |
m |
Total number of elements. |
direction |
With |
df_measures |
A dataframe with |
A numeric.
set.seed(42) X1 <- rnorm(50) X2 <- rnorm(50) X3 <- rnorm(50) predictors <- paste0("X", 1:3) df_lm <- data.frame(X1 = X1, X2 = X2, X3 = X3, X4 = X1 + X2 + X3 + rnorm(50, sd = 0.5), X5 = X1 + 3 * X3 + rnorm(50, sd = 0.5), X6 = X2 - 2 * X3 + rnorm(50, sd = 0.5), X7 = X1 - X2 + rnorm(50, sd = 2), Y = X1 - X2 + 3 * X3 + rnorm(50)) model <- lm(Y ~ ., data = df_lm) pvalues <- summary(model)$coefficients[-1, 4] ebc_AUC(pvalues, predictors, m = 7) df_measures <- ebc_tidy_by_threshold(pvalues, predictors, m = 7) ebc_AUC_from_measures(df_measures)
set.seed(42) X1 <- rnorm(50) X2 <- rnorm(50) X3 <- rnorm(50) predictors <- paste0("X", 1:3) df_lm <- data.frame(X1 = X1, X2 = X2, X3 = X3, X4 = X1 + X2 + X3 + rnorm(50, sd = 0.5), X5 = X1 + 3 * X3 + rnorm(50, sd = 0.5), X6 = X2 - 2 * X3 + rnorm(50, sd = 0.5), X7 = X1 - X2 + rnorm(50, sd = 2), Y = X1 - X2 + 3 * X3 + rnorm(50)) model <- lm(Y ~ ., data = df_lm) pvalues <- summary(model)$coefficients[-1, 4] ebc_AUC(pvalues, predictors, m = 7) df_measures <- ebc_tidy_by_threshold(pvalues, predictors, m = 7) ebc_AUC_from_measures(df_measures)
Compute the the confusion matrix
ebc_confusion(detected, true, all, m = length(all), prop = FALSE)
ebc_confusion(detected, true, all, m = length(all), prop = FALSE)
detected |
Vector of elements that are detected. |
true |
Vector of element that are supposed to be detected. |
all |
Vector of all elements. |
m |
Total number of elements. |
prop |
Logical, default to |
See ebc_allmeasures
for the description of the measures.
A 2*2 named matrix.
ebc_confusion(detected = c("A", "C", "D"), true = c("A", "B", "C"), m = 6)
ebc_confusion(detected = c("A", "C", "D"), true = c("A", "B", "C"), m = 6)
Construct a single row summary of the classifier.
ebc_tidy( detected, true, all, m = length(all), measures = c("TPR", "FPR", "FDR", "ACC", "F1") )
ebc_tidy( detected, true, all, m = length(all), measures = c("TPR", "FPR", "FDR", "ACC", "F1") )
detected |
Vector of elements that are detected. |
true |
Vector of element that are supposed to be detected. |
all |
Vector of all elements. |
m |
Total number of elements. |
measures |
Desired measures of performance. |
See ebc_allmeasures
for the available measures and
their descriptions.
A single-row data.frame with one column per
element in measures
.
ebc_TP
, ebc_TPR
,
ebc_allmeasures
ebc_tidy(detected = c("A", "C", "D"), true = c("A", "B", "C"), all = LETTERS[1:6], measures = c("ACC", "FDR"))
ebc_tidy(detected = c("A", "C", "D"), true = c("A", "B", "C"), all = LETTERS[1:6], measures = c("ACC", "FDR"))
Computes measures according to a moving threshold.
ebc_tidy_by_threshold( detection_values, true, all, m = length(all), measures = c("TPR", "FPR", "FDR", "ACC", "F1"), direction = c("<", ">", "<=", ">=") )
ebc_tidy_by_threshold( detection_values, true, all, m = length(all), measures = c("TPR", "FPR", "FDR", "ACC", "F1"), direction = c("<", ">", "<=", ">=") )
detection_values |
Values corresponding to elements that are detected. Must be named. |
true |
Vector of element that are supposed to be detected. |
all |
Vector of all elements. |
m |
Total number of elements. |
measures |
Desired measures of performance. |
direction |
With |
See ebc_allmeasures
for the available measures and
their descriptions.
A dataframe with one column called threshold and other corresponding
to those specified in measures
.
set.seed(42) X1 <- rnorm(50) X2 <- rnorm(50) X3 <- rnorm(50) predictors <- paste0("X", 1:3) df_lm <- data.frame(X1 = X1, X2 = X2, X3 = X3, X4 = X1 + X2 + X3 + rnorm(50, sd = 0.5), X5 = X1 + 3 * X3 + rnorm(50, sd = 0.5), X6 = X2 - 2 * X3 + rnorm(50, sd = 0.5), X7 = X1 - X2 + rnorm(50, sd = 2), Y = X1 - X2 + 3 * X3 + rnorm(50)) model <- lm(Y ~ ., data = df_lm) pvalues <- summary(model)$coefficients[-1, 4] ebc_tidy_by_threshold(pvalues, predictors, m = 7)
set.seed(42) X1 <- rnorm(50) X2 <- rnorm(50) X3 <- rnorm(50) predictors <- paste0("X", 1:3) df_lm <- data.frame(X1 = X1, X2 = X2, X3 = X3, X4 = X1 + X2 + X3 + rnorm(50, sd = 0.5), X5 = X1 + 3 * X3 + rnorm(50, sd = 0.5), X6 = X2 - 2 * X3 + rnorm(50, sd = 0.5), X7 = X1 - X2 + rnorm(50, sd = 2), Y = X1 - X2 + 3 * X3 + rnorm(50)) model <- lm(Y ~ ., data = df_lm) pvalues <- summary(model)$coefficients[-1, 4] ebc_tidy_by_threshold(pvalues, predictors, m = 7)
Basic measures from the confusion matrix.
ebc_TP(detected, true) ebc_FP(detected, true) ebc_FN(detected, true) ebc_TN(detected, true, all, m = length(all))
ebc_TP(detected, true) ebc_FP(detected, true) ebc_FN(detected, true) ebc_TN(detected, true, all, m = length(all))
detected |
Vector of elements that are detected. |
true |
Vector of element that are supposed to be detected. |
all |
Vector of all elements. |
m |
Total number of elements. |
See ebc_allmeasures
for the description of the measures.
An integer.
ebc_TPR
, ebc_tidy
,
ebc_allmeasures
ebc_TP(detected = c("A", "C", "D"), true = c("A", "B", "C")) ebc_FP(detected = c("A", "C", "D"), true = c("A", "B", "C")) ebc_FN(detected = c("A", "C", "D"), true = c("A", "B", "C")) ebc_TN(detected = c("A", "C", "D"), true = c("A", "B", "C"), all = LETTERS[1:6]) ebc_TN(detected = c("A", "C", "D"), true = c("A", "B", "C"), m = 6)
ebc_TP(detected = c("A", "C", "D"), true = c("A", "B", "C")) ebc_FP(detected = c("A", "C", "D"), true = c("A", "B", "C")) ebc_FN(detected = c("A", "C", "D"), true = c("A", "B", "C")) ebc_TN(detected = c("A", "C", "D"), true = c("A", "B", "C"), all = LETTERS[1:6]) ebc_TN(detected = c("A", "C", "D"), true = c("A", "B", "C"), m = 6)
Measures derived from confusion matrix.
ebc_TPR(detected, true) ebc_TNR(detected, true, all, m = length(all)) ebc_PPV(detected, true) ebc_NPV(detected, true, all, m = length(all)) ebc_FNR(detected, true) ebc_FPR(detected, true, all, m = length(all)) ebc_FDR(detected, true) ebc_FOR(detected, true, all, m = length(all)) ebc_ACC(detected, true, all, m = length(all)) ebc_BACC(detected, true, all, m = length(all)) ebc_F1(detected, true) ebc_PLR(detected, true, all, m = length(all)) ebc_NLR(detected, true, all, m = length(all)) ebc_DOR(detected, true, all, m = length(all))
ebc_TPR(detected, true) ebc_TNR(detected, true, all, m = length(all)) ebc_PPV(detected, true) ebc_NPV(detected, true, all, m = length(all)) ebc_FNR(detected, true) ebc_FPR(detected, true, all, m = length(all)) ebc_FDR(detected, true) ebc_FOR(detected, true, all, m = length(all)) ebc_ACC(detected, true, all, m = length(all)) ebc_BACC(detected, true, all, m = length(all)) ebc_F1(detected, true) ebc_PLR(detected, true, all, m = length(all)) ebc_NLR(detected, true, all, m = length(all)) ebc_DOR(detected, true, all, m = length(all))
detected |
Vector of elements that are detected. |
true |
Vector of element that are supposed to be detected. |
all |
Vector of all elements. |
m |
Total number of elements. |
See ebc_allmeasures
for the description of the measures.
A numeric.
ebc_TP
, ebc_tidy
,
ebc_allmeasures
ebc_TPR(detected = c("A", "C", "D"), true = c("A", "B", "C")) ebc_ACC(detected = c("A", "C", "D"), true = c("A", "B", "C"), all = LETTERS[1:5])
ebc_TPR(detected = c("A", "C", "D"), true = c("A", "B", "C")) ebc_ACC(detected = c("A", "C", "D"), true = c("A", "B", "C"), all = LETTERS[1:5])