| Title: | Machine Learning Performance Evaluation on Steroids |
|---|---|
| Description: | Performance evaluation metrics for supervised and unsupervised machine learning, statistical learning and artificial intelligence applications. Core computations are implemented in 'C++' for scalability and efficiency. |
| Authors: | Serkan Korkmaz [cre, aut, cph] (ORCID: <https://orcid.org/0000-0002-5052-0982>) |
| Maintainer: | Serkan Korkmaz <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 0.3-4 |
| Built: | 2026-06-04 06:59:17 UTC |
| Source: | https://github.com/serkor1/SLmetrics |
A generic S3 function to compute the accuracy score for a classification model. This function dispatches to S3 methods in accuracy() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because accuracy() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap accuracy() in a "safe" validator that checks for NA values and matching length, for example:
safe_accuracy <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
accuracy(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate accuracy ## via S3 dispatching accuracy(confusion_matrix) ## additional performance metrics ## below
The accuracy.factor() method calls cmatrix() internally, so explicitly invoking accuracy.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## Generic S3 method ## for Accuracy accuracy(...) ## Generic S3 method ## for weighted Accuracy weighted.accuracy(...)## Generic S3 method ## for Accuracy accuracy(...) ## Generic S3 method ## for weighted Accuracy weighted.accuracy(...)
... |
Arguments passed on to |
A <double>-value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::accuracy( actual = actual_classes, predicted = predicted_classes )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::accuracy( actual = actual_classes, predicted = predicted_classes )
A generic S3 function to compute the accuracy score for a classification model. This function dispatches to S3 methods in accuracy() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because accuracy() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap accuracy() in a "safe" validator that checks for NA values and matching length, for example:
safe_accuracy <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
accuracy(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate accuracy ## via S3 dispatching accuracy(confusion_matrix) ## additional performance metrics ## below
The accuracy.factor() method calls cmatrix() internally, so explicitly invoking accuracy.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## S3 method for class 'cmatrix' accuracy(x, ...)## S3 method for class 'cmatrix' accuracy(x, ...)
x |
A confusion matrix created |
... |
Arguments passed into other methods. |
A <double>-value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Construct confusion ## matrix confusion_matrix <- SLmetrics::cmatrix( actual = actual_classes, predicted = predicted_classes ) ## Evaluate performance SLmetrics::accuracy(confusion_matrix)## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Construct confusion ## matrix confusion_matrix <- SLmetrics::cmatrix( actual = actual_classes, predicted = predicted_classes ) ## Evaluate performance SLmetrics::accuracy(confusion_matrix)
A generic S3 function to compute the accuracy score for a classification model. This function dispatches to S3 methods in accuracy() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because accuracy() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap accuracy() in a "safe" validator that checks for NA values and matching length, for example:
safe_accuracy <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
accuracy(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate accuracy ## via S3 dispatching accuracy(confusion_matrix) ## additional performance metrics ## below
The accuracy.factor() method calls cmatrix() internally, so explicitly invoking accuracy.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## S3 method for class 'factor' accuracy(actual, predicted, ...)## S3 method for class 'factor' accuracy(actual, predicted, ...)
actual, predicted
|
A pair of <integer> or <factor> vectors of length |
... |
Arguments passed into other methods. |
A <double>-value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::accuracy( actual = actual_classes, predicted = predicted_classes )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::accuracy( actual = actual_classes, predicted = predicted_classes )
A generic S3 function to compute the area under the precision recall curve score for a classification model. This function dispatches to S3 methods in auc.pr.curve() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because auc.pr.curve() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap auc.pr.curve() in a "safe" validator that checks for NA values and matching length, for example:
safe_auc.pr.curve <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
auc.pr.curve(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
Use pr.curve() to construct the data.frame and use plot to visualize the area under the curve.
To avoid sorting the same probability matrix multiple times (once per class or curve), you can precompute a single set of sort indices and pass it via the indices argument. This reduces the overall cost from O(K·N log N) to O(N log N + K·N).
## presort response ## probabilities indices <- preorder(response, decreasing = TRUE) ## evaluate area under the precision recall curve auc.pr.curve(actual, response, indices = indices)
## Generic S3 method ## for Area under the Precision Recall Curve auc.pr.curve(...) ## Generic S3 method for ## unweighted area under the ## Precision Recall Curve auc.pr.curve(...) ## Generic S3 method ## for weighted Area under the Precision Recall Curve weighted.auc.pr.curve(...)## Generic S3 method ## for Area under the Precision Recall Curve auc.pr.curve(...) ## Generic S3 method for ## unweighted area under the ## Precision Recall Curve auc.pr.curve(...) ## Generic S3 method ## for weighted Area under the Precision Recall Curve weighted.auc.pr.curve(...)
... |
Arguments passed on to
|
If estimator is given as
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual classes ## and response probabilities actual_classes <- factor( x = sample( x = classes, size = 1e2, replace = TRUE, prob = c(0.7, 0.3) ) ) response_probabilities <- ifelse( actual_classes == "Kebab", rbeta(sum(actual_classes == "Kebab"), 2, 5), rbeta(sum(actual_classes == "Falafel"), 5, 2) ) ## Construct response ## matrix probability_matrix <- cbind( response_probabilities, 1 - response_probabilities ) ## Calculate area under the precision recall curve SLmetrics::auc.pr.curve( actual = actual_classes, response = probability_matrix )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual classes ## and response probabilities actual_classes <- factor( x = sample( x = classes, size = 1e2, replace = TRUE, prob = c(0.7, 0.3) ) ) response_probabilities <- ifelse( actual_classes == "Kebab", rbeta(sum(actual_classes == "Kebab"), 2, 5), rbeta(sum(actual_classes == "Falafel"), 5, 2) ) ## Construct response ## matrix probability_matrix <- cbind( response_probabilities, 1 - response_probabilities ) ## Calculate area under the precision recall curve SLmetrics::auc.pr.curve( actual = actual_classes, response = probability_matrix )
A generic S3 function to compute the area under the precision recall curve score for a classification model. This function dispatches to S3 methods in auc.pr.curve() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because auc.pr.curve() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap auc.pr.curve() in a "safe" validator that checks for NA values and matching length, for example:
safe_auc.pr.curve <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
auc.pr.curve(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
Use pr.curve() to construct the data.frame and use plot to visualize the area under the curve.
To avoid sorting the same probability matrix multiple times (once per class or curve), you can precompute a single set of sort indices and pass it via the indices argument. This reduces the overall cost from O(K·N log N) to O(N log N + K·N).
## presort response ## probabilities indices <- preorder(response, decreasing = TRUE) ## evaluate area under the precision recall curve auc.pr.curve(actual, response, indices = indices)
## S3 method for class 'factor' auc.pr.curve( actual, response, estimator = 0L, method = 0L, indices = NULL, ... )## S3 method for class 'factor' auc.pr.curve( actual, response, estimator = 0L, method = 0L, indices = NULL, ... )
actual |
|
response |
A |
estimator |
|
method |
A <double> value (default: |
indices |
An optional |
... |
Arguments passed into other methods. |
If estimator is given as
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual classes ## and response probabilities actual_classes <- factor( x = sample( x = classes, size = 1e2, replace = TRUE, prob = c(0.7, 0.3) ) ) response_probabilities <- ifelse( actual_classes == "Kebab", rbeta(sum(actual_classes == "Kebab"), 2, 5), rbeta(sum(actual_classes == "Falafel"), 5, 2) ) ## Construct response ## matrix probability_matrix <- cbind( response_probabilities, 1 - response_probabilities ) ## Evaluate performance SLmetrics::auc.pr.curve( actual = actual_classes, response = probability_matrix )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual classes ## and response probabilities actual_classes <- factor( x = sample( x = classes, size = 1e2, replace = TRUE, prob = c(0.7, 0.3) ) ) response_probabilities <- ifelse( actual_classes == "Kebab", rbeta(sum(actual_classes == "Kebab"), 2, 5), rbeta(sum(actual_classes == "Falafel"), 5, 2) ) ## Construct response ## matrix probability_matrix <- cbind( response_probabilities, 1 - response_probabilities ) ## Evaluate performance SLmetrics::auc.pr.curve( actual = actual_classes, response = probability_matrix )
A generic S3 function to compute the area under the receiver operator characteristics curve score for a classification model. This function dispatches to S3 methods in auc.roc.curve() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because auc.roc.curve() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap auc.roc.curve() in a "safe" validator that checks for NA values and matching length, for example:
safe_auc.roc.curve <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
auc.roc.curve(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
Use roc.curve() to construct the data.frame and use plot to visualize the area under the curve.
To avoid sorting the same probability matrix multiple times (once per class or curve), you can precompute a single set of sort indices and pass it via the indices argument. This reduces the overall cost from O(K·N log N) to O(N log N + K·N).
## presort response ## probabilities indices <- preorder(response, decreasing = TRUE) ## evaluate area under the receiver operator characteristics curve auc.roc.curve(actual, response, indices = indices)
## Generic S3 method ## for Area under the Receiver Operator Characteristics Curve auc.roc.curve(...) ## Generic S3 method for ## unweighted area under the ## Receiver Operator Characteristics ## Curve auc.roc.curve(...) ## Generic S3 method ## for weighted Area under the Receiver Operator Characteristics Curve weighted.auc.roc.curve(...)## Generic S3 method ## for Area under the Receiver Operator Characteristics Curve auc.roc.curve(...) ## Generic S3 method for ## unweighted area under the ## Receiver Operator Characteristics ## Curve auc.roc.curve(...) ## Generic S3 method ## for weighted Area under the Receiver Operator Characteristics Curve weighted.auc.roc.curve(...)
... |
Arguments passed on to
|
If estimator is given as
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual classes ## and response probabilities actual_classes <- factor( x = sample( x = classes, size = 1e2, replace = TRUE, prob = c(0.7, 0.3) ) ) response_probabilities <- ifelse( actual_classes == "Kebab", rbeta(sum(actual_classes == "Kebab"), 2, 5), rbeta(sum(actual_classes == "Falafel"), 5, 2) ) ## Construct response ## matrix probability_matrix <- cbind( response_probabilities, 1 - response_probabilities ) ## Calculate area under the receiver operator characteristics curve SLmetrics::auc.roc.curve( actual = actual_classes, response = probability_matrix )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual classes ## and response probabilities actual_classes <- factor( x = sample( x = classes, size = 1e2, replace = TRUE, prob = c(0.7, 0.3) ) ) response_probabilities <- ifelse( actual_classes == "Kebab", rbeta(sum(actual_classes == "Kebab"), 2, 5), rbeta(sum(actual_classes == "Falafel"), 5, 2) ) ## Construct response ## matrix probability_matrix <- cbind( response_probabilities, 1 - response_probabilities ) ## Calculate area under the receiver operator characteristics curve SLmetrics::auc.roc.curve( actual = actual_classes, response = probability_matrix )
A generic S3 function to compute the area under the receiver operator characteristics curve score for a classification model. This function dispatches to S3 methods in auc.roc.curve() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because auc.roc.curve() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap auc.roc.curve() in a "safe" validator that checks for NA values and matching length, for example:
safe_auc.roc.curve <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
auc.roc.curve(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
Use roc.curve() to construct the data.frame and use plot to visualize the area under the curve.
To avoid sorting the same probability matrix multiple times (once per class or curve), you can precompute a single set of sort indices and pass it via the indices argument. This reduces the overall cost from O(K·N log N) to O(N log N + K·N).
## presort response ## probabilities indices <- preorder(response, decreasing = TRUE) ## evaluate area under the receiver operator characteristics curve auc.roc.curve(actual, response, indices = indices)
## S3 method for class 'factor' auc.roc.curve( actual, response, estimator = 0L, method = 0L, indices = NULL, ... )## S3 method for class 'factor' auc.roc.curve( actual, response, estimator = 0L, method = 0L, indices = NULL, ... )
actual |
|
response |
A |
estimator |
|
method |
A <double> value (default: |
indices |
An optional |
... |
Arguments passed into other methods. |
If estimator is given as
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual classes ## and response probabilities actual_classes <- factor( x = sample( x = classes, size = 1e2, replace = TRUE, prob = c(0.7, 0.3) ) ) response_probabilities <- ifelse( actual_classes == "Kebab", rbeta(sum(actual_classes == "Kebab"), 2, 5), rbeta(sum(actual_classes == "Falafel"), 5, 2) ) ## Construct response ## matrix probability_matrix <- cbind( response_probabilities, 1 - response_probabilities ) ## Evaluate performance SLmetrics::auc.roc.curve( actual = actual_classes, response = probability_matrix )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual classes ## and response probabilities actual_classes <- factor( x = sample( x = classes, size = 1e2, replace = TRUE, prob = c(0.7, 0.3) ) ) response_probabilities <- ifelse( actual_classes == "Kebab", rbeta(sum(actual_classes == "Kebab"), 2, 5), rbeta(sum(actual_classes == "Falafel"), 5, 2) ) ## Construct response ## matrix probability_matrix <- cbind( response_probabilities, 1 - response_probabilities ) ## Evaluate performance SLmetrics::auc.roc.curve( actual = actual_classes, response = probability_matrix )
The auc.xy()-function calculates the area under the curve.
## Generic S3 method auc.xy(...)## Generic S3 method auc.xy(...)
... |
Arguments passed on to
|
A <double> value.
Trapezoidal rule
The trapezoidal rule approximates the integral of a function between
and using trapezoids formed between consecutive points. If
we have points (with )
and corresponding function values , the area under
the curve is approximated by:
Step-function method
The step-function (rectangular) method uses the value of the function at one
endpoint of each subinterval to form rectangles. With the same partition
, the rectangular approximation can be written as:
Area under the curve
## S3 method for class 'numeric' auc.xy(y, x, method = 0L, presorted = TRUE, ...)## S3 method for class 'numeric' auc.xy(y, x, method = 0L, presorted = TRUE, ...)
y, x
|
|
method |
A <integer> value (default: |
presorted |
A <logical>-value length 1 (default: FALSE). If TRUE the input will not be sorted by threshold. |
... |
Arguments passed into other methods. |
A generic S3 function to compute the balanced accuracy score for a classification model. This function dispatches to S3 methods in baccuracy() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because baccuracy() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap baccuracy() in a "safe" validator that checks for NA values and matching length, for example:
safe_baccuracy <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
baccuracy(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate balanced accuracy ## via S3 dispatching baccuracy(confusion_matrix) ## additional performance metrics ## below
The baccuracy.factor() method calls cmatrix() internally, so explicitly invoking baccuracy.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## Generic S3 method ## for Balanced Accuracy baccuracy(...) ## Generic S3 method ## for weighted Balanced Accuracy weighted.baccuracy(...)## Generic S3 method ## for Balanced Accuracy baccuracy(...) ## Generic S3 method ## for weighted Balanced Accuracy weighted.baccuracy(...)
... |
Arguments passed on to
|
A <double>-value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::baccuracy( actual = actual_classes, predicted = predicted_classes )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::baccuracy( actual = actual_classes, predicted = predicted_classes )
A generic S3 function to compute the balanced accuracy score for a classification model. This function dispatches to S3 methods in baccuracy() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because baccuracy() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap baccuracy() in a "safe" validator that checks for NA values and matching length, for example:
safe_baccuracy <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
baccuracy(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate balanced accuracy ## via S3 dispatching baccuracy(confusion_matrix) ## additional performance metrics ## below
The baccuracy.factor() method calls cmatrix() internally, so explicitly invoking baccuracy.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## S3 method for class 'cmatrix' baccuracy(x, adjust = FALSE, na.rm = TRUE, ...)## S3 method for class 'cmatrix' baccuracy(x, adjust = FALSE, na.rm = TRUE, ...)
x |
A confusion matrix created |
adjust |
A <logical> value (default: FALSE). If TRUE the metric is adjusted for random chance |
na.rm |
A <logical> value of length |
... |
Arguments passed into other methods. |
A <double>-value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Construct confusion ## matrix confusion_matrix <- SLmetrics::cmatrix( actual = actual_classes, predicted = predicted_classes ) ## Evaluate performance SLmetrics::baccuracy(confusion_matrix)## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Construct confusion ## matrix confusion_matrix <- SLmetrics::cmatrix( actual = actual_classes, predicted = predicted_classes ) ## Evaluate performance SLmetrics::baccuracy(confusion_matrix)
A generic S3 function to compute the balanced accuracy score for a classification model. This function dispatches to S3 methods in baccuracy() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because baccuracy() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap baccuracy() in a "safe" validator that checks for NA values and matching length, for example:
safe_baccuracy <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
baccuracy(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate balanced accuracy ## via S3 dispatching baccuracy(confusion_matrix) ## additional performance metrics ## below
The baccuracy.factor() method calls cmatrix() internally, so explicitly invoking baccuracy.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## S3 method for class 'factor' baccuracy(actual, predicted, adjust = FALSE, na.rm = TRUE, ...)## S3 method for class 'factor' baccuracy(actual, predicted, adjust = FALSE, na.rm = TRUE, ...)
actual, predicted
|
A pair of <integer> or <factor> vectors of length |
adjust |
A <logical> value (default: FALSE). If TRUE the metric is adjusted for random chance |
na.rm |
A <logical> value of length |
... |
Arguments passed into other methods. |
A <double>-value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::baccuracy( actual = actual_classes, predicted = predicted_classes )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::baccuracy( actual = actual_classes, predicted = predicted_classes )
This dataset contains features extracted from the wavelet transform of banknote images, which are used to classify banknotes as authentic or inauthentic. The data originates from the UCI Machine Learning Repository.
The data is provided as a list with two components:
A data frame containing the following variables:
Variance of the wavelet transformed image.
Skewness of the wavelet transformed image.
Curtosis of the wavelet transformed image.
Entropy of the image.
A factor indicating the authenticity of the banknote. The factor has two levels:
Indicates the banknote is not genuine.
Indicates the banknote is genuine.
data(banknote)data(banknote)
A list with two components:
A data frame with 4 variables: variance, skewness,
curtosis, and entropy.
A factor with levels "inauthentic" and "authentic"
representing the banknote's authenticity.
Gillich, Eugen & Lohweg, Volker. (2010). Banknote Authentication.
A generic S3 function to compute the brier score score for a classification model. This function dispatches to S3 methods in brier.score() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because brier.score() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap brier.score() in a "safe" validator that checks for NA values and matching length, for example:
safe_brier.score <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
brier.score(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## Generic S3 method ## for Brier Score brier.score(...) ## Generic S3 method ## for weighted Brier Score weighted.brier.score(...)## Generic S3 method ## for Brier Score brier.score(...) ## Generic S3 method ## for weighted Brier Score weighted.brier.score(...)
... |
Arguments passed on to
|
A <double>-value
Gneiting, Tilmann, and Adrian E. Raftery. "Strictly proper scoring rules, prediction, and estimation." Journal of the American statistical Association 102.477 (2007): 359-378.
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## seed set.seed(1903) ## The general setup ## with 3 classes n_obs <- 10 n_classes <- 3 ## Generate indicator matrix ## with observed outcome (ok) and ## its predicted probability matrix (qk) ok <- diag(n_classes)[ sample.int(n_classes, n_obs, TRUE), ] qk <- matrix(runif(n_obs * n_classes), n_obs, n_classes) qk <- qk / rowSums(qk) ## Evaluate performance SLmetrics::brier.score( ok = ok, qk = qk )## seed set.seed(1903) ## The general setup ## with 3 classes n_obs <- 10 n_classes <- 3 ## Generate indicator matrix ## with observed outcome (ok) and ## its predicted probability matrix (qk) ok <- diag(n_classes)[ sample.int(n_classes, n_obs, TRUE), ] qk <- matrix(runif(n_obs * n_classes), n_obs, n_classes) qk <- qk / rowSums(qk) ## Evaluate performance SLmetrics::brier.score( ok = ok, qk = qk )
A generic S3 function to compute the brier score score for a classification model. This function dispatches to S3 methods in brier.score() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because brier.score() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap brier.score() in a "safe" validator that checks for NA values and matching length, for example:
safe_brier.score <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
brier.score(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## S3 method for class 'matrix' brier.score(ok, qk, ...)## S3 method for class 'matrix' brier.score(ok, qk, ...)
ok |
A <double> indicator matrix with |
qk |
A |
... |
Arguments passed into other methods. |
A <double>-value
Gneiting, Tilmann, and Adrian E. Raftery. "Strictly proper scoring rules, prediction, and estimation." Journal of the American statistical Association 102.477 (2007): 359-378.
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## seed set.seed(1903) ## The general setup ## with 3 classes n_obs <- 10 n_classes <- 3 ## Generate indicator matrix ## with observed outcome (ok) and ## its predicted probability matrix (qk) ok <- diag(n_classes)[ sample.int(n_classes, n_obs, TRUE), ] qk <- matrix(runif(n_obs * n_classes), n_obs, n_classes) qk <- qk / rowSums(qk) ## Evaluate performance SLmetrics::brier.score( ok = ok, qk = qk )## seed set.seed(1903) ## The general setup ## with 3 classes n_obs <- 10 n_classes <- 3 ## Generate indicator matrix ## with observed outcome (ok) and ## its predicted probability matrix (qk) ok <- diag(n_classes)[ sample.int(n_classes, n_obs, TRUE), ] qk <- matrix(runif(n_obs * n_classes), n_obs, n_classes) qk <- qk / rowSums(qk) ## Evaluate performance SLmetrics::brier.score( ok = ok, qk = qk )
A generic S3 function to compute the concordance correlation coefficient score for a regression model. This function dispatches to S3 methods in ccc() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because ccc() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap ccc() in a "safe" validator that checks for NA values and matching length, for example:
safe_ccc <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
ccc(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## Generic S3 method ## for Concordance Correlation Coefficient ccc(...) ## Generic S3 method ## for weighted Concordance Correlation Coefficient weighted.ccc(...)## Generic S3 method ## for Concordance Correlation Coefficient ccc(...) ## Generic S3 method ## for weighted Concordance Correlation Coefficient weighted.ccc(...)
... |
Arguments passed on to |
A <double> value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Virtanen, Pauli, et al. "SciPy 1.0: fundamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Other Regression:
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
gmse(),
huberloss(),
maape(),
mae(),
mape(),
mpe(),
mse(),
pinball(),
rae(),
rmse(),
rmsle(),
rrmse(),
rrse(),
rsq(),
smape()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::ccc( actual = actual_values, predicted = predicted_values )## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::ccc( actual = actual_values, predicted = predicted_values )
A generic S3 function to compute the concordance correlation coefficient score for a regression model. This function dispatches to S3 methods in ccc() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because ccc() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap ccc() in a "safe" validator that checks for NA values and matching length, for example:
safe_ccc <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
ccc(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## S3 method for class 'numeric' ccc(actual, predicted, correction = FALSE, ...)## S3 method for class 'numeric' ccc(actual, predicted, correction = FALSE, ...)
actual, predicted
|
|
correction |
A <logical> vector of length |
... |
Arguments passed into other methods |
A <double> value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Virtanen, Pauli, et al. "SciPy 1.0: fundamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Regression:
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
gmse(),
huberloss(),
maape(),
mae(),
mape(),
mpe(),
mse(),
pinball(),
rae(),
rmse(),
rmsle(),
rrmse(),
rrse(),
rsq(),
smape()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::ccc( actual = actual_values, predicted = predicted_values )## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::ccc( actual = actual_values, predicted = predicted_values )
-StatisticA generic S3 function to compute the cohen's -statistic score for a classification model. This function dispatches to S3 methods in ckappa() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because ckappa() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap ckappa() in a "safe" validator that checks for NA values and matching length, for example:
safe_ckappa <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
ckappa(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix
confusion_matrix <- cmatrix(actual, predicted)
## evaluate cohen's \eqn{\kappa}-statistic
## via S3 dispatching
ckappa(confusion_matrix)
## additional performance metrics
## below
The ckappa.factor() method calls cmatrix() internally, so explicitly invoking ckappa.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## Generic S3 method ## for Cohen's \eqn{\kappa}-Statistic ckappa(...) ## Generic S3 method ## for weighted Cohen's \eqn{\kappa}-Statistic weighted.ckappa(...)## Generic S3 method ## for Cohen's \eqn{\kappa}-Statistic ckappa(...) ## Generic S3 method ## for weighted Cohen's \eqn{\kappa}-Statistic weighted.ckappa(...)
... |
Arguments passed on to |
A <double>-value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::ckappa( actual = actual_classes, predicted = predicted_classes )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::ckappa( actual = actual_classes, predicted = predicted_classes )
-StatisticA generic S3 function to compute the cohen's -statistic score for a classification model. This function dispatches to S3 methods in ckappa() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because ckappa() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap ckappa() in a "safe" validator that checks for NA values and matching length, for example:
safe_ckappa <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
ckappa(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix
confusion_matrix <- cmatrix(actual, predicted)
## evaluate cohen's \eqn{\kappa}-statistic
## via S3 dispatching
ckappa(confusion_matrix)
## additional performance metrics
## below
The ckappa.factor() method calls cmatrix() internally, so explicitly invoking ckappa.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## S3 method for class 'cmatrix' ckappa(x, beta = 0, ...)## S3 method for class 'cmatrix' ckappa(x, beta = 0, ...)
x |
A confusion matrix created |
beta |
A <double> value of length 1 (default: 0). If |
... |
Arguments passed into other methods. |
A <double>-value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Construct confusion ## matrix confusion_matrix <- SLmetrics::cmatrix( actual = actual_classes, predicted = predicted_classes ) ## Evaluate performance SLmetrics::ckappa(confusion_matrix)## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Construct confusion ## matrix confusion_matrix <- SLmetrics::cmatrix( actual = actual_classes, predicted = predicted_classes ) ## Evaluate performance SLmetrics::ckappa(confusion_matrix)
-StatisticA generic S3 function to compute the cohen's -statistic score for a classification model. This function dispatches to S3 methods in ckappa() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because ckappa() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap ckappa() in a "safe" validator that checks for NA values and matching length, for example:
safe_ckappa <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
ckappa(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix
confusion_matrix <- cmatrix(actual, predicted)
## evaluate cohen's \eqn{\kappa}-statistic
## via S3 dispatching
ckappa(confusion_matrix)
## additional performance metrics
## below
The ckappa.factor() method calls cmatrix() internally, so explicitly invoking ckappa.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## S3 method for class 'factor' ckappa(actual, predicted, beta = 0, ...)## S3 method for class 'factor' ckappa(actual, predicted, beta = 0, ...)
actual, predicted
|
A pair of <integer> or <factor> vectors of length |
beta |
A <double> value of length 1 (default: 0). If |
... |
Arguments passed into other methods. |
A <double>-value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::ckappa( actual = actual_classes, predicted = predicted_classes )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::ckappa( actual = actual_classes, predicted = predicted_classes )
A generic S3 function to compute the confusion matrix for a classification model. This function dispatches to S3 methods in cmatrix() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because cmatrix() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap cmatrix() in a "safe" validator that checks for NA values and matching length, for example:
safe_cmatrix <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
cmatrix(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
cmatrix() is the main function for classification metrics with cmatrix S3 dispatch. These functions internally calls cmatrix(), so there is a signficant gain in computing the confusion matrix first, and then pass it onto the metrics.
For example:
## Compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## Evaluate accuracy ## via S3 dispatching accuracy(confusion_matrix) ## Evaluate recall ## via S3 dispatching recall(confusion_matrix)
## Generic S3 method ## for Confusion Matrix cmatrix(...) ## Generic S3 method ## for weighted Confusion Matrix weighted.cmatrix(...)## Generic S3 method ## for Confusion Matrix cmatrix(...) ## Generic S3 method ## for weighted Confusion Matrix weighted.cmatrix(...)
... |
Arguments passed on to |
A named x <matrix>
There is no robust defensive measure against misspecifying the confusion matrix. If the arguments are passed correctly, the resulting confusion matrix is on the form:
| A (Predicted) | B (Predicted) | |
| A (Actual) | Value | Value |
| B (Actual) | Value | Value |
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Compute the confusion ## matrix SLmetrics::cmatrix( actual = actual_classes, predicted = predicted_classes )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Compute the confusion ## matrix SLmetrics::cmatrix( actual = actual_classes, predicted = predicted_classes )
A generic S3 function to compute the confusion matrix for a classification model. This function dispatches to S3 methods in cmatrix() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because cmatrix() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap cmatrix() in a "safe" validator that checks for NA values and matching length, for example:
safe_cmatrix <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
cmatrix(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
cmatrix() is the main function for classification metrics with cmatrix S3 dispatch. These functions internally calls cmatrix(), so there is a signficant gain in computing the confusion matrix first, and then pass it onto the metrics.
For example:
## Compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## Evaluate accuracy ## via S3 dispatching accuracy(confusion_matrix) ## Evaluate recall ## via S3 dispatching recall(confusion_matrix)
## S3 method for class 'factor' cmatrix(actual, predicted, ...)## S3 method for class 'factor' cmatrix(actual, predicted, ...)
actual, predicted
|
A pair of <integer> or <factor> vectors of length |
... |
Arguments passed into other methods. |
A named x <matrix>
There is no robust defensive measure against misspecifying the confusion matrix. If the arguments are passed correctly, the resulting confusion matrix is on the form:
| A (Predicted) | B (Predicted) | |
| A (Actual) | Value | Value |
| B (Actual) | Value | Value |
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Compute confusion matrix SLmetrics::cmatrix( actual = actual_classes, predicted = predicted_classes )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Compute confusion matrix SLmetrics::cmatrix( actual = actual_classes, predicted = predicted_classes )
A generic S3 function to compute the cross entropy score for a classification model. This function dispatches to S3 methods in cross.entropy() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because cross.entropy() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap cross.entropy() in a "safe" validator that checks for NA values and matching length, for example:
safe_cross.entropy <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
cross.entropy(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## Generic S3 method ## for Cross Entropy cross.entropy(...)## Generic S3 method ## for Cross Entropy cross.entropy(...)
... |
Arguments passed on to
|
A <double> value or vector:
A single <double> value (length 1) if dim == 0.
A <double> vector with length equal to the length of columns if dim == 1.
A <double> vector with length equal to the length of rows if dim == 2.
MacKay, David JC. Information theory, inference and learning algorithms. Cambridge university press, 2003.
Kramer, Oliver, and Oliver Kramer. "Scikit-learn." Machine learning for evolution strategies (2016): 45-53.
Virtanen, Pauli, et al. "SciPy 1.0: f'undamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
Other Entropy:
logloss(),
relative.entropy(),
shannon.entropy()
## generate valid probability ## distributions rand.sum <- function(n) { x <- sort(runif( n-1 )) c(x,1) - c(0, x) } ## empirical and ## predicted probabilites set.seed(1903) pk <- t(replicate(200,rand.sum(5))) qk <- t(replicate(200,rand.sum(5))) ## entropy cross.entropy( pk = pk, qk = qk )## generate valid probability ## distributions rand.sum <- function(n) { x <- sort(runif( n-1 )) c(x,1) - c(0, x) } ## empirical and ## predicted probabilites set.seed(1903) pk <- t(replicate(200,rand.sum(5))) qk <- t(replicate(200,rand.sum(5))) ## entropy cross.entropy( pk = pk, qk = qk )
A generic S3 function to compute the cross entropy score for a classification model. This function dispatches to S3 methods in cross.entropy() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because cross.entropy() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap cross.entropy() in a "safe" validator that checks for NA values and matching length, for example:
safe_cross.entropy <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
cross.entropy(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## S3 method for class 'matrix' cross.entropy(pk, qk, dim = 0L, normalize = FALSE, ...)## S3 method for class 'matrix' cross.entropy(pk, qk, dim = 0L, normalize = FALSE, ...)
pk, qk
|
A pair of <double> matrices of length |
dim |
An <integer> value of length 1 (Default: 0). Defines the dimension along which to calculate the entropy (0: total, 1: row-wise, 2: column-wise). |
normalize |
A <logical>-value (default: TRUE). If TRUE, the mean cross-entropy across all observations is returned; otherwise, the sum of cross-entropies is returned. |
... |
Arguments passed into other methods. |
A <double> value or vector:
A single <double> value (length 1) if dim == 0.
A <double> vector with length equal to the length of columns if dim == 1.
A <double> vector with length equal to the length of rows if dim == 2.
MacKay, David JC. Information theory, inference and learning algorithms. Cambridge university press, 2003.
Kramer, Oliver, and Oliver Kramer. "Scikit-learn." Machine learning for evolution strategies (2016): 45-53.
Virtanen, Pauli, et al. "SciPy 1.0: fundamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
Other Entropy:
logloss(),
relative.entropy(),
shannon.entropy()
## generate valid probability ## distributions rand.sum <- function(n) { x <- sort(runif( n-1 )) c(x,1) - c(0, x) } ## empirical and ## predicted probabilites set.seed(1903) pk <- t(replicate(200,rand.sum(5))) qk <- t(replicate(200,rand.sum(5))) ## entropy cross.entropy( pk = pk, qk = qk )## generate valid probability ## distributions rand.sum <- function(n) { x <- sort(runif( n-1 )) c(x,1) - c(0, x) } ## empirical and ## predicted probabilites set.seed(1903) pk <- t(replicate(200,rand.sum(5))) qk <- t(replicate(200,rand.sum(5))) ## entropy cross.entropy( pk = pk, qk = qk )
A generic S3 function to compute the gamma deviance score for a regression model. This function dispatches to S3 methods in deviance.gamma() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because deviance.gamma() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap deviance.gamma() in a "safe" validator that checks for NA values and matching length, for example:
safe_deviance.gamma <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
deviance.gamma(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## Generic S3 method ## for Gamma Deviance deviance.gamma(...) ## Generic S3 method ## for weighted Gamma Deviance weighted.deviance.gamma(...)## Generic S3 method ## for Gamma Deviance deviance.gamma(...) ## Generic S3 method ## for weighted Gamma Deviance weighted.deviance.gamma(...)
... |
Arguments passed on to |
A <double> value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Virtanen, Pauli, et al. "SciPy 1.0: fundamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Other Regression:
ccc(),
deviance.poisson(),
deviance.tweedie(),
gmse(),
huberloss(),
maape(),
mae(),
mape(),
mpe(),
mse(),
pinball(),
rae(),
rmse(),
rmsle(),
rrmse(),
rrse(),
rsq(),
smape()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::deviance.gamma( actual = actual_values, predicted = predicted_values )## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::deviance.gamma( actual = actual_values, predicted = predicted_values )
A generic S3 function to compute the gamma deviance score for a regression model. This function dispatches to S3 methods in deviance.gamma() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because deviance.gamma() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap deviance.gamma() in a "safe" validator that checks for NA values and matching length, for example:
safe_deviance.gamma <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
deviance.gamma(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## S3 method for class 'gamma.numeric' deviance(actual, predicted, ...)## S3 method for class 'gamma.numeric' deviance(actual, predicted, ...)
actual, predicted
|
|
... |
Arguments passed into other methods |
A <double> value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Virtanen, Pauli, et al. "SciPy 1.0: fundamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Regression:
ccc(),
deviance.poisson(),
deviance.tweedie(),
gmse(),
huberloss(),
maape(),
mae(),
mape(),
mpe(),
mse(),
pinball(),
rae(),
rmse(),
rmsle(),
rrmse(),
rrse(),
rsq(),
smape()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::deviance.gamma( actual = actual_values, predicted = predicted_values )## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::deviance.gamma( actual = actual_values, predicted = predicted_values )
A generic S3 function to compute the poisson deviance score for a regression model. This function dispatches to S3 methods in deviance.poisson() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because deviance.poisson() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap deviance.poisson() in a "safe" validator that checks for NA values and matching length, for example:
safe_deviance.poisson <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
deviance.poisson(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## Generic S3 method ## for Poisson Deviance deviance.poisson(...) ## Generic S3 method ## for weighted Poisson Deviance weighted.deviance.poisson(...)## Generic S3 method ## for Poisson Deviance deviance.poisson(...) ## Generic S3 method ## for weighted Poisson Deviance weighted.deviance.poisson(...)
... |
Arguments passed on to |
A <double> value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Virtanen, Pauli, et al. "SciPy 1.0: fundamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Other Regression:
ccc(),
deviance.gamma(),
deviance.tweedie(),
gmse(),
huberloss(),
maape(),
mae(),
mape(),
mpe(),
mse(),
pinball(),
rae(),
rmse(),
rmsle(),
rrmse(),
rrse(),
rsq(),
smape()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::deviance.poisson( actual = actual_values, predicted = predicted_values )## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::deviance.poisson( actual = actual_values, predicted = predicted_values )
A generic S3 function to compute the poisson deviance score for a regression model. This function dispatches to S3 methods in deviance.poisson() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because deviance.poisson() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap deviance.poisson() in a "safe" validator that checks for NA values and matching length, for example:
safe_deviance.poisson <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
deviance.poisson(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## S3 method for class 'poisson.numeric' deviance(actual, predicted, ...)## S3 method for class 'poisson.numeric' deviance(actual, predicted, ...)
actual, predicted
|
|
... |
Arguments passed into other methods |
A <double> value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Virtanen, Pauli, et al. "SciPy 1.0: fundamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Regression:
ccc(),
deviance.gamma(),
deviance.tweedie(),
gmse(),
huberloss(),
maape(),
mae(),
mape(),
mpe(),
mse(),
pinball(),
rae(),
rmse(),
rmsle(),
rrmse(),
rrse(),
rsq(),
smape()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::deviance.poisson( actual = actual_values, predicted = predicted_values )## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::deviance.poisson( actual = actual_values, predicted = predicted_values )
A generic S3 function to compute the tweedie deviance score for a regression model. This function dispatches to S3 methods in deviance.tweedie() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because deviance.tweedie() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap deviance.tweedie() in a "safe" validator that checks for NA values and matching length, for example:
safe_deviance.tweedie <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
deviance.tweedie(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## Generic S3 method ## for Tweedie Deviance deviance.tweedie(...) ## Generic S3 method ## for weighted Tweedie Deviance weighted.deviance.tweedie(...)## Generic S3 method ## for Tweedie Deviance deviance.tweedie(...) ## Generic S3 method ## for weighted Tweedie Deviance weighted.deviance.tweedie(...)
... |
Arguments passed on to
|
A <double> value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Virtanen, Pauli, et al. "SciPy 1.0: fundamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Other Regression:
ccc(),
deviance.gamma(),
deviance.poisson(),
gmse(),
huberloss(),
maape(),
mae(),
mape(),
mpe(),
mse(),
pinball(),
rae(),
rmse(),
rmsle(),
rrmse(),
rrse(),
rsq(),
smape()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::deviance.tweedie( actual = actual_values, predicted = predicted_values )## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::deviance.tweedie( actual = actual_values, predicted = predicted_values )
A generic S3 function to compute the tweedie deviance score for a regression model. This function dispatches to S3 methods in deviance.tweedie() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because deviance.tweedie() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap deviance.tweedie() in a "safe" validator that checks for NA values and matching length, for example:
safe_deviance.tweedie <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
deviance.tweedie(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## S3 method for class 'tweedie.numeric' deviance(actual, predicted, power = 2, ...)## S3 method for class 'tweedie.numeric' deviance(actual, predicted, power = 2, ...)
actual, predicted
|
|
power |
A <double> value, default = 2. Tweedie power parameter. Either power <= 0 or power >= 1. The higher
|
... |
Arguments passed into other methods |
A <double> value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Virtanen, Pauli, et al. "SciPy 1.0: fundamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Regression:
ccc(),
deviance.gamma(),
deviance.poisson(),
gmse(),
huberloss(),
maape(),
mae(),
mape(),
mpe(),
mse(),
pinball(),
rae(),
rmse(),
rmsle(),
rrmse(),
rrse(),
rsq(),
smape()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::deviance.tweedie( actual = actual_values, predicted = predicted_values )## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::deviance.tweedie( actual = actual_values, predicted = predicted_values )
A generic S3 function to compute the diagnostic odds ratio score for a classification model. This function dispatches to S3 methods in dor() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because dor() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap dor() in a "safe" validator that checks for NA values and matching length, for example:
safe_dor <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
dor(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate diagnostic odds ratio ## via S3 dispatching dor(confusion_matrix) ## additional performance metrics ## below
The dor.factor() method calls cmatrix() internally, so explicitly invoking dor.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## Generic S3 method ## for Diagnostic Odds Ratio dor(...)## Generic S3 method ## for Diagnostic Odds Ratio dor(...)
... |
Arguments passed on to |
A <double>-value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::dor( actual = actual_classes, predicted = predicted_classes )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::dor( actual = actual_classes, predicted = predicted_classes )
A generic S3 function to compute the diagnostic odds ratio score for a classification model. This function dispatches to S3 methods in dor() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because dor() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap dor() in a "safe" validator that checks for NA values and matching length, for example:
safe_dor <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
dor(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate diagnostic odds ratio ## via S3 dispatching dor(confusion_matrix) ## additional performance metrics ## below
The dor.factor() method calls cmatrix() internally, so explicitly invoking dor.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## S3 method for class 'cmatrix' dor(x, ...)## S3 method for class 'cmatrix' dor(x, ...)
x |
A confusion matrix created |
... |
Arguments passed into other methods. |
A <double>-value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Construct confusion ## matrix confusion_matrix <- SLmetrics::cmatrix( actual = actual_classes, predicted = predicted_classes ) ## Evaluate performance SLmetrics::dor(confusion_matrix)## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Construct confusion ## matrix confusion_matrix <- SLmetrics::cmatrix( actual = actual_classes, predicted = predicted_classes ) ## Evaluate performance SLmetrics::dor(confusion_matrix)
A generic S3 function to compute the diagnostic odds ratio score for a classification model. This function dispatches to S3 methods in dor() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because dor() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap dor() in a "safe" validator that checks for NA values and matching length, for example:
safe_dor <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
dor(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate diagnostic odds ratio ## via S3 dispatching dor(confusion_matrix) ## additional performance metrics ## below
The dor.factor() method calls cmatrix() internally, so explicitly invoking dor.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## S3 method for class 'factor' dor(actual, predicted, ...)## S3 method for class 'factor' dor(actual, predicted, ...)
actual, predicted
|
A pair of <integer> or <factor> vectors of length |
... |
Arguments passed into other methods. |
A <double>-value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::dor( actual = actual_classes, predicted = predicted_classes )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::dor( actual = actual_classes, predicted = predicted_classes )
A generic S3 function to compute the score for a classification model. This function dispatches to S3 methods in fbeta() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because fbeta() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap fbeta() in a "safe" validator that checks for NA values and matching length, for example:
safe_fbeta <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
fbeta(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix
confusion_matrix <- cmatrix(actual, predicted)
## evaluate \eqn{f_{\beta}}
## via S3 dispatching
fbeta(confusion_matrix)
## additional performance metrics
## below
The fbeta.factor() method calls cmatrix() internally, so explicitly invoking fbeta.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## Generic S3 method ## for \eqn{f_{\beta}} fbeta(...) ## Generic S3 method ## for weighted \eqn{f_{\beta}} weighted.fbeta(...)## Generic S3 method ## for \eqn{f_{\beta}} fbeta(...) ## Generic S3 method ## for weighted \eqn{f_{\beta}} weighted.fbeta(...)
... |
Arguments passed on to
|
If estimator is given as
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::fbeta( actual = actual_classes, predicted = predicted_classes )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::fbeta( actual = actual_classes, predicted = predicted_classes )
A generic S3 function to compute the score for a classification model. This function dispatches to S3 methods in fbeta() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because fbeta() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap fbeta() in a "safe" validator that checks for NA values and matching length, for example:
safe_fbeta <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
fbeta(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix
confusion_matrix <- cmatrix(actual, predicted)
## evaluate \eqn{f_{\beta}}
## via S3 dispatching
fbeta(confusion_matrix)
## additional performance metrics
## below
The fbeta.factor() method calls cmatrix() internally, so explicitly invoking fbeta.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## S3 method for class 'cmatrix' fbeta(x, beta = 1, estimator = 0L, na.rm = TRUE, ...)## S3 method for class 'cmatrix' fbeta(x, beta = 1, estimator = 0L, na.rm = TRUE, ...)
x |
A confusion matrix created |
beta |
|
estimator |
|
na.rm |
A <logical> value of length |
... |
Arguments passed into other methods. |
If estimator is given as
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Construct confusion ## matrix confusion_matrix <- SLmetrics::cmatrix( actual = actual_classes, predicted = predicted_classes ) ## Evaluate performance SLmetrics::fbeta(confusion_matrix)## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Construct confusion ## matrix confusion_matrix <- SLmetrics::cmatrix( actual = actual_classes, predicted = predicted_classes ) ## Evaluate performance SLmetrics::fbeta(confusion_matrix)
A generic S3 function to compute the score for a classification model. This function dispatches to S3 methods in fbeta() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because fbeta() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap fbeta() in a "safe" validator that checks for NA values and matching length, for example:
safe_fbeta <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
fbeta(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix
confusion_matrix <- cmatrix(actual, predicted)
## evaluate \eqn{f_{\beta}}
## via S3 dispatching
fbeta(confusion_matrix)
## additional performance metrics
## below
The fbeta.factor() method calls cmatrix() internally, so explicitly invoking fbeta.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## S3 method for class 'factor' fbeta(actual, predicted, beta = 1, estimator = 0L, na.rm = TRUE, ...)## S3 method for class 'factor' fbeta(actual, predicted, beta = 1, estimator = 0L, na.rm = TRUE, ...)
actual, predicted
|
A pair of <integer> or <factor> vectors of length |
beta |
|
estimator |
|
na.rm |
A <logical> value of length |
... |
Arguments passed into other methods. |
If estimator is given as
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::fbeta( actual = actual_classes, predicted = predicted_classes )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::fbeta( actual = actual_classes, predicted = predicted_classes )
A generic S3 function to compute the false discovery rate score for a classification model. This function dispatches to S3 methods in fdr() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because fdr() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap fdr() in a "safe" validator that checks for NA values and matching length, for example:
safe_fdr <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
fdr(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate false discovery rate ## via S3 dispatching fdr(confusion_matrix) ## additional performance metrics ## below
The fdr.factor() method calls cmatrix() internally, so explicitly invoking fdr.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## Generic S3 method ## for False Discovery Rate fdr(...) ## Generic S3 method ## for weighted False Discovery Rate weighted.fdr(...)## Generic S3 method ## for False Discovery Rate fdr(...) ## Generic S3 method ## for weighted False Discovery Rate weighted.fdr(...)
... |
Arguments passed on to
|
If estimator is given as
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::fdr( actual = actual_classes, predicted = predicted_classes )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::fdr( actual = actual_classes, predicted = predicted_classes )
A generic S3 function to compute the false discovery rate score for a classification model. This function dispatches to S3 methods in fdr() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because fdr() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap fdr() in a "safe" validator that checks for NA values and matching length, for example:
safe_fdr <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
fdr(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate false discovery rate ## via S3 dispatching fdr(confusion_matrix) ## additional performance metrics ## below
The fdr.factor() method calls cmatrix() internally, so explicitly invoking fdr.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## S3 method for class 'cmatrix' fdr(x, estimator = 0L, na.rm = TRUE, ...)## S3 method for class 'cmatrix' fdr(x, estimator = 0L, na.rm = TRUE, ...)
x |
A confusion matrix created |
estimator |
|
na.rm |
A <logical> value of length |
... |
Arguments passed into other methods. |
If estimator is given as
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Construct confusion ## matrix confusion_matrix <- SLmetrics::cmatrix( actual = actual_classes, predicted = predicted_classes ) ## Evaluate performance SLmetrics::fdr(confusion_matrix)## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Construct confusion ## matrix confusion_matrix <- SLmetrics::cmatrix( actual = actual_classes, predicted = predicted_classes ) ## Evaluate performance SLmetrics::fdr(confusion_matrix)
A generic S3 function to compute the false discovery rate score for a classification model. This function dispatches to S3 methods in fdr() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because fdr() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap fdr() in a "safe" validator that checks for NA values and matching length, for example:
safe_fdr <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
fdr(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate false discovery rate ## via S3 dispatching fdr(confusion_matrix) ## additional performance metrics ## below
The fdr.factor() method calls cmatrix() internally, so explicitly invoking fdr.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## S3 method for class 'factor' fdr(actual, predicted, estimator = 0L, na.rm = TRUE, ...)## S3 method for class 'factor' fdr(actual, predicted, estimator = 0L, na.rm = TRUE, ...)
actual, predicted
|
A pair of <integer> or <factor> vectors of length |
estimator |
|
na.rm |
A <logical> value of length |
... |
Arguments passed into other methods. |
If estimator is given as
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::fdr( actual = actual_classes, predicted = predicted_classes )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::fdr( actual = actual_classes, predicted = predicted_classes )
A generic S3 function to compute the false omission rate score for a classification model. This function dispatches to S3 methods in fer() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because fer() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap fer() in a "safe" validator that checks for NA values and matching length, for example:
safe_fer <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
fer(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate false omission rate ## via S3 dispatching fer(confusion_matrix) ## additional performance metrics ## below
The fer.factor() method calls cmatrix() internally, so explicitly invoking fer.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## Generic S3 method ## for False Omission Rate fer(...) ## Generic S3 method ## for weighted False Omission Rate weighted.fer(...)## Generic S3 method ## for False Omission Rate fer(...) ## Generic S3 method ## for weighted False Omission Rate weighted.fer(...)
... |
Arguments passed on to
|
If estimator is given as
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::fer( actual = actual_classes, predicted = predicted_classes )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::fer( actual = actual_classes, predicted = predicted_classes )
A generic S3 function to compute the false omission rate score for a classification model. This function dispatches to S3 methods in fer() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because fer() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap fer() in a "safe" validator that checks for NA values and matching length, for example:
safe_fer <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
fer(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate false omission rate ## via S3 dispatching fer(confusion_matrix) ## additional performance metrics ## below
The fer.factor() method calls cmatrix() internally, so explicitly invoking fer.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## S3 method for class 'cmatrix' fer(x, estimator = 0L, na.rm = TRUE, ...)## S3 method for class 'cmatrix' fer(x, estimator = 0L, na.rm = TRUE, ...)
x |
A confusion matrix created |
estimator |
|
na.rm |
A <logical> value of length |
... |
Arguments passed into other methods. |
If estimator is given as
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Construct confusion ## matrix confusion_matrix <- SLmetrics::cmatrix( actual = actual_classes, predicted = predicted_classes ) ## Evaluate performance SLmetrics::fer(confusion_matrix)## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Construct confusion ## matrix confusion_matrix <- SLmetrics::cmatrix( actual = actual_classes, predicted = predicted_classes ) ## Evaluate performance SLmetrics::fer(confusion_matrix)
A generic S3 function to compute the false omission rate score for a classification model. This function dispatches to S3 methods in fer() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because fer() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap fer() in a "safe" validator that checks for NA values and matching length, for example:
safe_fer <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
fer(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate false omission rate ## via S3 dispatching fer(confusion_matrix) ## additional performance metrics ## below
The fer.factor() method calls cmatrix() internally, so explicitly invoking fer.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## S3 method for class 'factor' fer(actual, predicted, estimator = 0L, na.rm = TRUE, ...)## S3 method for class 'factor' fer(actual, predicted, estimator = 0L, na.rm = TRUE, ...)
actual, predicted
|
A pair of <integer> or <factor> vectors of length |
estimator |
|
na.rm |
A <logical> value of length |
... |
Arguments passed into other methods. |
If estimator is given as
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::fer( actual = actual_classes, predicted = predicted_classes )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::fer( actual = actual_classes, predicted = predicted_classes )
A generic S3 function to compute the fowlkes mallows index score for a classification model. This function dispatches to S3 methods in fmi() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because fmi() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap fmi() in a "safe" validator that checks for NA values and matching length, for example:
safe_fmi <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
fmi(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate fowlkes mallows index ## via S3 dispatching fmi(confusion_matrix) ## additional performance metrics ## below
The fmi.factor() method calls cmatrix() internally, so explicitly invoking fmi.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## Generic S3 method ## for Fowlkes Mallows Index fmi(...) ## Generic S3 method ## for weighted Fowlkes Mallows Index weighted.fmi(...)## Generic S3 method ## for Fowlkes Mallows Index fmi(...) ## Generic S3 method ## for weighted Fowlkes Mallows Index weighted.fmi(...)
... |
Arguments passed on to |
A <double>-value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::fmi( actual = actual_classes, predicted = predicted_classes )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::fmi( actual = actual_classes, predicted = predicted_classes )
A generic S3 function to compute the fowlkes mallows index score for a classification model. This function dispatches to S3 methods in fmi() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because fmi() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap fmi() in a "safe" validator that checks for NA values and matching length, for example:
safe_fmi <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
fmi(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate fowlkes mallows index ## via S3 dispatching fmi(confusion_matrix) ## additional performance metrics ## below
The fmi.factor() method calls cmatrix() internally, so explicitly invoking fmi.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## S3 method for class 'cmatrix' fmi(x, ...)## S3 method for class 'cmatrix' fmi(x, ...)
x |
A confusion matrix created |
... |
Arguments passed into other methods. |
A <double>-value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Construct confusion ## matrix confusion_matrix <- SLmetrics::cmatrix( actual = actual_classes, predicted = predicted_classes ) ## Evaluate performance SLmetrics::fmi(confusion_matrix)## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Construct confusion ## matrix confusion_matrix <- SLmetrics::cmatrix( actual = actual_classes, predicted = predicted_classes ) ## Evaluate performance SLmetrics::fmi(confusion_matrix)
A generic S3 function to compute the fowlkes mallows index score for a classification model. This function dispatches to S3 methods in fmi() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because fmi() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap fmi() in a "safe" validator that checks for NA values and matching length, for example:
safe_fmi <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
fmi(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate fowlkes mallows index ## via S3 dispatching fmi(confusion_matrix) ## additional performance metrics ## below
The fmi.factor() method calls cmatrix() internally, so explicitly invoking fmi.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## S3 method for class 'factor' fmi(actual, predicted, ...)## S3 method for class 'factor' fmi(actual, predicted, ...)
actual, predicted
|
A pair of <integer> or <factor> vectors of length |
... |
Arguments passed into other methods. |
A <double>-value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::fmi( actual = actual_classes, predicted = predicted_classes )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::fmi( actual = actual_classes, predicted = predicted_classes )
A generic S3 function to compute the false positive rate score for a classification model. This function dispatches to S3 methods in fpr() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because fpr() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap fpr() in a "safe" validator that checks for NA values and matching length, for example:
safe_fpr <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
fpr(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate false positive rate ## via S3 dispatching fpr(confusion_matrix) ## additional performance metrics ## below
The fpr.factor() method calls cmatrix() internally, so explicitly invoking fpr.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## Generic S3 method ## for False Positive Rate fpr(...) ## Generic S3 method ## for weighted False Positive Rate weighted.fpr(...)## Generic S3 method ## for False Positive Rate fpr(...) ## Generic S3 method ## for weighted False Positive Rate weighted.fpr(...)
... |
Arguments passed on to
|
If estimator is given as
The false positive rate has other names depending on research field:
Fallout, fallout()
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::fpr( actual = actual_classes, predicted = predicted_classes )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::fpr( actual = actual_classes, predicted = predicted_classes )
A generic S3 function to compute the false positive rate score for a classification model. This function dispatches to S3 methods in fpr() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because fpr() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap fpr() in a "safe" validator that checks for NA values and matching length, for example:
safe_fpr <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
fpr(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate false positive rate ## via S3 dispatching fpr(confusion_matrix) ## additional performance metrics ## below
The fpr.factor() method calls cmatrix() internally, so explicitly invoking fpr.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## S3 method for class 'cmatrix' fpr(x, estimator = 0L, na.rm = TRUE, ...)## S3 method for class 'cmatrix' fpr(x, estimator = 0L, na.rm = TRUE, ...)
x |
A confusion matrix created |
estimator |
|
na.rm |
A <logical> value of length |
... |
Arguments passed into other methods. |
If estimator is given as
The false positive rate has other names depending on research field:
Fallout, fallout()
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Construct confusion ## matrix confusion_matrix <- SLmetrics::cmatrix( actual = actual_classes, predicted = predicted_classes ) ## Evaluate performance SLmetrics::fpr(confusion_matrix)## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Construct confusion ## matrix confusion_matrix <- SLmetrics::cmatrix( actual = actual_classes, predicted = predicted_classes ) ## Evaluate performance SLmetrics::fpr(confusion_matrix)
A generic S3 function to compute the false positive rate score for a classification model. This function dispatches to S3 methods in fpr() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because fpr() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap fpr() in a "safe" validator that checks for NA values and matching length, for example:
safe_fpr <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
fpr(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate false positive rate ## via S3 dispatching fpr(confusion_matrix) ## additional performance metrics ## below
The fpr.factor() method calls cmatrix() internally, so explicitly invoking fpr.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## S3 method for class 'factor' fpr(actual, predicted, estimator = 0L, na.rm = TRUE, ...)## S3 method for class 'factor' fpr(actual, predicted, estimator = 0L, na.rm = TRUE, ...)
actual, predicted
|
A pair of <integer> or <factor> vectors of length |
estimator |
|
na.rm |
A <logical> value of length |
... |
Arguments passed into other methods. |
If estimator is given as
The false positive rate has other names depending on research field:
Fallout, fallout()
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::fpr( actual = actual_classes, predicted = predicted_classes )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::fpr( actual = actual_classes, predicted = predicted_classes )
A generic S3 function to compute the geometric mean squared error score for a regression model. This function dispatches to S3 methods in gmse() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because gmse() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap gmse() in a "safe" validator that checks for NA values and matching length, for example:
safe_gmse <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
gmse(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## Generic S3 method ## for Geometric Mean Squared Error gmse(...) ## Generic S3 method ## for weighted Geometric Mean Squared Error weighted.gmse(...)## Generic S3 method ## for Geometric Mean Squared Error gmse(...) ## Generic S3 method ## for weighted Geometric Mean Squared Error weighted.gmse(...)
... |
Arguments passed on to |
A <double> value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Virtanen, Pauli, et al. "SciPy 1.0: fundamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Other Regression:
ccc(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
huberloss(),
maape(),
mae(),
mape(),
mpe(),
mse(),
pinball(),
rae(),
rmse(),
rmsle(),
rrmse(),
rrse(),
rsq(),
smape()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::gmse( actual = actual_values, predicted = predicted_values )## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::gmse( actual = actual_values, predicted = predicted_values )
A generic S3 function to compute the geometric mean squared error score for a regression model. This function dispatches to S3 methods in gmse() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because gmse() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap gmse() in a "safe" validator that checks for NA values and matching length, for example:
safe_gmse <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
gmse(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## S3 method for class 'numeric' gmse(actual, predicted, ...)## S3 method for class 'numeric' gmse(actual, predicted, ...)
actual, predicted
|
|
... |
Arguments passed into other methods |
A <double> value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Virtanen, Pauli, et al. "SciPy 1.0: fundamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Regression:
ccc(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
huberloss(),
maape(),
mae(),
mape(),
mpe(),
mse(),
pinball(),
rae(),
rmse(),
rmsle(),
rrmse(),
rrse(),
rsq(),
smape()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::gmse( actual = actual_values, predicted = predicted_values )## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::gmse( actual = actual_values, predicted = predicted_values )
A generic S3 function to compute the hamming loss score for a classification model. This function dispatches to S3 methods in hammingloss() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because hammingloss() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap hammingloss() in a "safe" validator that checks for NA values and matching length, for example:
safe_hammingloss <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
hammingloss(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate hamming loss ## via S3 dispatching hammingloss(confusion_matrix) ## additional performance metrics ## below
The hammingloss.factor() method calls cmatrix() internally, so explicitly invoking hammingloss.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## Generic S3 method ## for Hamming Loss hammingloss(...) ## Generic S3 method ## for weighted Hamming Loss weighted.hammingloss(...)## Generic S3 method ## for Hamming Loss hammingloss(...) ## Generic S3 method ## for weighted Hamming Loss weighted.hammingloss(...)
... |
Arguments passed on to |
A <double>-value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::hammingloss( actual = actual_classes, predicted = predicted_classes )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::hammingloss( actual = actual_classes, predicted = predicted_classes )
A generic S3 function to compute the hamming loss score for a classification model. This function dispatches to S3 methods in hammingloss() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because hammingloss() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap hammingloss() in a "safe" validator that checks for NA values and matching length, for example:
safe_hammingloss <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
hammingloss(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate hamming loss ## via S3 dispatching hammingloss(confusion_matrix) ## additional performance metrics ## below
The hammingloss.factor() method calls cmatrix() internally, so explicitly invoking hammingloss.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## S3 method for class 'cmatrix' hammingloss(x, ...)## S3 method for class 'cmatrix' hammingloss(x, ...)
x |
A confusion matrix created |
... |
Arguments passed into other methods. |
A <double>-value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Construct confusion ## matrix confusion_matrix <- SLmetrics::cmatrix( actual = actual_classes, predicted = predicted_classes ) ## Evaluate performance SLmetrics::hammingloss(confusion_matrix)## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Construct confusion ## matrix confusion_matrix <- SLmetrics::cmatrix( actual = actual_classes, predicted = predicted_classes ) ## Evaluate performance SLmetrics::hammingloss(confusion_matrix)
A generic S3 function to compute the hamming loss score for a classification model. This function dispatches to S3 methods in hammingloss() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because hammingloss() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap hammingloss() in a "safe" validator that checks for NA values and matching length, for example:
safe_hammingloss <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
hammingloss(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate hamming loss ## via S3 dispatching hammingloss(confusion_matrix) ## additional performance metrics ## below
The hammingloss.factor() method calls cmatrix() internally, so explicitly invoking hammingloss.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## S3 method for class 'factor' hammingloss(actual, predicted, ...)## S3 method for class 'factor' hammingloss(actual, predicted, ...)
actual, predicted
|
A pair of <integer> or <factor> vectors of length |
... |
Arguments passed into other methods. |
A <double>-value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::hammingloss( actual = actual_classes, predicted = predicted_classes )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::hammingloss( actual = actual_classes, predicted = predicted_classes )
A generic S3 function to compute the huber loss score for a regression model. This function dispatches to S3 methods in huberloss() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because huberloss() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap huberloss() in a "safe" validator that checks for NA values and matching length, for example:
safe_huberloss <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
huberloss(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## Generic S3 method ## for Huber Loss huberloss(...) ## Generic S3 method ## for weighted Huber Loss weighted.huberloss(...)## Generic S3 method ## for Huber Loss huberloss(...) ## Generic S3 method ## for weighted Huber Loss weighted.huberloss(...)
... |
Arguments passed on to |
A <double> value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Virtanen, Pauli, et al. "SciPy 1.0: fundamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Other Regression:
ccc(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
gmse(),
maape(),
mae(),
mape(),
mpe(),
mse(),
pinball(),
rae(),
rmse(),
rmsle(),
rrmse(),
rrse(),
rsq(),
smape()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::huberloss( actual = actual_values, predicted = predicted_values )## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::huberloss( actual = actual_values, predicted = predicted_values )
A generic S3 function to compute the huber loss score for a regression model. This function dispatches to S3 methods in huberloss() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because huberloss() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap huberloss() in a "safe" validator that checks for NA values and matching length, for example:
safe_huberloss <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
huberloss(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## S3 method for class 'numeric' huberloss(actual, predicted, delta = 1, ...)## S3 method for class 'numeric' huberloss(actual, predicted, delta = 1, ...)
actual, predicted
|
|
delta |
A <double>-vector of length |
... |
Arguments passed into other methods |
A <double> value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Virtanen, Pauli, et al. "SciPy 1.0: fundamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Regression:
ccc(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
gmse(),
maape(),
mae(),
mape(),
mpe(),
mse(),
pinball(),
rae(),
rmse(),
rmsle(),
rrmse(),
rrse(),
rsq(),
smape()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::huberloss( actual = actual_values, predicted = predicted_values )## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::huberloss( actual = actual_values, predicted = predicted_values )
A generic S3 function to compute the jaccard index score for a classification model. This function dispatches to S3 methods in jaccard() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because jaccard() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap jaccard() in a "safe" validator that checks for NA values and matching length, for example:
safe_jaccard <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
jaccard(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate jaccard index ## via S3 dispatching jaccard(confusion_matrix) ## additional performance metrics ## below
The jaccard.factor() method calls cmatrix() internally, so explicitly invoking jaccard.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## Generic S3 method ## for Jaccard Index jaccard(...) ## Generic S3 method ## for weighted Jaccard Index weighted.jaccard(...)## Generic S3 method ## for Jaccard Index jaccard(...) ## Generic S3 method ## for weighted Jaccard Index weighted.jaccard(...)
... |
Arguments passed on to
|
If estimator is given as
The specificity has other names depending on research field:
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::jaccard( actual = actual_classes, predicted = predicted_classes )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::jaccard( actual = actual_classes, predicted = predicted_classes )
A generic S3 function to compute the jaccard index score for a classification model. This function dispatches to S3 methods in jaccard() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because jaccard() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap jaccard() in a "safe" validator that checks for NA values and matching length, for example:
safe_jaccard <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
jaccard(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate jaccard index ## via S3 dispatching jaccard(confusion_matrix) ## additional performance metrics ## below
The jaccard.factor() method calls cmatrix() internally, so explicitly invoking jaccard.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## S3 method for class 'cmatrix' jaccard(x, estimator = 0L, na.rm = TRUE, ...)## S3 method for class 'cmatrix' jaccard(x, estimator = 0L, na.rm = TRUE, ...)
x |
A confusion matrix created |
estimator |
|
na.rm |
A <logical> value of length |
... |
Arguments passed into other methods. |
If estimator is given as
The specificity has other names depending on research field:
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Construct confusion ## matrix confusion_matrix <- SLmetrics::cmatrix( actual = actual_classes, predicted = predicted_classes ) ## Evaluate performance SLmetrics::jaccard(confusion_matrix)## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Construct confusion ## matrix confusion_matrix <- SLmetrics::cmatrix( actual = actual_classes, predicted = predicted_classes ) ## Evaluate performance SLmetrics::jaccard(confusion_matrix)
A generic S3 function to compute the jaccard index score for a classification model. This function dispatches to S3 methods in jaccard() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because jaccard() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap jaccard() in a "safe" validator that checks for NA values and matching length, for example:
safe_jaccard <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
jaccard(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate jaccard index ## via S3 dispatching jaccard(confusion_matrix) ## additional performance metrics ## below
The jaccard.factor() method calls cmatrix() internally, so explicitly invoking jaccard.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## S3 method for class 'factor' jaccard(actual, predicted, estimator = 0L, na.rm = TRUE, ...)## S3 method for class 'factor' jaccard(actual, predicted, estimator = 0L, na.rm = TRUE, ...)
actual, predicted
|
A pair of <integer> or <factor> vectors of length |
estimator |
|
na.rm |
A <logical> value of length |
... |
Arguments passed into other methods. |
If estimator is given as
The specificity has other names depending on research field:
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::jaccard( actual = actual_classes, predicted = predicted_classes )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::jaccard( actual = actual_classes, predicted = predicted_classes )
A generic S3 function to compute the logarithmic loss score for a classification model. This function dispatches to S3 methods in logloss() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because logloss() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap logloss() in a "safe" validator that checks for NA values and matching length, for example:
safe_logloss <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
logloss(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## Generic S3 method ## for Logarithmic Loss logloss(...) ## Generic S3 method ## for weighted Logarithmic Loss weighted.logloss(...)## Generic S3 method ## for Logarithmic Loss logloss(...) ## Generic S3 method ## for weighted Logarithmic Loss weighted.logloss(...)
... |
Arguments passed on to
|
A <double>
MacKay, David JC. Information theory, inference and learning algorithms. Cambridge university press, 2003.
Kramer, Oliver, and Oliver Kramer. "Scikit-learn." Machine learning for evolution strategies (2016): 45-53.
Virtanen, Pauli, et al. "SciPy 1.0: f'undamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
Other Entropy:
cross.entropy(),
relative.entropy(),
shannon.entropy()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted response ## probabilities actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) response <- runif(n = 1e3) ## Logloss SLmetrics::logloss( actual = actual_classes, response = cbind( response, 1 - response ) ) ## Generate observed ## frequencies actual_frequency <- sample(10L:100L, size = 1e3, replace = TRUE) ## Poisson Logloss SLmetrics::logloss( actual = actual_frequency, response = response )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted response ## probabilities actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) response <- runif(n = 1e3) ## Logloss SLmetrics::logloss( actual = actual_classes, response = cbind( response, 1 - response ) ) ## Generate observed ## frequencies actual_frequency <- sample(10L:100L, size = 1e3, replace = TRUE) ## Poisson Logloss SLmetrics::logloss( actual = actual_frequency, response = response )
A generic S3 function to compute the logarithmic loss score for a classification model. This function dispatches to S3 methods in logloss() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because logloss() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap logloss() in a "safe" validator that checks for NA values and matching length, for example:
safe_logloss <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
logloss(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## S3 method for class 'factor' logloss(actual, response, normalize = TRUE, ...)## S3 method for class 'factor' logloss(actual, response, normalize = TRUE, ...)
actual |
|
response |
A |
normalize |
A <logical>-value (default: TRUE). If TRUE, the mean cross-entropy across all observations is returned; otherwise, the sum of cross-entropies is returned. |
... |
Arguments passed into other methods. |
A <double>
MacKay, David JC. Information theory, inference and learning algorithms. Cambridge university press, 2003.
Kramer, Oliver, and Oliver Kramer. "Scikit-learn." Machine learning for evolution strategies (2016): 45-53.
Virtanen, Pauli, et al. "SciPy 1.0: fundamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
Other Entropy:
cross.entropy(),
relative.entropy(),
shannon.entropy()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted response ## probabilities actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) response <- runif(n = 1e3) ## Evaluate performance SLmetrics::logloss( actual = actual_classes, response = cbind( response, 1 - response ) ) ## Generate observed ## frequencies actual_frequency <- sample(10L:100L, size = 1e3, replace = TRUE) SLmetrics::logloss( actual = actual_frequency, response = response )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted response ## probabilities actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) response <- runif(n = 1e3) ## Evaluate performance SLmetrics::logloss( actual = actual_classes, response = cbind( response, 1 - response ) ) ## Generate observed ## frequencies actual_frequency <- sample(10L:100L, size = 1e3, replace = TRUE) SLmetrics::logloss( actual = actual_frequency, response = response )
A generic S3 function to compute the logarithmic loss score for a classification model. This function dispatches to S3 methods in logloss() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because logloss() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap logloss() in a "safe" validator that checks for NA values and matching length, for example:
safe_logloss <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
logloss(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## S3 method for class 'integer' logloss(actual, response, normalize = TRUE, ...)## S3 method for class 'integer' logloss(actual, response, normalize = TRUE, ...)
actual |
|
response |
A |
normalize |
A <logical>-value (default: TRUE). If TRUE, the mean cross-entropy across all observations is returned; otherwise, the sum of cross-entropies is returned. |
... |
Arguments passed into other methods. |
A <double>
MacKay, David JC. Information theory, inference and learning algorithms. Cambridge university press, 2003.
Kramer, Oliver, and Oliver Kramer. "Scikit-learn." Machine learning for evolution strategies (2016): 45-53.
Virtanen, Pauli, et al. "SciPy 1.0: fundamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
Other Entropy:
cross.entropy(),
relative.entropy(),
shannon.entropy()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted response ## probabilities actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) response <- runif(n = 1e3) ## Evaluate performance SLmetrics::logloss( actual = actual_classes, response = cbind( response, 1 - response ) ) ## Generate observed ## frequencies actual_frequency <- sample(10L:100L, size = 1e3, replace = TRUE) SLmetrics::logloss( actual = actual_frequency, response = response )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted response ## probabilities actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) response <- runif(n = 1e3) ## Evaluate performance SLmetrics::logloss( actual = actual_classes, response = cbind( response, 1 - response ) ) ## Generate observed ## frequencies actual_frequency <- sample(10L:100L, size = 1e3, replace = TRUE) SLmetrics::logloss( actual = actual_frequency, response = response )
A generic S3 function to compute the mean arctangent absolute percentage error score for a regression model. This function dispatches to S3 methods in maape() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because maape() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap maape() in a "safe" validator that checks for NA values and matching length, for example:
safe_maape <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
maape(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## Generic S3 method ## for Mean Arctangent Absolute Percentage Error maape(...) ## Generic S3 method ## for weighted Mean Arctangent Absolute Percentage Error weighted.maape(...)## Generic S3 method ## for Mean Arctangent Absolute Percentage Error maape(...) ## Generic S3 method ## for weighted Mean Arctangent Absolute Percentage Error weighted.maape(...)
... |
Arguments passed on to |
A <double> value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Virtanen, Pauli, et al. "SciPy 1.0: fundamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Other Regression:
ccc(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
gmse(),
huberloss(),
mae(),
mape(),
mpe(),
mse(),
pinball(),
rae(),
rmse(),
rmsle(),
rrmse(),
rrse(),
rsq(),
smape()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::maape( actual = actual_values, predicted = predicted_values )## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::maape( actual = actual_values, predicted = predicted_values )
A generic S3 function to compute the mean arctangent absolute percentage error score for a regression model. This function dispatches to S3 methods in maape() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because maape() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap maape() in a "safe" validator that checks for NA values and matching length, for example:
safe_maape <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
maape(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## S3 method for class 'numeric' maape(actual, predicted, ...)## S3 method for class 'numeric' maape(actual, predicted, ...)
actual, predicted
|
|
... |
Arguments passed into other methods |
A <double> value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Virtanen, Pauli, et al. "SciPy 1.0: fundamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Regression:
ccc(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
gmse(),
huberloss(),
mae(),
mape(),
mpe(),
mse(),
pinball(),
rae(),
rmse(),
rmsle(),
rrmse(),
rrse(),
rsq(),
smape()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::maape( actual = actual_values, predicted = predicted_values )## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::maape( actual = actual_values, predicted = predicted_values )
A generic S3 function to compute the mean absolute error score for a regression model. This function dispatches to S3 methods in mae() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because mae() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap mae() in a "safe" validator that checks for NA values and matching length, for example:
safe_mae <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
mae(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## Generic S3 method ## for Mean Absolute Error mae(...) ## Generic S3 method ## for weighted Mean Absolute Error weighted.mae(...)## Generic S3 method ## for Mean Absolute Error mae(...) ## Generic S3 method ## for weighted Mean Absolute Error weighted.mae(...)
... |
Arguments passed on to |
A <double> value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Virtanen, Pauli, et al. "SciPy 1.0: fundamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Other Regression:
ccc(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
gmse(),
huberloss(),
maape(),
mape(),
mpe(),
mse(),
pinball(),
rae(),
rmse(),
rmsle(),
rrmse(),
rrse(),
rsq(),
smape()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::mae( actual = actual_values, predicted = predicted_values )## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::mae( actual = actual_values, predicted = predicted_values )
A generic S3 function to compute the mean absolute error score for a regression model. This function dispatches to S3 methods in mae() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because mae() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap mae() in a "safe" validator that checks for NA values and matching length, for example:
safe_mae <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
mae(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## S3 method for class 'numeric' mae(actual, predicted, ...)## S3 method for class 'numeric' mae(actual, predicted, ...)
actual, predicted
|
|
... |
Arguments passed into other methods |
A <double> value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Virtanen, Pauli, et al. "SciPy 1.0: fundamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Regression:
ccc(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
gmse(),
huberloss(),
maape(),
mape(),
mpe(),
mse(),
pinball(),
rae(),
rmse(),
rmsle(),
rrmse(),
rrse(),
rsq(),
smape()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::mae( actual = actual_values, predicted = predicted_values )## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::mae( actual = actual_values, predicted = predicted_values )
A generic S3 function to compute the mean absolute percentage error score for a regression model. This function dispatches to S3 methods in mape() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because mape() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap mape() in a "safe" validator that checks for NA values and matching length, for example:
safe_mape <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
mape(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## Generic S3 method ## for Mean Absolute Percentage Error mape(...) ## Generic S3 method ## for weighted Mean Absolute Percentage Error weighted.mape(...)## Generic S3 method ## for Mean Absolute Percentage Error mape(...) ## Generic S3 method ## for weighted Mean Absolute Percentage Error weighted.mape(...)
... |
Arguments passed on to |
A <double> value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Virtanen, Pauli, et al. "SciPy 1.0: fundamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Other Regression:
ccc(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
gmse(),
huberloss(),
maape(),
mae(),
mpe(),
mse(),
pinball(),
rae(),
rmse(),
rmsle(),
rrmse(),
rrse(),
rsq(),
smape()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::mape( actual = actual_values, predicted = predicted_values )## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::mape( actual = actual_values, predicted = predicted_values )
A generic S3 function to compute the mean absolute percentage error score for a regression model. This function dispatches to S3 methods in mape() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because mape() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap mape() in a "safe" validator that checks for NA values and matching length, for example:
safe_mape <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
mape(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## S3 method for class 'numeric' mape(actual, predicted, ...)## S3 method for class 'numeric' mape(actual, predicted, ...)
actual, predicted
|
|
... |
Arguments passed into other methods |
A <double> value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Virtanen, Pauli, et al. "SciPy 1.0: fundamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Regression:
ccc(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
gmse(),
huberloss(),
maape(),
mae(),
mpe(),
mse(),
pinball(),
rae(),
rmse(),
rmsle(),
rrmse(),
rrse(),
rsq(),
smape()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::mape( actual = actual_values, predicted = predicted_values )## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::mape( actual = actual_values, predicted = predicted_values )
A generic S3 function to compute the matthews correlation coefficient score for a classification model. This function dispatches to S3 methods in mcc() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because mcc() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap mcc() in a "safe" validator that checks for NA values and matching length, for example:
safe_mcc <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
mcc(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate matthews correlation coefficient ## via S3 dispatching mcc(confusion_matrix) ## additional performance metrics ## below
The mcc.factor() method calls cmatrix() internally, so explicitly invoking mcc.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## Generic S3 method ## for Matthews Correlation Coefficient mcc(...) ## Generic S3 method ## for weighted Matthews Correlation Coefficient weighted.mcc(...)## Generic S3 method ## for Matthews Correlation Coefficient mcc(...) ## Generic S3 method ## for weighted Matthews Correlation Coefficient weighted.mcc(...)
... |
Arguments passed on to |
A <double>-value
The Matthews Correlation Coefficient has other names depending on research field:
-coefficient, phi()
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::mcc( actual = actual_classes, predicted = predicted_classes )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::mcc( actual = actual_classes, predicted = predicted_classes )
A generic S3 function to compute the matthews correlation coefficient score for a classification model. This function dispatches to S3 methods in mcc() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because mcc() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap mcc() in a "safe" validator that checks for NA values and matching length, for example:
safe_mcc <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
mcc(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate matthews correlation coefficient ## via S3 dispatching mcc(confusion_matrix) ## additional performance metrics ## below
The mcc.factor() method calls cmatrix() internally, so explicitly invoking mcc.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## S3 method for class 'cmatrix' mcc(x, ...)## S3 method for class 'cmatrix' mcc(x, ...)
x |
A confusion matrix created |
... |
Arguments passed into other methods. |
A <double>-value
The Matthews Correlation Coefficient has other names depending on research field:
-coefficient, phi()
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Construct confusion ## matrix confusion_matrix <- SLmetrics::cmatrix( actual = actual_classes, predicted = predicted_classes ) ## Evaluate performance SLmetrics::mcc(confusion_matrix)## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Construct confusion ## matrix confusion_matrix <- SLmetrics::cmatrix( actual = actual_classes, predicted = predicted_classes ) ## Evaluate performance SLmetrics::mcc(confusion_matrix)
A generic S3 function to compute the matthews correlation coefficient score for a classification model. This function dispatches to S3 methods in mcc() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because mcc() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap mcc() in a "safe" validator that checks for NA values and matching length, for example:
safe_mcc <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
mcc(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate matthews correlation coefficient ## via S3 dispatching mcc(confusion_matrix) ## additional performance metrics ## below
The mcc.factor() method calls cmatrix() internally, so explicitly invoking mcc.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## S3 method for class 'factor' mcc(actual, predicted, ...)## S3 method for class 'factor' mcc(actual, predicted, ...)
actual, predicted
|
A pair of <integer> or <factor> vectors of length |
... |
Arguments passed into other methods. |
A <double>-value
The Matthews Correlation Coefficient has other names depending on research field:
-coefficient, phi()
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::mcc( actual = actual_classes, predicted = predicted_classes )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::mcc( actual = actual_classes, predicted = predicted_classes )
A generic S3 function to compute the mean percentage error score for a regression model. This function dispatches to S3 methods in mpe() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because mpe() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap mpe() in a "safe" validator that checks for NA values and matching length, for example:
safe_mpe <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
mpe(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## Generic S3 method ## for Mean Percentage Error mpe(...) ## Generic S3 method ## for weighted Mean Percentage Error weighted.mpe(...)## Generic S3 method ## for Mean Percentage Error mpe(...) ## Generic S3 method ## for weighted Mean Percentage Error weighted.mpe(...)
... |
Arguments passed on to |
A <double> value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Virtanen, Pauli, et al. "SciPy 1.0: fundamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Other Regression:
ccc(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
gmse(),
huberloss(),
maape(),
mae(),
mape(),
mse(),
pinball(),
rae(),
rmse(),
rmsle(),
rrmse(),
rrse(),
rsq(),
smape()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::mpe( actual = actual_values, predicted = predicted_values )## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::mpe( actual = actual_values, predicted = predicted_values )
A generic S3 function to compute the mean percentage error score for a regression model. This function dispatches to S3 methods in mpe() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because mpe() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap mpe() in a "safe" validator that checks for NA values and matching length, for example:
safe_mpe <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
mpe(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## S3 method for class 'numeric' mpe(actual, predicted, ...)## S3 method for class 'numeric' mpe(actual, predicted, ...)
actual, predicted
|
|
... |
Arguments passed into other methods |
A <double> value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Virtanen, Pauli, et al. "SciPy 1.0: fundamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Regression:
ccc(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
gmse(),
huberloss(),
maape(),
mae(),
mape(),
mse(),
pinball(),
rae(),
rmse(),
rmsle(),
rrmse(),
rrse(),
rsq(),
smape()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::mpe( actual = actual_values, predicted = predicted_values )## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::mpe( actual = actual_values, predicted = predicted_values )
A generic S3 function to compute the mean squared error score for a regression model. This function dispatches to S3 methods in mse() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because mse() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap mse() in a "safe" validator that checks for NA values and matching length, for example:
safe_mse <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
mse(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## Generic S3 method ## for Mean Squared Error mse(...) ## Generic S3 method ## for weighted Mean Squared Error weighted.mse(...)## Generic S3 method ## for Mean Squared Error mse(...) ## Generic S3 method ## for weighted Mean Squared Error weighted.mse(...)
... |
Arguments passed on to |
A <double> value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Virtanen, Pauli, et al. "SciPy 1.0: fundamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Other Regression:
ccc(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
gmse(),
huberloss(),
maape(),
mae(),
mape(),
mpe(),
pinball(),
rae(),
rmse(),
rmsle(),
rrmse(),
rrse(),
rsq(),
smape()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::mse( actual = actual_values, predicted = predicted_values )## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::mse( actual = actual_values, predicted = predicted_values )
A generic S3 function to compute the mean squared error score for a regression model. This function dispatches to S3 methods in mse() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because mse() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap mse() in a "safe" validator that checks for NA values and matching length, for example:
safe_mse <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
mse(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## S3 method for class 'numeric' mse(actual, predicted, ...)## S3 method for class 'numeric' mse(actual, predicted, ...)
actual, predicted
|
|
... |
Arguments passed into other methods |
A <double> value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Virtanen, Pauli, et al. "SciPy 1.0: fundamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Regression:
ccc(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
gmse(),
huberloss(),
maape(),
mae(),
mape(),
mpe(),
pinball(),
rae(),
rmse(),
rmsle(),
rrmse(),
rrse(),
rsq(),
smape()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::mse( actual = actual_values, predicted = predicted_values )## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::mse( actual = actual_values, predicted = predicted_values )
A generic S3 function to compute the negative likelihood ratio score for a classification model. This function dispatches to S3 methods in nlr() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because nlr() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap nlr() in a "safe" validator that checks for NA values and matching length, for example:
safe_nlr <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
nlr(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate negative likelihood ratio ## via S3 dispatching nlr(confusion_matrix) ## additional performance metrics ## below
The nlr.factor() method calls cmatrix() internally, so explicitly invoking nlr.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## Generic S3 method ## for Negative Likelihood Ratio nlr(...) ## Generic S3 method ## for weighted Negative Likelihood Ratio weighted.nlr(...)## Generic S3 method ## for Negative Likelihood Ratio nlr(...) ## Generic S3 method ## for weighted Negative Likelihood Ratio weighted.nlr(...)
... |
Arguments passed on to |
A <double>-value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
The plr()-function for the Positive Likehood Ratio (LR+)
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::nlr( actual = actual_classes, predicted = predicted_classes )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::nlr( actual = actual_classes, predicted = predicted_classes )
A generic S3 function to compute the negative likelihood ratio score for a classification model. This function dispatches to S3 methods in nlr() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because nlr() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap nlr() in a "safe" validator that checks for NA values and matching length, for example:
safe_nlr <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
nlr(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate negative likelihood ratio ## via S3 dispatching nlr(confusion_matrix) ## additional performance metrics ## below
The nlr.factor() method calls cmatrix() internally, so explicitly invoking nlr.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## S3 method for class 'cmatrix' nlr(x, ...)## S3 method for class 'cmatrix' nlr(x, ...)
x |
A confusion matrix created |
... |
Arguments passed into other methods. |
A <double>-value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
The plr()-function for the Positive Likehood Ratio (LR+)
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Construct confusion ## matrix confusion_matrix <- SLmetrics::cmatrix( actual = actual_classes, predicted = predicted_classes ) ## Evaluate performance SLmetrics::nlr(confusion_matrix)## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Construct confusion ## matrix confusion_matrix <- SLmetrics::cmatrix( actual = actual_classes, predicted = predicted_classes ) ## Evaluate performance SLmetrics::nlr(confusion_matrix)
A generic S3 function to compute the negative likelihood ratio score for a classification model. This function dispatches to S3 methods in nlr() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because nlr() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap nlr() in a "safe" validator that checks for NA values and matching length, for example:
safe_nlr <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
nlr(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate negative likelihood ratio ## via S3 dispatching nlr(confusion_matrix) ## additional performance metrics ## below
The nlr.factor() method calls cmatrix() internally, so explicitly invoking nlr.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## S3 method for class 'factor' nlr(actual, predicted, ...)## S3 method for class 'factor' nlr(actual, predicted, ...)
actual, predicted
|
A pair of <integer> or <factor> vectors of length |
... |
Arguments passed into other methods. |
A <double>-value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
The plr()-function for the Positive Likehood Ratio (LR+)
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::nlr( actual = actual_classes, predicted = predicted_classes )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::nlr( actual = actual_classes, predicted = predicted_classes )
A generic S3 function to compute the negative predictive value score for a classification model. This function dispatches to S3 methods in npv() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because npv() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap npv() in a "safe" validator that checks for NA values and matching length, for example:
safe_npv <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
npv(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate negative predictive value ## via S3 dispatching npv(confusion_matrix) ## additional performance metrics ## below
The npv.factor() method calls cmatrix() internally, so explicitly invoking npv.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## Generic S3 method ## for Negative Predictive Value npv(...) ## Generic S3 method ## for weighted Negative Predictive Value weighted.npv(...)## Generic S3 method ## for Negative Predictive Value npv(...) ## Generic S3 method ## for weighted Negative Predictive Value weighted.npv(...)
... |
Arguments passed on to
|
If estimator is given as
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::npv( actual = actual_classes, predicted = predicted_classes )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::npv( actual = actual_classes, predicted = predicted_classes )
A generic S3 function to compute the negative predictive value score for a classification model. This function dispatches to S3 methods in npv() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because npv() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap npv() in a "safe" validator that checks for NA values and matching length, for example:
safe_npv <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
npv(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate negative predictive value ## via S3 dispatching npv(confusion_matrix) ## additional performance metrics ## below
The npv.factor() method calls cmatrix() internally, so explicitly invoking npv.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## S3 method for class 'cmatrix' npv(x, estimator = 0L, na.rm = TRUE, ...)## S3 method for class 'cmatrix' npv(x, estimator = 0L, na.rm = TRUE, ...)
x |
A confusion matrix created |
estimator |
|
na.rm |
A <logical> value of length |
... |
Arguments passed into other methods. |
If estimator is given as
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Construct confusion ## matrix confusion_matrix <- SLmetrics::cmatrix( actual = actual_classes, predicted = predicted_classes ) ## Evaluate performance SLmetrics::npv(confusion_matrix)## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Construct confusion ## matrix confusion_matrix <- SLmetrics::cmatrix( actual = actual_classes, predicted = predicted_classes ) ## Evaluate performance SLmetrics::npv(confusion_matrix)
A generic S3 function to compute the negative predictive value score for a classification model. This function dispatches to S3 methods in npv() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because npv() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap npv() in a "safe" validator that checks for NA values and matching length, for example:
safe_npv <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
npv(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate negative predictive value ## via S3 dispatching npv(confusion_matrix) ## additional performance metrics ## below
The npv.factor() method calls cmatrix() internally, so explicitly invoking npv.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## S3 method for class 'factor' npv(actual, predicted, estimator = 0L, na.rm = TRUE, ...)## S3 method for class 'factor' npv(actual, predicted, estimator = 0L, na.rm = TRUE, ...)
actual, predicted
|
A pair of <integer> or <factor> vectors of length |
estimator |
|
na.rm |
A <logical> value of length |
... |
Arguments passed into other methods. |
If estimator is given as
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::npv( actual = actual_classes, predicted = predicted_classes )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::npv( actual = actual_classes, predicted = predicted_classes )
This dataset is used to estimate obesity levels based on eating habits and physical condition. The data originates from the UCI Machine Learning Repository and has been preprocessed to include both predictors and a target variable.
The dataset is provided as a list with two components:
A data frame containing various predictors related to lifestyle, eating habits, and physical condition. The variables include:
The age of the individual in years.
The height of the individual in meters.
Binary variable indicating whether the individual has a family history of overweight (1 = yes, 0 = no).
Binary variable indicating whether the individual frequently consumes high-calorie foods (1 = yes, 0 = no).
The frequency of consumption of vegetables in meals.
The number of main meals consumed per day.
Categorical variable indicating the frequency of consumption of food between meals.
Typical levels include "no", "sometimes", "frequently", and "always".
Binary variable indicating whether the individual smokes (1 = yes, 0 = no).
Daily water consumption (typically in liters).
Binary variable indicating whether the individual monitors calorie consumption (1 = yes, 0 = no).
The frequency of physical activity.
The time spent using electronic devices (e.g., screen time in hours).
Categorical variable indicating the frequency of alcohol consumption.
Typical levels include "no", "sometimes", "frequently", and "always".
Binary variable indicating the gender of the individual (1 = male, 0 = female).
A list containing two elements:
A numeric vector representing the weight of the individual (used as the regression target).
A factor indicating the obesity level classification. The levels are derived from the original nobeyesdad variable in the dataset.
data(obesity)data(obesity)
A list with two components:
A data frame containing various predictors related to eating habits, physical condition, and lifestyle.
A list with two elements: regression (weight in kilograms) and class (obesity level classification).
Palechor, Fabio Mendoza, and Alexis De la Hoz Manotas. "Dataset for estimation of obesity levels based on eating habits and physical condition in individuals from Colombia, Peru and Mexico." Data in brief 25 (2019): 104344.
Enable or disable OpenMP parallelization for computations.
This toggle is a brute-force implementation and does not guard against data races or nested parallel regions. Nested OpenMP regions can introduce subtle race conditions if multiple layers of parallelism access shared data concurrently. If you combine this package’s OpenMP switch with other parallel machine-learning routines, you may encounter undefined behavior.
## enable OpenMP openmp.on() ## disable OpenMP openmp.off() ## set number of threads openmp.threads(threads)## enable OpenMP openmp.on() ## disable OpenMP openmp.off() ## set number of threads openmp.threads(threads)
threads |
A positive <integer>-value (Default: None). If |
If OpenMP is unavailable, the function returns NULL.
## Not run: ## enable OpenMP SLmetrics::openmp.on() ## disable OpenMP SLmetrics::openmp.off() ## available threads SLmetrics::openmp.threads() ## set number of threads SLmetrics::openmp.threads(2) ## End(Not run)## Not run: ## enable OpenMP SLmetrics::openmp.on() ## disable OpenMP SLmetrics::openmp.off() ## available threads SLmetrics::openmp.threads() ## set number of threads SLmetrics::openmp.threads(2) ## End(Not run)
A generic S3 function to compute the pinball loss score for a regression model. This function dispatches to S3 methods in pinball() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because pinball() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap pinball() in a "safe" validator that checks for NA values and matching length, for example:
safe_pinball <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
pinball(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## Generic S3 method ## for Pinball Loss pinball(...) ## Generic S3 method ## for weighted Pinball Loss weighted.pinball(...)## Generic S3 method ## for Pinball Loss pinball(...) ## Generic S3 method ## for weighted Pinball Loss weighted.pinball(...)
... |
Arguments passed on to |
A <double> value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Virtanen, Pauli, et al. "SciPy 1.0: fundamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Other Regression:
ccc(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
gmse(),
huberloss(),
maape(),
mae(),
mape(),
mpe(),
mse(),
rae(),
rmse(),
rmsle(),
rrmse(),
rrse(),
rsq(),
smape()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::pinball( actual = actual_values, predicted = predicted_values )## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::pinball( actual = actual_values, predicted = predicted_values )
A generic S3 function to compute the pinball loss score for a regression model. This function dispatches to S3 methods in pinball() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because pinball() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap pinball() in a "safe" validator that checks for NA values and matching length, for example:
safe_pinball <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
pinball(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## S3 method for class 'numeric' pinball(actual, predicted, alpha = 0.5, deviance = FALSE, ...)## S3 method for class 'numeric' pinball(actual, predicted, alpha = 0.5, deviance = FALSE, ...)
actual, predicted
|
|
alpha |
A <double>-value of length |
deviance |
A <logical>-value of length 1 (default: FALSE). If TRUE the function returns the |
... |
Arguments passed into other methods |
A <double> value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Virtanen, Pauli, et al. "SciPy 1.0: fundamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Regression:
ccc(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
gmse(),
huberloss(),
maape(),
mae(),
mape(),
mpe(),
mse(),
rae(),
rmse(),
rmsle(),
rrmse(),
rrse(),
rsq(),
smape()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::pinball( actual = actual_values, predicted = predicted_values )## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::pinball( actual = actual_values, predicted = predicted_values )
A generic S3 function to compute the positive likelihood ratio score for a classification model. This function dispatches to S3 methods in plr() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because plr() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap plr() in a "safe" validator that checks for NA values and matching length, for example:
safe_plr <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
plr(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate positive likelihood ratio ## via S3 dispatching plr(confusion_matrix) ## additional performance metrics ## below
The plr.factor() method calls cmatrix() internally, so explicitly invoking plr.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## Generic S3 method ## for Positive Likelihood Ratio plr(...) ## Generic S3 method ## for weighted Positive Likelihood Ratio weighted.plr(...) ## Generic S3 method ## for weighted Diagnostic Odds Ratio weighted.plr(...)## Generic S3 method ## for Positive Likelihood Ratio plr(...) ## Generic S3 method ## for weighted Positive Likelihood Ratio weighted.plr(...) ## Generic S3 method ## for weighted Diagnostic Odds Ratio weighted.plr(...)
... |
Arguments passed on to |
A <double>-value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
The nlr()-function for the Negative Likehood Ratio (LR-)
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::plr( actual = actual_classes, predicted = predicted_classes )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::plr( actual = actual_classes, predicted = predicted_classes )
A generic S3 function to compute the positive likelihood ratio score for a classification model. This function dispatches to S3 methods in plr() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because plr() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap plr() in a "safe" validator that checks for NA values and matching length, for example:
safe_plr <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
plr(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate positive likelihood ratio ## via S3 dispatching plr(confusion_matrix) ## additional performance metrics ## below
The plr.factor() method calls cmatrix() internally, so explicitly invoking plr.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## S3 method for class 'cmatrix' plr(x, ...)## S3 method for class 'cmatrix' plr(x, ...)
x |
A confusion matrix created |
... |
Arguments passed into other methods. |
A <double>-value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
The nlr()-function for the Negative Likehood Ratio (LR-)
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Construct confusion ## matrix confusion_matrix <- SLmetrics::cmatrix( actual = actual_classes, predicted = predicted_classes ) ## Evaluate performance SLmetrics::plr(confusion_matrix)## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Construct confusion ## matrix confusion_matrix <- SLmetrics::cmatrix( actual = actual_classes, predicted = predicted_classes ) ## Evaluate performance SLmetrics::plr(confusion_matrix)
A generic S3 function to compute the positive likelihood ratio score for a classification model. This function dispatches to S3 methods in plr() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because plr() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap plr() in a "safe" validator that checks for NA values and matching length, for example:
safe_plr <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
plr(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate positive likelihood ratio ## via S3 dispatching plr(confusion_matrix) ## additional performance metrics ## below
The plr.factor() method calls cmatrix() internally, so explicitly invoking plr.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## S3 method for class 'factor' plr(actual, predicted, ...)## S3 method for class 'factor' plr(actual, predicted, ...)
actual, predicted
|
A pair of <integer> or <factor> vectors of length |
... |
Arguments passed into other methods. |
A <double>-value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
The nlr()-function for the Negative Likehood Ratio (LR-)
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::plr( actual = actual_classes, predicted = predicted_classes )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::plr( actual = actual_classes, predicted = predicted_classes )
A generic S3 function to compute the precision recall curve score for a classification model. This function dispatches to S3 methods in pr.curve() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because pr.curve() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap pr.curve() in a "safe" validator that checks for NA values and matching length, for example:
safe_pr.curve <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
pr.curve(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
Use auc.pr.curve for calculating the area under the curve directly.
To avoid sorting the same probability matrix multiple times (once per class or curve), you can precompute a single set of sort indices and pass it via the indices argument. This reduces the overall cost from O(K·N log N) to O(N log N + K·N).
## presort response ## probabilities indices <- preorder(response, decreasing = TRUE) ## evaluate precision recall curve pr.curve(actual, response, indices = indices)
## Generic S3 method ## for Precision Recall Curve pr.curve(...) ## Generic S3 method ## for weighted Precision Recall Curve weighted.pr.curve(...)## Generic S3 method ## for Precision Recall Curve pr.curve(...) ## Generic S3 method ## for weighted Precision Recall Curve weighted.pr.curve(...)
... |
Arguments passed on to
|
A data.frame on the following form,
threshold |
<numeric> Thresholds used to determine |
level |
|
label |
|
recall |
<numeric> The recall |
precision |
<numeric> The precision |
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual classes ## and response probabilities actual_classes <- factor( x = sample( x = classes, size = 1e2, replace = TRUE, prob = c(0.7, 0.3) ) ) response_probabilities <- ifelse( actual_classes == "Kebab", rbeta(sum(actual_classes == "Kebab"), 2, 5), rbeta(sum(actual_classes == "Falafel"), 5, 2) ) ## Construct response ## matrix probability_matrix <- cbind( response_probabilities, 1 - response_probabilities ) ## Visualize precision recall curve plot( SLmetrics::pr.curve( actual = actual_classes, response = probability_matrix ) )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual classes ## and response probabilities actual_classes <- factor( x = sample( x = classes, size = 1e2, replace = TRUE, prob = c(0.7, 0.3) ) ) response_probabilities <- ifelse( actual_classes == "Kebab", rbeta(sum(actual_classes == "Kebab"), 2, 5), rbeta(sum(actual_classes == "Falafel"), 5, 2) ) ## Construct response ## matrix probability_matrix <- cbind( response_probabilities, 1 - response_probabilities ) ## Visualize precision recall curve plot( SLmetrics::pr.curve( actual = actual_classes, response = probability_matrix ) )
A generic S3 function to compute the precision recall curve score for a classification model. This function dispatches to S3 methods in pr.curve() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because pr.curve() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap pr.curve() in a "safe" validator that checks for NA values and matching length, for example:
safe_pr.curve <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
pr.curve(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
Use auc.pr.curve for calculating the area under the curve directly.
To avoid sorting the same probability matrix multiple times (once per class or curve), you can precompute a single set of sort indices and pass it via the indices argument. This reduces the overall cost from O(K·N log N) to O(N log N + K·N).
## presort response ## probabilities indices <- preorder(response, decreasing = TRUE) ## evaluate precision recall curve pr.curve(actual, response, indices = indices)
## S3 method for class 'factor' pr.curve(actual, response, thresholds = NULL, indices = NULL, ...)## S3 method for class 'factor' pr.curve(actual, response, thresholds = NULL, indices = NULL, ...)
actual |
|
response |
A |
thresholds |
|
indices |
An optional |
... |
Arguments passed into other methods. |
A data.frame on the following form,
threshold |
<numeric> Thresholds used to determine |
level |
|
label |
|
recall |
<numeric> The recall |
precision |
<numeric> The precision |
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual classes ## and response probabilities actual_classes <- factor( x = sample( x = classes, size = 1e2, replace = TRUE, prob = c(0.7, 0.3) ) ) response_probabilities <- ifelse( actual_classes == "Kebab", rbeta(sum(actual_classes == "Kebab"), 2, 5), rbeta(sum(actual_classes == "Falafel"), 5, 2) ) ## Construct response ## matrix probability_matrix <- cbind( response_probabilities, 1 - response_probabilities ) ## Visualize plot( SLmetrics::pr.curve( actual = actual_classes, response = probability_matrix ) )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual classes ## and response probabilities actual_classes <- factor( x = sample( x = classes, size = 1e2, replace = TRUE, prob = c(0.7, 0.3) ) ) response_probabilities <- ifelse( actual_classes == "Kebab", rbeta(sum(actual_classes == "Kebab"), 2, 5), rbeta(sum(actual_classes == "Falafel"), 5, 2) ) ## Construct response ## matrix probability_matrix <- cbind( response_probabilities, 1 - response_probabilities ) ## Visualize plot( SLmetrics::pr.curve( actual = actual_classes, response = probability_matrix ) )
A generic S3 function to compute the precision score for a classification model. This function dispatches to S3 methods in precision() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because precision() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap precision() in a "safe" validator that checks for NA values and matching length, for example:
safe_precision <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
precision(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate precision ## via S3 dispatching precision(confusion_matrix) ## additional performance metrics ## below
The precision.factor() method calls cmatrix() internally, so explicitly invoking precision.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## Generic S3 method ## for Precision precision(...) ## Generic S3 method ## for weighted Precision weighted.precision(...)## Generic S3 method ## for Precision precision(...) ## Generic S3 method ## for weighted Precision weighted.precision(...)
... |
Arguments passed on to
|
If estimator is given as
The precision has other names depending on research field:
Positive Predictive Value, ppv()
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::precision( actual = actual_classes, predicted = predicted_classes )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::precision( actual = actual_classes, predicted = predicted_classes )
A generic S3 function to compute the precision score for a classification model. This function dispatches to S3 methods in precision() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because precision() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap precision() in a "safe" validator that checks for NA values and matching length, for example:
safe_precision <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
precision(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate precision ## via S3 dispatching precision(confusion_matrix) ## additional performance metrics ## below
The precision.factor() method calls cmatrix() internally, so explicitly invoking precision.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## S3 method for class 'cmatrix' precision(x, estimator = 0L, na.rm = TRUE, ...)## S3 method for class 'cmatrix' precision(x, estimator = 0L, na.rm = TRUE, ...)
x |
A confusion matrix created |
estimator |
|
na.rm |
A <logical> value of length |
... |
Arguments passed into other methods. |
If estimator is given as
The precision has other names depending on research field:
Positive Predictive Value, ppv()
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Construct confusion ## matrix confusion_matrix <- SLmetrics::cmatrix( actual = actual_classes, predicted = predicted_classes ) ## Evaluate performance SLmetrics::precision(confusion_matrix)## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Construct confusion ## matrix confusion_matrix <- SLmetrics::cmatrix( actual = actual_classes, predicted = predicted_classes ) ## Evaluate performance SLmetrics::precision(confusion_matrix)
A generic S3 function to compute the precision score for a classification model. This function dispatches to S3 methods in precision() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because precision() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap precision() in a "safe" validator that checks for NA values and matching length, for example:
safe_precision <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
precision(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate precision ## via S3 dispatching precision(confusion_matrix) ## additional performance metrics ## below
The precision.factor() method calls cmatrix() internally, so explicitly invoking precision.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## S3 method for class 'factor' precision(actual, predicted, estimator = 0L, na.rm = TRUE, ...)## S3 method for class 'factor' precision(actual, predicted, estimator = 0L, na.rm = TRUE, ...)
actual, predicted
|
A pair of <integer> or <factor> vectors of length |
estimator |
|
na.rm |
A <logical> value of length |
... |
Arguments passed into other methods. |
If estimator is given as
The precision has other names depending on research field:
Positive Predictive Value, ppv()
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::precision( actual = actual_classes, predicted = predicted_classes )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::precision( actual = actual_classes, predicted = predicted_classes )
A generic S3 function for somehting long. This function dispatches to S3 methods in preorder() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because preorder() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap preorder() in a “safe” validator that checks for NA values and matching length, for example:
safe_preorder <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
preorder(x, y, ...)
}
## Generic S3 method ## for Preorder Matrices preorder(...)## Generic S3 method ## for Preorder Matrices preorder(...)
... |
Arguments passed on to |
A container of sorted indices
Other Utilities:
presort()
A generic S3 function for somehting long. This function dispatches to S3 methods in preorder() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because preorder() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap preorder() in a “safe” validator that checks for NA values and matching length, for example:
safe_preorder <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
preorder(x, y, ...)
}
## S3 method for class 'matrix' preorder(x, decreasing = FALSE, ...)## S3 method for class 'matrix' preorder(x, decreasing = FALSE, ...)
x |
A <matrix> to be sorted |
decreasing |
A <logical> |
... |
Arguments passed into other methods |
A <matrix> of same dimensions as the input <matrix>
Other Utilities:
presort()
A generic S3 function for somehting long. This function dispatches to S3 methods in presort() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because presort() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap presort() in a “safe” validator that checks for NA values and matching length, for example:
safe_presort <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
presort(x, y, ...)
}
## Generic S3 method ## for Presort Matrices presort(...)## Generic S3 method ## for Presort Matrices presort(...)
... |
Arguments passed on to |
A sorted container
Other Utilities:
preorder()
A generic S3 function for somehting long. This function dispatches to S3 methods in presort() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because presort() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap presort() in a “safe” validator that checks for NA values and matching length, for example:
safe_presort <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
presort(x, y, ...)
}
## S3 method for class 'matrix' presort(x, decreasing = FALSE, ...)## S3 method for class 'matrix' presort(x, decreasing = FALSE, ...)
x |
A <matrix> to be sorted |
decreasing |
A <logical> |
... |
Arguments passed into other methods |
A <matrix> of same dimensions as the input <matrix>
Other Utilities:
preorder()
A generic S3 function to compute the relative absolute error score for a regression model. This function dispatches to S3 methods in rae() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because rae() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap rae() in a "safe" validator that checks for NA values and matching length, for example:
safe_rae <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
rae(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## Generic S3 method ## for Relative Absolute Error rae(...) ## Generic S3 method ## for weighted Relative Absolute Error weighted.rae(...)## Generic S3 method ## for Relative Absolute Error rae(...) ## Generic S3 method ## for weighted Relative Absolute Error weighted.rae(...)
... |
Arguments passed on to |
A <double> value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Virtanen, Pauli, et al. "SciPy 1.0: fundamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Other Regression:
ccc(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
gmse(),
huberloss(),
maape(),
mae(),
mape(),
mpe(),
mse(),
pinball(),
rmse(),
rmsle(),
rrmse(),
rrse(),
rsq(),
smape()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::rae( actual = actual_values, predicted = predicted_values )## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::rae( actual = actual_values, predicted = predicted_values )
A generic S3 function to compute the relative absolute error score for a regression model. This function dispatches to S3 methods in rae() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because rae() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap rae() in a "safe" validator that checks for NA values and matching length, for example:
safe_rae <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
rae(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## S3 method for class 'numeric' rae(actual, predicted, ...)## S3 method for class 'numeric' rae(actual, predicted, ...)
actual, predicted
|
|
... |
Arguments passed into other methods |
A <double> value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Virtanen, Pauli, et al. "SciPy 1.0: fundamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Regression:
ccc(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
gmse(),
huberloss(),
maape(),
mae(),
mape(),
mpe(),
mse(),
pinball(),
rmse(),
rmsle(),
rrmse(),
rrse(),
rsq(),
smape()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::rae( actual = actual_values, predicted = predicted_values )## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::rae( actual = actual_values, predicted = predicted_values )
A generic S3 function to compute the recall score for a classification model. This function dispatches to S3 methods in recall() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because recall() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap recall() in a "safe" validator that checks for NA values and matching length, for example:
safe_recall <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
recall(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate recall ## via S3 dispatching recall(confusion_matrix) ## additional performance metrics ## below
The recall.factor() method calls cmatrix() internally, so explicitly invoking recall.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## Generic S3 method ## for Recall recall(...) ## Generic S3 method ## for weighted Recall weighted.recall(...)## Generic S3 method ## for Recall recall(...) ## Generic S3 method ## for weighted Recall weighted.recall(...)
... |
Arguments passed on to
|
If estimator is given as
The Recall has other names depending on research field:
Sensitivity, sensitivity()
True Positive Rate, tpr()
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::recall( actual = actual_classes, predicted = predicted_classes )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::recall( actual = actual_classes, predicted = predicted_classes )
A generic S3 function to compute the recall score for a classification model. This function dispatches to S3 methods in recall() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because recall() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap recall() in a "safe" validator that checks for NA values and matching length, for example:
safe_recall <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
recall(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate recall ## via S3 dispatching recall(confusion_matrix) ## additional performance metrics ## below
The recall.factor() method calls cmatrix() internally, so explicitly invoking recall.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## S3 method for class 'cmatrix' recall(x, estimator = 0L, na.rm = TRUE, ...)## S3 method for class 'cmatrix' recall(x, estimator = 0L, na.rm = TRUE, ...)
x |
A confusion matrix created |
estimator |
|
na.rm |
A <logical> value of length |
... |
Arguments passed into other methods. |
If estimator is given as
The Recall has other names depending on research field:
Sensitivity, sensitivity()
True Positive Rate, tpr()
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Construct confusion ## matrix confusion_matrix <- SLmetrics::cmatrix( actual = actual_classes, predicted = predicted_classes ) ## Evaluate performance SLmetrics::recall(confusion_matrix)## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Construct confusion ## matrix confusion_matrix <- SLmetrics::cmatrix( actual = actual_classes, predicted = predicted_classes ) ## Evaluate performance SLmetrics::recall(confusion_matrix)
A generic S3 function to compute the recall score for a classification model. This function dispatches to S3 methods in recall() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because recall() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap recall() in a "safe" validator that checks for NA values and matching length, for example:
safe_recall <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
recall(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate recall ## via S3 dispatching recall(confusion_matrix) ## additional performance metrics ## below
The recall.factor() method calls cmatrix() internally, so explicitly invoking recall.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## S3 method for class 'factor' recall(actual, predicted, estimator = 0L, na.rm = TRUE, ...)## S3 method for class 'factor' recall(actual, predicted, estimator = 0L, na.rm = TRUE, ...)
actual, predicted
|
A pair of <integer> or <factor> vectors of length |
estimator |
|
na.rm |
A <logical> value of length |
... |
Arguments passed into other methods. |
If estimator is given as
The Recall has other names depending on research field:
Sensitivity, sensitivity()
True Positive Rate, tpr()
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::recall( actual = actual_classes, predicted = predicted_classes )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::recall( actual = actual_classes, predicted = predicted_classes )
A generic S3 function to compute the relative entropy score for a classification model. This function dispatches to S3 methods in relative.entropy() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because relative.entropy() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap relative.entropy() in a "safe" validator that checks for NA values and matching length, for example:
safe_relative.entropy <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
relative.entropy(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## Generic S3 method ## for Relative Entropy relative.entropy(...)## Generic S3 method ## for Relative Entropy relative.entropy(...)
... |
Arguments passed on to
|
A <double> value or vector:
A single <double> value (length 1) if dim == 0.
A <double> vector with length equal to the length of columns if dim == 1.
A <double> vector with length equal to the length of rows if dim == 2.
MacKay, David JC. Information theory, inference and learning algorithms. Cambridge university press, 2003.
Kramer, Oliver, and Oliver Kramer. "Scikit-learn." Machine learning for evolution strategies (2016): 45-53.
Virtanen, Pauli, et al. "SciPy 1.0: f'undamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
Other Entropy:
cross.entropy(),
logloss(),
shannon.entropy()
## generate valid probability ## distributions rand.sum <- function(n) { x <- sort(runif( n-1 )) c(x,1) - c(0, x) } ## empirical and ## predicted probabilites set.seed(1903) pk <- t(replicate(200,rand.sum(5))) qk <- t(replicate(200,rand.sum(5))) ## entropy relative.entropy( pk = pk, qk = qk )## generate valid probability ## distributions rand.sum <- function(n) { x <- sort(runif( n-1 )) c(x,1) - c(0, x) } ## empirical and ## predicted probabilites set.seed(1903) pk <- t(replicate(200,rand.sum(5))) qk <- t(replicate(200,rand.sum(5))) ## entropy relative.entropy( pk = pk, qk = qk )
A generic S3 function to compute the relative entropy score for a classification model. This function dispatches to S3 methods in relative.entropy() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because relative.entropy() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap relative.entropy() in a "safe" validator that checks for NA values and matching length, for example:
safe_relative.entropy <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
relative.entropy(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## S3 method for class 'matrix' relative.entropy(pk, qk, dim = 0L, normalize = FALSE, ...)## S3 method for class 'matrix' relative.entropy(pk, qk, dim = 0L, normalize = FALSE, ...)
pk, qk
|
A pair of <double> matrices of length |
dim |
An <integer> value of length 1 (Default: 0). Defines the dimension along which to calculate the entropy (0: total, 1: row-wise, 2: column-wise). |
normalize |
A <logical>-value (default: TRUE). If TRUE, the mean cross-entropy across all observations is returned; otherwise, the sum of cross-entropies is returned. |
... |
Arguments passed into other methods. |
A <double> value or vector:
A single <double> value (length 1) if dim == 0.
A <double> vector with length equal to the length of columns if dim == 1.
A <double> vector with length equal to the length of rows if dim == 2.
MacKay, David JC. Information theory, inference and learning algorithms. Cambridge university press, 2003.
Kramer, Oliver, and Oliver Kramer. "Scikit-learn." Machine learning for evolution strategies (2016): 45-53.
Virtanen, Pauli, et al. "SciPy 1.0: fundamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
Other Entropy:
cross.entropy(),
logloss(),
shannon.entropy()
## generate valid probability ## distributions rand.sum <- function(n) { x <- sort(runif( n-1 )) c(x,1) - c(0, x) } ## empirical and ## predicted probabilites set.seed(1903) pk <- t(replicate(200,rand.sum(5))) qk <- t(replicate(200,rand.sum(5))) ## entropy relative.entropy( pk = pk, qk = qk )## generate valid probability ## distributions rand.sum <- function(n) { x <- sort(runif( n-1 )) c(x,1) - c(0, x) } ## empirical and ## predicted probabilites set.seed(1903) pk <- t(replicate(200,rand.sum(5))) qk <- t(replicate(200,rand.sum(5))) ## entropy relative.entropy( pk = pk, qk = qk )
A generic S3 function to compute the root mean squared error score for a regression model. This function dispatches to S3 methods in rmse() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because rmse() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap rmse() in a "safe" validator that checks for NA values and matching length, for example:
safe_rmse <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
rmse(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## Generic S3 method ## for Root Mean Squared Error rmse(...) ## Generic S3 method ## for weighted Root Mean Squared Error weighted.rmse(...)## Generic S3 method ## for Root Mean Squared Error rmse(...) ## Generic S3 method ## for weighted Root Mean Squared Error weighted.rmse(...)
... |
Arguments passed on to |
A <double> value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Virtanen, Pauli, et al. "SciPy 1.0: fundamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Other Regression:
ccc(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
gmse(),
huberloss(),
maape(),
mae(),
mape(),
mpe(),
mse(),
pinball(),
rae(),
rmsle(),
rrmse(),
rrse(),
rsq(),
smape()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::rmse( actual = actual_values, predicted = predicted_values )## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::rmse( actual = actual_values, predicted = predicted_values )
A generic S3 function to compute the root mean squared error score for a regression model. This function dispatches to S3 methods in rmse() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because rmse() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap rmse() in a "safe" validator that checks for NA values and matching length, for example:
safe_rmse <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
rmse(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## S3 method for class 'numeric' rmse(actual, predicted, ...)## S3 method for class 'numeric' rmse(actual, predicted, ...)
actual, predicted
|
|
... |
Arguments passed into other methods |
A <double> value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Virtanen, Pauli, et al. "SciPy 1.0: fundamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Regression:
ccc(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
gmse(),
huberloss(),
maape(),
mae(),
mape(),
mpe(),
mse(),
pinball(),
rae(),
rmsle(),
rrmse(),
rrse(),
rsq(),
smape()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::rmse( actual = actual_values, predicted = predicted_values )## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::rmse( actual = actual_values, predicted = predicted_values )
A generic S3 function to compute the root mean squared logarithmic error score for a regression model. This function dispatches to S3 methods in rmsle() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because rmsle() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap rmsle() in a "safe" validator that checks for NA values and matching length, for example:
safe_rmsle <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
rmsle(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## Generic S3 method ## for Root Mean Squared Logarithmic Error rmsle(...) ## Generic S3 method ## for weighted Root Mean Squared Logarithmic Error weighted.rmsle(...)## Generic S3 method ## for Root Mean Squared Logarithmic Error rmsle(...) ## Generic S3 method ## for weighted Root Mean Squared Logarithmic Error weighted.rmsle(...)
... |
Arguments passed on to |
A <double> value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Virtanen, Pauli, et al. "SciPy 1.0: fundamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Other Regression:
ccc(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
gmse(),
huberloss(),
maape(),
mae(),
mape(),
mpe(),
mse(),
pinball(),
rae(),
rmse(),
rrmse(),
rrse(),
rsq(),
smape()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::rmsle( actual = actual_values, predicted = predicted_values )## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::rmsle( actual = actual_values, predicted = predicted_values )
A generic S3 function to compute the root mean squared logarithmic error score for a regression model. This function dispatches to S3 methods in rmsle() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because rmsle() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap rmsle() in a "safe" validator that checks for NA values and matching length, for example:
safe_rmsle <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
rmsle(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## S3 method for class 'numeric' rmsle(actual, predicted, ...)## S3 method for class 'numeric' rmsle(actual, predicted, ...)
actual, predicted
|
|
... |
Arguments passed into other methods |
A <double> value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Virtanen, Pauli, et al. "SciPy 1.0: fundamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Regression:
ccc(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
gmse(),
huberloss(),
maape(),
mae(),
mape(),
mpe(),
mse(),
pinball(),
rae(),
rmse(),
rrmse(),
rrse(),
rsq(),
smape()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::rmsle( actual = actual_values, predicted = predicted_values )## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::rmsle( actual = actual_values, predicted = predicted_values )
A generic S3 function to compute the reciever operator characteristics score for a classification model. This function dispatches to S3 methods in roc.curve() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because roc.curve() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap roc.curve() in a "safe" validator that checks for NA values and matching length, for example:
safe_roc.curve <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
roc.curve(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
Use auc.roc.curve for calculating the area under the curve directly.
To avoid sorting the same probability matrix multiple times (once per class or curve), you can precompute a single set of sort indices and pass it via the indices argument. This reduces the overall cost from O(K·N log N) to O(N log N + K·N).
## presort response ## probabilities indices <- preorder(response, decreasing = TRUE) ## evaluate reciever operator characteristics roc.curve(actual, response, indices = indices)
## Generic S3 method ## for Reciever Operator Characteristics roc.curve(...) ## Generic S3 method ## for weighted Reciever Operator Characteristics weighted.roc.curve(...)## Generic S3 method ## for Reciever Operator Characteristics roc.curve(...) ## Generic S3 method ## for weighted Reciever Operator Characteristics weighted.roc.curve(...)
... |
Arguments passed on to
|
A data.frame on the following form,
threshold |
|
level |
|
label |
|
fpr |
<numeric> The false positive rate |
tpr |
<numeric> The true positve rate |
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual classes ## and response probabilities actual_classes <- factor( x = sample( x = classes, size = 1e2, replace = TRUE, prob = c(0.7, 0.3) ) ) response_probabilities <- ifelse( actual_classes == "Kebab", rbeta(sum(actual_classes == "Kebab"), 2, 5), rbeta(sum(actual_classes == "Falafel"), 5, 2) ) ## Construct response ## matrix probability_matrix <- cbind( response_probabilities, 1 - response_probabilities ) ## Visualize reciever operator characteristics plot( SLmetrics::roc.curve( actual = actual_classes, response = probability_matrix ) )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual classes ## and response probabilities actual_classes <- factor( x = sample( x = classes, size = 1e2, replace = TRUE, prob = c(0.7, 0.3) ) ) response_probabilities <- ifelse( actual_classes == "Kebab", rbeta(sum(actual_classes == "Kebab"), 2, 5), rbeta(sum(actual_classes == "Falafel"), 5, 2) ) ## Construct response ## matrix probability_matrix <- cbind( response_probabilities, 1 - response_probabilities ) ## Visualize reciever operator characteristics plot( SLmetrics::roc.curve( actual = actual_classes, response = probability_matrix ) )
A generic S3 function to compute the reciever operator characteristics score for a classification model. This function dispatches to S3 methods in roc.curve() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because roc.curve() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap roc.curve() in a "safe" validator that checks for NA values and matching length, for example:
safe_roc.curve <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
roc.curve(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
Use auc.roc.curve for calculating the area under the curve directly.
To avoid sorting the same probability matrix multiple times (once per class or curve), you can precompute a single set of sort indices and pass it via the indices argument. This reduces the overall cost from O(K·N log N) to O(N log N + K·N).
## presort response ## probabilities indices <- preorder(response, decreasing = TRUE) ## evaluate reciever operator characteristics roc.curve(actual, response, indices = indices)
## S3 method for class 'factor' roc.curve(actual, response, thresholds = NULL, indices = NULL, ...)## S3 method for class 'factor' roc.curve(actual, response, thresholds = NULL, indices = NULL, ...)
actual |
|
response |
A |
thresholds |
|
indices |
An optional |
... |
Arguments passed into other methods. |
A data.frame on the following form,
threshold |
|
level |
|
label |
|
fpr |
<numeric> The false positive rate |
tpr |
<numeric> The true positve rate |
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual classes ## and response probabilities actual_classes <- factor( x = sample( x = classes, size = 1e2, replace = TRUE, prob = c(0.7, 0.3) ) ) response_probabilities <- ifelse( actual_classes == "Kebab", rbeta(sum(actual_classes == "Kebab"), 2, 5), rbeta(sum(actual_classes == "Falafel"), 5, 2) ) ## Construct response ## matrix probability_matrix <- cbind( response_probabilities, 1 - response_probabilities ) ## Visualize plot( SLmetrics::roc.curve( actual = actual_classes, response = probability_matrix ) )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual classes ## and response probabilities actual_classes <- factor( x = sample( x = classes, size = 1e2, replace = TRUE, prob = c(0.7, 0.3) ) ) response_probabilities <- ifelse( actual_classes == "Kebab", rbeta(sum(actual_classes == "Kebab"), 2, 5), rbeta(sum(actual_classes == "Falafel"), 5, 2) ) ## Construct response ## matrix probability_matrix <- cbind( response_probabilities, 1 - response_probabilities ) ## Visualize plot( SLmetrics::roc.curve( actual = actual_classes, response = probability_matrix ) )
A generic S3 function to compute the relative root mean squared error score for a regression model. This function dispatches to S3 methods in rrmse() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because rrmse() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap rrmse() in a "safe" validator that checks for NA values and matching length, for example:
safe_rrmse <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
rrmse(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## Generic S3 method ## for Relative Root Mean Squared Error rrmse(...) ## Generic S3 method ## for weighted Concordance Correlation Coefficient weighted.rrmse(...)## Generic S3 method ## for Relative Root Mean Squared Error rrmse(...) ## Generic S3 method ## for weighted Concordance Correlation Coefficient weighted.rrmse(...)
... |
Arguments passed on to |
A <double> value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Virtanen, Pauli, et al. "SciPy 1.0: fundamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Other Regression:
ccc(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
gmse(),
huberloss(),
maape(),
mae(),
mape(),
mpe(),
mse(),
pinball(),
rae(),
rmse(),
rmsle(),
rrse(),
rsq(),
smape()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::rrmse( actual = actual_values, predicted = predicted_values )## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::rrmse( actual = actual_values, predicted = predicted_values )
A generic S3 function to compute the relative root mean squared error score for a regression model. This function dispatches to S3 methods in rrmse() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because rrmse() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap rrmse() in a "safe" validator that checks for NA values and matching length, for example:
safe_rrmse <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
rrmse(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## S3 method for class 'numeric' rrmse(actual, predicted, normalization = 1L, ...)## S3 method for class 'numeric' rrmse(actual, predicted, normalization = 1L, ...)
actual, predicted
|
|
normalization |
A <double>-value of length |
... |
Arguments passed into other methods |
A <double> value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Virtanen, Pauli, et al. "SciPy 1.0: fundamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Regression:
ccc(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
gmse(),
huberloss(),
maape(),
mae(),
mape(),
mpe(),
mse(),
pinball(),
rae(),
rmse(),
rmsle(),
rrse(),
rsq(),
smape()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::rrmse( actual = actual_values, predicted = predicted_values )## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::rrmse( actual = actual_values, predicted = predicted_values )
A generic S3 function to compute the root relative squared error score for a regression model. This function dispatches to S3 methods in rrse() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because rrse() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap rrse() in a "safe" validator that checks for NA values and matching length, for example:
safe_rrse <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
rrse(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## Generic S3 method ## for Root Relative Squared Error rrse(...) ## Generic S3 method ## for weighted Root Relative Squared Error weighted.rrse(...)## Generic S3 method ## for Root Relative Squared Error rrse(...) ## Generic S3 method ## for weighted Root Relative Squared Error weighted.rrse(...)
... |
Arguments passed on to |
A <double> value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Virtanen, Pauli, et al. "SciPy 1.0: fundamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Other Regression:
ccc(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
gmse(),
huberloss(),
maape(),
mae(),
mape(),
mpe(),
mse(),
pinball(),
rae(),
rmse(),
rmsle(),
rrmse(),
rsq(),
smape()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::rrse( actual = actual_values, predicted = predicted_values )## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::rrse( actual = actual_values, predicted = predicted_values )
A generic S3 function to compute the root relative squared error score for a regression model. This function dispatches to S3 methods in rrse() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because rrse() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap rrse() in a "safe" validator that checks for NA values and matching length, for example:
safe_rrse <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
rrse(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## S3 method for class 'numeric' rrse(actual, predicted, ...)## S3 method for class 'numeric' rrse(actual, predicted, ...)
actual, predicted
|
|
... |
Arguments passed into other methods |
A <double> value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Virtanen, Pauli, et al. "SciPy 1.0: fundamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Regression:
ccc(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
gmse(),
huberloss(),
maape(),
mae(),
mape(),
mpe(),
mse(),
pinball(),
rae(),
rmse(),
rmsle(),
rrmse(),
rsq(),
smape()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::rrse( actual = actual_values, predicted = predicted_values )## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::rrse( actual = actual_values, predicted = predicted_values )
A generic S3 function to compute the score for a regression model. This function dispatches to S3 methods in rsq() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because rsq() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap rsq() in a "safe" validator that checks for NA values and matching length, for example:
safe_rsq <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
rsq(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## Generic S3 method ## for \eqn{r^2} rsq(...) ## Generic S3 method ## for weighted \eqn{r^2} weighted.rsq(...)## Generic S3 method ## for \eqn{r^2} rsq(...) ## Generic S3 method ## for weighted \eqn{r^2} weighted.rsq(...)
... |
Arguments passed on to |
A <double> value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Virtanen, Pauli, et al. "SciPy 1.0: fundamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Other Regression:
ccc(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
gmse(),
huberloss(),
maape(),
mae(),
mape(),
mpe(),
mse(),
pinball(),
rae(),
rmse(),
rmsle(),
rrmse(),
rrse(),
smape()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::rsq( actual = actual_values, predicted = predicted_values )## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::rsq( actual = actual_values, predicted = predicted_values )
A generic S3 function to compute the score for a regression model. This function dispatches to S3 methods in rsq() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because rsq() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap rsq() in a "safe" validator that checks for NA values and matching length, for example:
safe_rsq <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
rsq(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## S3 method for class 'numeric' rsq(actual, predicted, k = 0, ...)## S3 method for class 'numeric' rsq(actual, predicted, k = 0, ...)
actual, predicted
|
|
k |
A <double>-vector of length 1 (default: 0). For adjusted |
... |
Arguments passed into other methods |
A <double> value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Virtanen, Pauli, et al. "SciPy 1.0: fundamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Regression:
ccc(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
gmse(),
huberloss(),
maape(),
mae(),
mape(),
mpe(),
mse(),
pinball(),
rae(),
rmse(),
rmsle(),
rrmse(),
rrse(),
smape()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::rsq( actual = actual_values, predicted = predicted_values )## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::rsq( actual = actual_values, predicted = predicted_values )
A generic S3 function to compute the shannon entropy score for a classification model. This function dispatches to S3 methods in shannon.entropy() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because shannon.entropy() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap shannon.entropy() in a "safe" validator that checks for NA values and matching length, for example:
safe_shannon.entropy <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
shannon.entropy(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## Generic S3 method ## for Shannon Entropy shannon.entropy(...)## Generic S3 method ## for Shannon Entropy shannon.entropy(...)
... |
Arguments passed on to
|
A <double> value or vector:
A single <double> value (length 1) if dim == 0.
A <double> vector with length equal to the length of columns if dim == 1.
A <double> vector with length equal to the length of rows if dim == 2.
MacKay, David JC. Information theory, inference and learning algorithms. Cambridge university press, 2003.
Kramer, Oliver, and Oliver Kramer. "Scikit-learn." Machine learning for evolution strategies (2016): 45-53.
Virtanen, Pauli, et al. "SciPy 1.0: f'undamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
smape(),
specificity(),
zerooneloss()
Other Entropy:
cross.entropy(),
logloss(),
relative.entropy()
## generate valid probability ## distributions rand.sum <- function(n) { x <- sort(runif( n-1 )) c(x,1) - c(0, x) } ## empirical and ## predicted probabilites set.seed(1903) pk <- t(replicate(200,rand.sum(5))) ## entropy SLmetrics::shannon.entropy( pk = pk )## generate valid probability ## distributions rand.sum <- function(n) { x <- sort(runif( n-1 )) c(x,1) - c(0, x) } ## empirical and ## predicted probabilites set.seed(1903) pk <- t(replicate(200,rand.sum(5))) ## entropy SLmetrics::shannon.entropy( pk = pk )
A generic S3 function to compute the shannon entropy score for a classification model. This function dispatches to S3 methods in shannon.entropy() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because shannon.entropy() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap shannon.entropy() in a "safe" validator that checks for NA values and matching length, for example:
safe_shannon.entropy <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
shannon.entropy(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## S3 method for class 'matrix' shannon.entropy(pk, dim = 0L, normalize = FALSE, ...)## S3 method for class 'matrix' shannon.entropy(pk, dim = 0L, normalize = FALSE, ...)
pk |
A |
dim |
An <integer> value of length 1 (Default: 0). Defines the dimension along which to calculate the entropy (0: total, 1: row-wise, 2: column-wise). |
normalize |
A <logical>-value (default: TRUE). If TRUE, the mean cross-entropy across all observations is returned; otherwise, the sum of cross-entropies is returned. |
... |
Arguments passed into other methods. |
A <double> value or vector:
A single <double> value (length 1) if dim == 0.
A <double> vector with length equal to the length of columns if dim == 1.
A <double> vector with length equal to the length of rows if dim == 2.
MacKay, David JC. Information theory, inference and learning algorithms. Cambridge university press, 2003.
Kramer, Oliver, and Oliver Kramer. "Scikit-learn." Machine learning for evolution strategies (2016): 45-53.
Virtanen, Pauli, et al. "SciPy 1.0: fundamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
smape(),
specificity(),
zerooneloss()
Other Entropy:
cross.entropy(),
logloss(),
relative.entropy()
## generate valid probability ## distributions rand.sum <- function(n) { x <- sort(runif( n-1 )) c(x,1) - c(0, x) } ## empirical and ## predicted probabilites set.seed(1903) pk <- t(replicate(200,rand.sum(5))) ## entropy SLmetrics::shannon.entropy( pk = pk )## generate valid probability ## distributions rand.sum <- function(n) { x <- sort(runif( n-1 )) c(x,1) - c(0, x) } ## empirical and ## predicted probabilites set.seed(1903) pk <- t(replicate(200,rand.sum(5))) ## entropy SLmetrics::shannon.entropy( pk = pk )
A generic S3 function to compute the symmetric mean absolutte percentage error score for a regression model. This function dispatches to S3 methods in smape() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because smape() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap smape() in a "safe" validator that checks for NA values and matching length, for example:
safe_smape <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
smape(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## Generic S3 method ## for Symmetric Mean Absolutte Percentage Error smape(...) ## Generic S3 method ## for weighted Symmetric Mean Absolutte Percentage Error weighted.smape(...)## Generic S3 method ## for Symmetric Mean Absolutte Percentage Error smape(...) ## Generic S3 method ## for weighted Symmetric Mean Absolutte Percentage Error weighted.smape(...)
... |
Arguments passed on to |
A <double> value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Virtanen, Pauli, et al. "SciPy 1.0: fundamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Other Regression:
ccc(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
gmse(),
huberloss(),
maape(),
mae(),
mape(),
mpe(),
mse(),
pinball(),
rae(),
rmse(),
rmsle(),
rrmse(),
rrse(),
rsq()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
specificity(),
zerooneloss()
## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::smape( actual = actual_values, predicted = predicted_values )## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::smape( actual = actual_values, predicted = predicted_values )
A generic S3 function to compute the symmetric mean absolutte percentage error score for a regression model. This function dispatches to S3 methods in smape() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because smape() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap smape() in a "safe" validator that checks for NA values and matching length, for example:
safe_smape <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
smape(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## S3 method for class 'numeric' smape(actual, predicted, ...)## S3 method for class 'numeric' smape(actual, predicted, ...)
actual, predicted
|
|
... |
Arguments passed into other methods |
A <double> value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Virtanen, Pauli, et al. "SciPy 1.0: fundamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Regression:
ccc(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
gmse(),
huberloss(),
maape(),
mae(),
mape(),
mpe(),
mse(),
pinball(),
rae(),
rmse(),
rmsle(),
rrmse(),
rrse(),
rsq()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
specificity(),
zerooneloss()
## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::smape( actual = actual_values, predicted = predicted_values )## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Evaluate performance SLmetrics::smape( actual = actual_values, predicted = predicted_values )
A generic S3 function to compute the specificity score for a classification model. This function dispatches to S3 methods in specificity() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because specificity() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap specificity() in a "safe" validator that checks for NA values and matching length, for example:
safe_specificity <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
specificity(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate specificity ## via S3 dispatching specificity(confusion_matrix) ## additional performance metrics ## below
The specificity.factor() method calls cmatrix() internally, so explicitly invoking specificity.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## Generic S3 method ## for Specificity specificity(...) ## Generic S3 method ## for weighted Specificity weighted.specificity(...)## Generic S3 method ## for Specificity specificity(...) ## Generic S3 method ## for weighted Specificity weighted.specificity(...)
... |
Arguments passed on to
|
If estimator is given as
The specificity has other names depending on research field:
True Negative Rate, tnr()
Selectivity, selectivity()
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::specificity( actual = actual_classes, predicted = predicted_classes )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::specificity( actual = actual_classes, predicted = predicted_classes )
A generic S3 function to compute the specificity score for a classification model. This function dispatches to S3 methods in specificity() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because specificity() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap specificity() in a "safe" validator that checks for NA values and matching length, for example:
safe_specificity <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
specificity(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate specificity ## via S3 dispatching specificity(confusion_matrix) ## additional performance metrics ## below
The specificity.factor() method calls cmatrix() internally, so explicitly invoking specificity.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## S3 method for class 'cmatrix' specificity(x, estimator = 0L, na.rm = TRUE, ...)## S3 method for class 'cmatrix' specificity(x, estimator = 0L, na.rm = TRUE, ...)
x |
A confusion matrix created |
estimator |
|
na.rm |
A <logical> value of length |
... |
Arguments passed into other methods. |
If estimator is given as
The specificity has other names depending on research field:
True Negative Rate, tnr()
Selectivity, selectivity()
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Construct confusion ## matrix confusion_matrix <- SLmetrics::cmatrix( actual = actual_classes, predicted = predicted_classes ) ## Evaluate performance SLmetrics::specificity(confusion_matrix)## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Construct confusion ## matrix confusion_matrix <- SLmetrics::cmatrix( actual = actual_classes, predicted = predicted_classes ) ## Evaluate performance SLmetrics::specificity(confusion_matrix)
A generic S3 function to compute the specificity score for a classification model. This function dispatches to S3 methods in specificity() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because specificity() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap specificity() in a "safe" validator that checks for NA values and matching length, for example:
safe_specificity <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
specificity(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate specificity ## via S3 dispatching specificity(confusion_matrix) ## additional performance metrics ## below
The specificity.factor() method calls cmatrix() internally, so explicitly invoking specificity.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## S3 method for class 'factor' specificity(actual, predicted, estimator = 0L, na.rm = TRUE, ...)## S3 method for class 'factor' specificity(actual, predicted, estimator = 0L, na.rm = TRUE, ...)
actual, predicted
|
A pair of <integer> or <factor> vectors of length |
estimator |
|
na.rm |
A <logical> value of length |
... |
Arguments passed into other methods. |
If estimator is given as
The specificity has other names depending on research field:
True Negative Rate, tnr()
Selectivity, selectivity()
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::specificity( actual = actual_classes, predicted = predicted_classes )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::specificity( actual = actual_classes, predicted = predicted_classes )
A generic S3 function to compute the accuracy score for a classification model. This function dispatches to S3 methods in accuracy() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because accuracy() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap accuracy() in a "safe" validator that checks for NA values and matching length, for example:
safe_accuracy <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
accuracy(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate accuracy ## via S3 dispatching accuracy(confusion_matrix) ## additional performance metrics ## below
The accuracy.factor() method calls cmatrix() internally, so explicitly invoking accuracy.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## S3 method for class 'factor' weighted.accuracy(actual, predicted, w, ...)## S3 method for class 'factor' weighted.accuracy(actual, predicted, w, ...)
actual, predicted
|
A pair of <integer> or <factor> vectors of length |
w |
A <double> vector of sample weights. |
... |
Arguments passed into other methods. |
A <double>-value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Generate sample ## weights sample_weights <- runif( n = length(actual_classes) ) ## Evaluate performance SLmetrics::weighted.accuracy( actual = actual_classes, predicted = predicted_classes, w = sample_weights )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Generate sample ## weights sample_weights <- runif( n = length(actual_classes) ) ## Evaluate performance SLmetrics::weighted.accuracy( actual = actual_classes, predicted = predicted_classes, w = sample_weights )
A generic S3 function to compute the area under the precision recall curve score for a classification model. This function dispatches to S3 methods in auc.pr.curve() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because auc.pr.curve() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap auc.pr.curve() in a "safe" validator that checks for NA values and matching length, for example:
safe_auc.pr.curve <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
auc.pr.curve(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
Use pr.curve() to construct the data.frame and use plot to visualize the area under the curve.
To avoid sorting the same probability matrix multiple times (once per class or curve), you can precompute a single set of sort indices and pass it via the indices argument. This reduces the overall cost from O(K·N log N) to O(N log N + K·N).
## presort response ## probabilities indices <- preorder(response, decreasing = TRUE) ## evaluate area under the precision recall curve auc.pr.curve(actual, response, indices = indices)
## S3 method for class 'factor' weighted.auc.pr.curve( actual, response, w, estimator = 0L, method = 0L, indices = NULL, ... )## S3 method for class 'factor' weighted.auc.pr.curve( actual, response, w, estimator = 0L, method = 0L, indices = NULL, ... )
actual |
|
response |
A |
w |
A <double> vector of sample weights. |
estimator |
|
method |
A <double> value (default: |
indices |
An optional |
... |
Arguments passed into other methods. |
If estimator is given as
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual classes ## and response probabilities actual_classes <- factor( x = sample( x = classes, size = 1e2, replace = TRUE, prob = c(0.7, 0.3) ) ) response_probabilities <- ifelse( actual_classes == "Kebab", rbeta(sum(actual_classes == "Kebab"), 2, 5), rbeta(sum(actual_classes == "Falafel"), 5, 2) ) ## Construct response ## matrix probability_matrix <- cbind( response_probabilities, 1 - response_probabilities ) sample_weights <- runif(1e2) ## Evaluate performance SLmetrics::weighted.auc.pr.curve( actual = actual_classes, response = probability_matrix, w = sample_weights )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual classes ## and response probabilities actual_classes <- factor( x = sample( x = classes, size = 1e2, replace = TRUE, prob = c(0.7, 0.3) ) ) response_probabilities <- ifelse( actual_classes == "Kebab", rbeta(sum(actual_classes == "Kebab"), 2, 5), rbeta(sum(actual_classes == "Falafel"), 5, 2) ) ## Construct response ## matrix probability_matrix <- cbind( response_probabilities, 1 - response_probabilities ) sample_weights <- runif(1e2) ## Evaluate performance SLmetrics::weighted.auc.pr.curve( actual = actual_classes, response = probability_matrix, w = sample_weights )
A generic S3 function to compute the area under the receiver operator characteristics curve score for a classification model. This function dispatches to S3 methods in auc.roc.curve() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because auc.roc.curve() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap auc.roc.curve() in a "safe" validator that checks for NA values and matching length, for example:
safe_auc.roc.curve <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
auc.roc.curve(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
Use roc.curve() to construct the data.frame and use plot to visualize the area under the curve.
To avoid sorting the same probability matrix multiple times (once per class or curve), you can precompute a single set of sort indices and pass it via the indices argument. This reduces the overall cost from O(K·N log N) to O(N log N + K·N).
## presort response ## probabilities indices <- preorder(response, decreasing = TRUE) ## evaluate area under the receiver operator characteristics curve auc.roc.curve(actual, response, indices = indices)
## S3 method for class 'factor' weighted.auc.roc.curve( actual, response, w, estimator = 0L, method = 0L, indices = NULL, ... )## S3 method for class 'factor' weighted.auc.roc.curve( actual, response, w, estimator = 0L, method = 0L, indices = NULL, ... )
actual |
|
response |
A |
w |
A <double> vector of sample weights. |
estimator |
|
method |
A <double> value (default: |
indices |
An optional |
... |
Arguments passed into other methods. |
If estimator is given as
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual classes ## and response probabilities actual_classes <- factor( x = sample( x = classes, size = 1e2, replace = TRUE, prob = c(0.7, 0.3) ) ) response_probabilities <- ifelse( actual_classes == "Kebab", rbeta(sum(actual_classes == "Kebab"), 2, 5), rbeta(sum(actual_classes == "Falafel"), 5, 2) ) ## Construct response ## matrix probability_matrix <- cbind( response_probabilities, 1 - response_probabilities ) sample_weights <- runif(1e2) ## Evaluate performance SLmetrics::weighted.auc.roc.curve( actual = actual_classes, response = probability_matrix, w = sample_weights )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual classes ## and response probabilities actual_classes <- factor( x = sample( x = classes, size = 1e2, replace = TRUE, prob = c(0.7, 0.3) ) ) response_probabilities <- ifelse( actual_classes == "Kebab", rbeta(sum(actual_classes == "Kebab"), 2, 5), rbeta(sum(actual_classes == "Falafel"), 5, 2) ) ## Construct response ## matrix probability_matrix <- cbind( response_probabilities, 1 - response_probabilities ) sample_weights <- runif(1e2) ## Evaluate performance SLmetrics::weighted.auc.roc.curve( actual = actual_classes, response = probability_matrix, w = sample_weights )
A generic S3 function to compute the balanced accuracy score for a classification model. This function dispatches to S3 methods in baccuracy() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because baccuracy() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap baccuracy() in a "safe" validator that checks for NA values and matching length, for example:
safe_baccuracy <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
baccuracy(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate balanced accuracy ## via S3 dispatching baccuracy(confusion_matrix) ## additional performance metrics ## below
The baccuracy.factor() method calls cmatrix() internally, so explicitly invoking baccuracy.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## S3 method for class 'factor' weighted.baccuracy(actual, predicted, w, adjust = FALSE, na.rm = TRUE, ...)## S3 method for class 'factor' weighted.baccuracy(actual, predicted, w, adjust = FALSE, na.rm = TRUE, ...)
actual, predicted
|
A pair of <integer> or <factor> vectors of length |
w |
A <double> vector of sample weights. |
adjust |
A <logical> value (default: FALSE). If TRUE the metric is adjusted for random chance |
na.rm |
A <logical> value of length |
... |
Arguments passed into other methods. |
A <double>-value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Generate sample ## weights sample_weights <- runif( n = length(actual_classes) ) ## Evaluate performance SLmetrics::weighted.baccuracy( actual = actual_classes, predicted = predicted_classes, w = sample_weights )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Generate sample ## weights sample_weights <- runif( n = length(actual_classes) ) ## Evaluate performance SLmetrics::weighted.baccuracy( actual = actual_classes, predicted = predicted_classes, w = sample_weights )
A generic S3 function to compute the brier score score for a classification model. This function dispatches to S3 methods in brier.score() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because brier.score() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap brier.score() in a "safe" validator that checks for NA values and matching length, for example:
safe_brier.score <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
brier.score(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## S3 method for class 'matrix' weighted.brier.score(ok, qk, w, ...)## S3 method for class 'matrix' weighted.brier.score(ok, qk, w, ...)
ok |
A <double> indicator matrix with |
qk |
A |
w |
A <double> vector of sample weights. |
... |
Arguments passed into other methods. |
A <double>-value
Gneiting, Tilmann, and Adrian E. Raftery. "Strictly proper scoring rules, prediction, and estimation." Journal of the American statistical Association 102.477 (2007): 359-378.
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## seed set.seed(1903) ## The general setup ## with 3 classes n_obs <- 10 n_classes <- 3 ## Generate indicator matrix ## with observed outcome (ok) and ## its predicted probability matrix (qk) ok <- diag(n_classes)[ sample.int(n_classes, n_obs, TRUE), ] qk <- matrix(runif(n_obs * n_classes), n_obs, n_classes) qk <- qk / rowSums(qk) ## Generate sample ## weights sample_weights <- runif( n = n_obs ) ## Evaluate performance SLmetrics::weighted.brier.score( ok = ok, qk = qk, w = sample_weights )## seed set.seed(1903) ## The general setup ## with 3 classes n_obs <- 10 n_classes <- 3 ## Generate indicator matrix ## with observed outcome (ok) and ## its predicted probability matrix (qk) ok <- diag(n_classes)[ sample.int(n_classes, n_obs, TRUE), ] qk <- matrix(runif(n_obs * n_classes), n_obs, n_classes) qk <- qk / rowSums(qk) ## Generate sample ## weights sample_weights <- runif( n = n_obs ) ## Evaluate performance SLmetrics::weighted.brier.score( ok = ok, qk = qk, w = sample_weights )
A generic S3 function to compute the concordance correlation coefficient score for a regression model. This function dispatches to S3 methods in ccc() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because ccc() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap ccc() in a "safe" validator that checks for NA values and matching length, for example:
safe_ccc <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
ccc(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## S3 method for class 'numeric' weighted.ccc(actual, predicted, w, correction = FALSE, ...)## S3 method for class 'numeric' weighted.ccc(actual, predicted, w, correction = FALSE, ...)
actual, predicted
|
|
w |
A <double> vector of sample weights. |
correction |
A <logical> vector of length |
... |
Arguments passed into other methods |
A <double> value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Virtanen, Pauli, et al. "SciPy 1.0: fundamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Regression:
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
gmse(),
huberloss(),
maape(),
mae(),
mape(),
mpe(),
mse(),
pinball(),
rae(),
rmse(),
rmsle(),
rrmse(),
rrse(),
rsq(),
smape()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Generate sample ## weights sample_weights <- c(0.3, 0.5, 0.3, 0, 0.8, 0.8, 1) ## Evaluate performance SLmetrics::weighted.ccc( actual = actual_values, predicted = predicted_values, w = sample_weights )## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Generate sample ## weights sample_weights <- c(0.3, 0.5, 0.3, 0, 0.8, 0.8, 1) ## Evaluate performance SLmetrics::weighted.ccc( actual = actual_values, predicted = predicted_values, w = sample_weights )
-StatisticA generic S3 function to compute the cohen's -statistic score for a classification model. This function dispatches to S3 methods in ckappa() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because ckappa() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap ckappa() in a "safe" validator that checks for NA values and matching length, for example:
safe_ckappa <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
ckappa(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix
confusion_matrix <- cmatrix(actual, predicted)
## evaluate cohen's \eqn{\kappa}-statistic
## via S3 dispatching
ckappa(confusion_matrix)
## additional performance metrics
## below
The ckappa.factor() method calls cmatrix() internally, so explicitly invoking ckappa.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## S3 method for class 'factor' weighted.ckappa(actual, predicted, w, beta = 0, ...)## S3 method for class 'factor' weighted.ckappa(actual, predicted, w, beta = 0, ...)
actual, predicted
|
A pair of <integer> or <factor> vectors of length |
w |
A <double> vector of sample weights. |
beta |
A <double> value of length 1 (default: 0). If |
... |
Arguments passed into other methods. |
A <double>-value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Generate sample ## weights sample_weights <- runif( n = length(actual_classes) ) ## Evaluate performance SLmetrics::weighted.ckappa( actual = actual_classes, predicted = predicted_classes, w = sample_weights )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Generate sample ## weights sample_weights <- runif( n = length(actual_classes) ) ## Evaluate performance SLmetrics::weighted.ckappa( actual = actual_classes, predicted = predicted_classes, w = sample_weights )
A generic S3 function to compute the confusion matrix for a classification model. This function dispatches to S3 methods in cmatrix() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because cmatrix() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap cmatrix() in a "safe" validator that checks for NA values and matching length, for example:
safe_cmatrix <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
cmatrix(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
cmatrix() is the main function for classification metrics with cmatrix S3 dispatch. These functions internally calls cmatrix(), so there is a signficant gain in computing the confusion matrix first, and then pass it onto the metrics.
For example:
## Compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## Evaluate accuracy ## via S3 dispatching accuracy(confusion_matrix) ## Evaluate recall ## via S3 dispatching recall(confusion_matrix)
## S3 method for class 'factor' weighted.cmatrix(actual, predicted, w, ...)## S3 method for class 'factor' weighted.cmatrix(actual, predicted, w, ...)
actual, predicted
|
A pair of <integer> or <factor> vectors of length |
w |
A <double> vector of sample weights. |
... |
Arguments passed into other methods. |
A named x <matrix>
There is no robust defensive measure against misspecifying the confusion matrix. If the arguments are passed correctly, the resulting confusion matrix is on the form:
| A (Predicted) | B (Predicted) | |
| A (Actual) | Value | Value |
| B (Actual) | Value | Value |
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Generate sample ## weights sample_weights <- runif( n = length(actual_classes) ) ## Compute confusion matrix SLmetrics::weighted.cmatrix( actual = actual_classes, predicted = predicted_classes, w = sample_weights )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Generate sample ## weights sample_weights <- runif( n = length(actual_classes) ) ## Compute confusion matrix SLmetrics::weighted.cmatrix( actual = actual_classes, predicted = predicted_classes, w = sample_weights )
A generic S3 function to compute the gamma deviance score for a regression model. This function dispatches to S3 methods in deviance.gamma() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because deviance.gamma() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap deviance.gamma() in a "safe" validator that checks for NA values and matching length, for example:
safe_deviance.gamma <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
deviance.gamma(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## S3 method for class 'numeric' weighted.deviance.gamma(actual, predicted, w, ...)## S3 method for class 'numeric' weighted.deviance.gamma(actual, predicted, w, ...)
actual, predicted
|
|
w |
A <double> vector of sample weights. |
... |
Arguments passed into other methods |
A <double> value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Virtanen, Pauli, et al. "SciPy 1.0: fundamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Regression:
ccc(),
deviance.poisson(),
deviance.tweedie(),
gmse(),
huberloss(),
maape(),
mae(),
mape(),
mpe(),
mse(),
pinball(),
rae(),
rmse(),
rmsle(),
rrmse(),
rrse(),
rsq(),
smape()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Generate sample ## weights sample_weights <- c(0.3, 0.5, 0.3, 0, 0.8, 0.8, 1) ## Evaluate performance SLmetrics::weighted.deviance.gamma( actual = actual_values, predicted = predicted_values, w = sample_weights )## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Generate sample ## weights sample_weights <- c(0.3, 0.5, 0.3, 0, 0.8, 0.8, 1) ## Evaluate performance SLmetrics::weighted.deviance.gamma( actual = actual_values, predicted = predicted_values, w = sample_weights )
A generic S3 function to compute the poisson deviance score for a regression model. This function dispatches to S3 methods in deviance.poisson() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because deviance.poisson() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap deviance.poisson() in a "safe" validator that checks for NA values and matching length, for example:
safe_deviance.poisson <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
deviance.poisson(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## S3 method for class 'numeric' weighted.deviance.poisson(actual, predicted, w, ...)## S3 method for class 'numeric' weighted.deviance.poisson(actual, predicted, w, ...)
actual, predicted
|
|
w |
A <double> vector of sample weights. |
... |
Arguments passed into other methods |
A <double> value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Virtanen, Pauli, et al. "SciPy 1.0: fundamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Regression:
ccc(),
deviance.gamma(),
deviance.tweedie(),
gmse(),
huberloss(),
maape(),
mae(),
mape(),
mpe(),
mse(),
pinball(),
rae(),
rmse(),
rmsle(),
rrmse(),
rrse(),
rsq(),
smape()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Generate sample ## weights sample_weights <- c(0.3, 0.5, 0.3, 0, 0.8, 0.8, 1) ## Evaluate performance SLmetrics::weighted.deviance.poisson( actual = actual_values, predicted = predicted_values, w = sample_weights )## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Generate sample ## weights sample_weights <- c(0.3, 0.5, 0.3, 0, 0.8, 0.8, 1) ## Evaluate performance SLmetrics::weighted.deviance.poisson( actual = actual_values, predicted = predicted_values, w = sample_weights )
A generic S3 function to compute the tweedie deviance score for a regression model. This function dispatches to S3 methods in deviance.tweedie() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because deviance.tweedie() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap deviance.tweedie() in a "safe" validator that checks for NA values and matching length, for example:
safe_deviance.tweedie <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
deviance.tweedie(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## S3 method for class 'numeric' weighted.deviance.tweedie(actual, predicted, w, power = 2, ...)## S3 method for class 'numeric' weighted.deviance.tweedie(actual, predicted, w, power = 2, ...)
actual, predicted
|
|
w |
A <double> vector of sample weights. |
power |
A <double> value, default = 2. Tweedie power parameter. Either power <= 0 or power >= 1. The higher
|
... |
Arguments passed into other methods |
A <double> value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Virtanen, Pauli, et al. "SciPy 1.0: fundamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Regression:
ccc(),
deviance.gamma(),
deviance.poisson(),
gmse(),
huberloss(),
maape(),
mae(),
mape(),
mpe(),
mse(),
pinball(),
rae(),
rmse(),
rmsle(),
rrmse(),
rrse(),
rsq(),
smape()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Generate sample ## weights sample_weights <- c(0.3, 0.5, 0.3, 0, 0.8, 0.8, 1) ## Evaluate performance SLmetrics::weighted.deviance.tweedie( actual = actual_values, predicted = predicted_values, w = sample_weights )## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Generate sample ## weights sample_weights <- c(0.3, 0.5, 0.3, 0, 0.8, 0.8, 1) ## Evaluate performance SLmetrics::weighted.deviance.tweedie( actual = actual_values, predicted = predicted_values, w = sample_weights )
A generic S3 function to compute the positive likelihood ratio score for a classification model. This function dispatches to S3 methods in plr() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because plr() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap plr() in a "safe" validator that checks for NA values and matching length, for example:
safe_plr <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
plr(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate positive likelihood ratio ## via S3 dispatching plr(confusion_matrix) ## additional performance metrics ## below
The plr.factor() method calls cmatrix() internally, so explicitly invoking plr.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## S3 method for class 'factor' weighted.dor(actual, predicted, w, ...)## S3 method for class 'factor' weighted.dor(actual, predicted, w, ...)
actual, predicted
|
A pair of <integer> or <factor> vectors of length |
w |
A <double> vector of sample weights. |
... |
Arguments passed into other methods. |
A <double>-value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
The nlr()-function for the Negative Likehood Ratio (LR-)
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Generate sample ## weights sample_weights <- runif( n = length(actual_classes) ) ## Evaluate performance SLmetrics::weighted.dor( actual = actual_classes, predicted = predicted_classes, w = sample_weights )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Generate sample ## weights sample_weights <- runif( n = length(actual_classes) ) ## Evaluate performance SLmetrics::weighted.dor( actual = actual_classes, predicted = predicted_classes, w = sample_weights )
A generic S3 function to compute the score for a classification model. This function dispatches to S3 methods in fbeta() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because fbeta() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap fbeta() in a "safe" validator that checks for NA values and matching length, for example:
safe_fbeta <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
fbeta(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix
confusion_matrix <- cmatrix(actual, predicted)
## evaluate \eqn{f_{\beta}}
## via S3 dispatching
fbeta(confusion_matrix)
## additional performance metrics
## below
The fbeta.factor() method calls cmatrix() internally, so explicitly invoking fbeta.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## S3 method for class 'factor' weighted.fbeta( actual, predicted, w, beta = 1, estimator = 0L, na.rm = TRUE, ... )## S3 method for class 'factor' weighted.fbeta( actual, predicted, w, beta = 1, estimator = 0L, na.rm = TRUE, ... )
actual, predicted
|
A pair of <integer> or <factor> vectors of length |
w |
A <double> vector of sample weights. |
beta |
|
estimator |
|
na.rm |
A <logical> value of length |
... |
Arguments passed into other methods. |
If estimator is given as
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Generate sample ## weights sample_weights <- runif( n = length(actual_classes) ) ## Evaluate performance SLmetrics::weighted.fbeta( actual = actual_classes, predicted = predicted_classes, w = sample_weights )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Generate sample ## weights sample_weights <- runif( n = length(actual_classes) ) ## Evaluate performance SLmetrics::weighted.fbeta( actual = actual_classes, predicted = predicted_classes, w = sample_weights )
A generic S3 function to compute the false discovery rate score for a classification model. This function dispatches to S3 methods in fdr() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because fdr() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap fdr() in a "safe" validator that checks for NA values and matching length, for example:
safe_fdr <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
fdr(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate false discovery rate ## via S3 dispatching fdr(confusion_matrix) ## additional performance metrics ## below
The fdr.factor() method calls cmatrix() internally, so explicitly invoking fdr.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## S3 method for class 'factor' weighted.fdr(actual, predicted, w, estimator = 0L, na.rm = TRUE, ...)## S3 method for class 'factor' weighted.fdr(actual, predicted, w, estimator = 0L, na.rm = TRUE, ...)
actual, predicted
|
A pair of <integer> or <factor> vectors of length |
w |
A <double> vector of sample weights. |
estimator |
|
na.rm |
A <logical> value of length |
... |
Arguments passed into other methods. |
If estimator is given as
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Generate sample ## weights sample_weights <- runif( n = length(actual_classes) ) ## Evaluate performance SLmetrics::weighted.fdr( actual = actual_classes, predicted = predicted_classes, w = sample_weights )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Generate sample ## weights sample_weights <- runif( n = length(actual_classes) ) ## Evaluate performance SLmetrics::weighted.fdr( actual = actual_classes, predicted = predicted_classes, w = sample_weights )
A generic S3 function to compute the false omission rate score for a classification model. This function dispatches to S3 methods in fer() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because fer() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap fer() in a "safe" validator that checks for NA values and matching length, for example:
safe_fer <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
fer(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate false omission rate ## via S3 dispatching fer(confusion_matrix) ## additional performance metrics ## below
The fer.factor() method calls cmatrix() internally, so explicitly invoking fer.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## S3 method for class 'factor' weighted.fer(actual, predicted, w, estimator = 0L, na.rm = TRUE, ...)## S3 method for class 'factor' weighted.fer(actual, predicted, w, estimator = 0L, na.rm = TRUE, ...)
actual, predicted
|
A pair of <integer> or <factor> vectors of length |
w |
A <double> vector of sample weights. |
estimator |
|
na.rm |
A <logical> value of length |
... |
Arguments passed into other methods. |
If estimator is given as
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Generate sample ## weights sample_weights <- runif( n = length(actual_classes) ) ## Evaluate performance SLmetrics::weighted.fer( actual = actual_classes, predicted = predicted_classes, w = sample_weights )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Generate sample ## weights sample_weights <- runif( n = length(actual_classes) ) ## Evaluate performance SLmetrics::weighted.fer( actual = actual_classes, predicted = predicted_classes, w = sample_weights )
A generic S3 function to compute the fowlkes mallows index score for a classification model. This function dispatches to S3 methods in fmi() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because fmi() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap fmi() in a "safe" validator that checks for NA values and matching length, for example:
safe_fmi <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
fmi(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate fowlkes mallows index ## via S3 dispatching fmi(confusion_matrix) ## additional performance metrics ## below
The fmi.factor() method calls cmatrix() internally, so explicitly invoking fmi.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## S3 method for class 'factor' weighted.fmi(actual, predicted, w, ...)## S3 method for class 'factor' weighted.fmi(actual, predicted, w, ...)
actual, predicted
|
A pair of <integer> or <factor> vectors of length |
w |
A <double> vector of sample weights. |
... |
Arguments passed into other methods. |
A <double>-value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Generate sample ## weights sample_weights <- runif( n = length(actual_classes) ) ## Evaluate performance SLmetrics::weighted.fmi( actual = actual_classes, predicted = predicted_classes, w = sample_weights )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Generate sample ## weights sample_weights <- runif( n = length(actual_classes) ) ## Evaluate performance SLmetrics::weighted.fmi( actual = actual_classes, predicted = predicted_classes, w = sample_weights )
A generic S3 function to compute the false positive rate score for a classification model. This function dispatches to S3 methods in fpr() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because fpr() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap fpr() in a "safe" validator that checks for NA values and matching length, for example:
safe_fpr <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
fpr(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate false positive rate ## via S3 dispatching fpr(confusion_matrix) ## additional performance metrics ## below
The fpr.factor() method calls cmatrix() internally, so explicitly invoking fpr.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## S3 method for class 'factor' weighted.fpr(actual, predicted, w, estimator = 0L, na.rm = TRUE, ...)## S3 method for class 'factor' weighted.fpr(actual, predicted, w, estimator = 0L, na.rm = TRUE, ...)
actual, predicted
|
A pair of <integer> or <factor> vectors of length |
w |
A <double> vector of sample weights. |
estimator |
|
na.rm |
A <logical> value of length |
... |
Arguments passed into other methods. |
If estimator is given as
The false positive rate has other names depending on research field:
Fallout, fallout()
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Generate sample ## weights sample_weights <- runif( n = length(actual_classes) ) ## Evaluate performance SLmetrics::weighted.fpr( actual = actual_classes, predicted = predicted_classes, w = sample_weights )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Generate sample ## weights sample_weights <- runif( n = length(actual_classes) ) ## Evaluate performance SLmetrics::weighted.fpr( actual = actual_classes, predicted = predicted_classes, w = sample_weights )
A generic S3 function to compute the geometric mean squared error score for a regression model. This function dispatches to S3 methods in gmse() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because gmse() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap gmse() in a "safe" validator that checks for NA values and matching length, for example:
safe_gmse <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
gmse(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## S3 method for class 'numeric' weighted.gmse(actual, predicted, w, ...)## S3 method for class 'numeric' weighted.gmse(actual, predicted, w, ...)
actual, predicted
|
|
w |
A <double> vector of sample weights. |
... |
Arguments passed into other methods |
A <double> value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Virtanen, Pauli, et al. "SciPy 1.0: fundamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Regression:
ccc(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
huberloss(),
maape(),
mae(),
mape(),
mpe(),
mse(),
pinball(),
rae(),
rmse(),
rmsle(),
rrmse(),
rrse(),
rsq(),
smape()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Generate sample ## weights sample_weights <- c(0.3, 0.5, 0.3, 0, 0.8, 0.8, 1) ## Evaluate performance SLmetrics::weighted.gmse( actual = actual_values, predicted = predicted_values, w = sample_weights )## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Generate sample ## weights sample_weights <- c(0.3, 0.5, 0.3, 0, 0.8, 0.8, 1) ## Evaluate performance SLmetrics::weighted.gmse( actual = actual_values, predicted = predicted_values, w = sample_weights )
A generic S3 function to compute the hamming loss score for a classification model. This function dispatches to S3 methods in hammingloss() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because hammingloss() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap hammingloss() in a "safe" validator that checks for NA values and matching length, for example:
safe_hammingloss <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
hammingloss(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate hamming loss ## via S3 dispatching hammingloss(confusion_matrix) ## additional performance metrics ## below
The hammingloss.factor() method calls cmatrix() internally, so explicitly invoking hammingloss.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## S3 method for class 'factor' weighted.hammingloss(actual, predicted, w, ...)## S3 method for class 'factor' weighted.hammingloss(actual, predicted, w, ...)
actual, predicted
|
A pair of <integer> or <factor> vectors of length |
w |
A <double> vector of sample weights. |
... |
Arguments passed into other methods. |
A <double>-value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Generate sample ## weights sample_weights <- runif( n = length(actual_classes) ) ## Evaluate performance SLmetrics::weighted.hammingloss( actual = actual_classes, predicted = predicted_classes, w = sample_weights )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Generate sample ## weights sample_weights <- runif( n = length(actual_classes) ) ## Evaluate performance SLmetrics::weighted.hammingloss( actual = actual_classes, predicted = predicted_classes, w = sample_weights )
A generic S3 function to compute the huber loss score for a regression model. This function dispatches to S3 methods in huberloss() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because huberloss() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap huberloss() in a "safe" validator that checks for NA values and matching length, for example:
safe_huberloss <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
huberloss(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## S3 method for class 'numeric' weighted.huberloss(actual, predicted, w, delta = 1, ...)## S3 method for class 'numeric' weighted.huberloss(actual, predicted, w, delta = 1, ...)
actual, predicted
|
|
w |
A <double> vector of sample weights. |
delta |
A <double>-vector of length |
... |
Arguments passed into other methods |
A <double> value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Virtanen, Pauli, et al. "SciPy 1.0: fundamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Regression:
ccc(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
gmse(),
maape(),
mae(),
mape(),
mpe(),
mse(),
pinball(),
rae(),
rmse(),
rmsle(),
rrmse(),
rrse(),
rsq(),
smape()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Generate sample ## weights sample_weights <- c(0.3, 0.5, 0.3, 0, 0.8, 0.8, 1) ## Evaluate performance SLmetrics::weighted.huberloss( actual = actual_values, predicted = predicted_values, w = sample_weights )## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Generate sample ## weights sample_weights <- c(0.3, 0.5, 0.3, 0, 0.8, 0.8, 1) ## Evaluate performance SLmetrics::weighted.huberloss( actual = actual_values, predicted = predicted_values, w = sample_weights )
A generic S3 function to compute the jaccard index score for a classification model. This function dispatches to S3 methods in jaccard() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because jaccard() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap jaccard() in a "safe" validator that checks for NA values and matching length, for example:
safe_jaccard <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
jaccard(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate jaccard index ## via S3 dispatching jaccard(confusion_matrix) ## additional performance metrics ## below
The jaccard.factor() method calls cmatrix() internally, so explicitly invoking jaccard.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## S3 method for class 'factor' weighted.jaccard(actual, predicted, w, estimator = 0L, na.rm = TRUE, ...)## S3 method for class 'factor' weighted.jaccard(actual, predicted, w, estimator = 0L, na.rm = TRUE, ...)
actual, predicted
|
A pair of <integer> or <factor> vectors of length |
w |
A <double> vector of sample weights. |
estimator |
|
na.rm |
A <logical> value of length |
... |
Arguments passed into other methods. |
If estimator is given as
The specificity has other names depending on research field:
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Generate sample ## weights sample_weights <- runif( n = length(actual_classes) ) ## Evaluate performance SLmetrics::weighted.jaccard( actual = actual_classes, predicted = predicted_classes, w = sample_weights )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Generate sample ## weights sample_weights <- runif( n = length(actual_classes) ) ## Evaluate performance SLmetrics::weighted.jaccard( actual = actual_classes, predicted = predicted_classes, w = sample_weights )
A generic S3 function to compute the logarithmic loss score for a classification model. This function dispatches to S3 methods in logloss() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because logloss() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap logloss() in a "safe" validator that checks for NA values and matching length, for example:
safe_logloss <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
logloss(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## S3 method for class 'factor' weighted.logloss(actual, response, w, normalize = TRUE, ...)## S3 method for class 'factor' weighted.logloss(actual, response, w, normalize = TRUE, ...)
actual |
|
response |
A |
w |
A <double> vector of sample weights. |
normalize |
A <logical>-value (default: TRUE). If TRUE, the mean cross-entropy across all observations is returned; otherwise, the sum of cross-entropies is returned. |
... |
Arguments passed into other methods. |
A <double>
MacKay, David JC. Information theory, inference and learning algorithms. Cambridge university press, 2003.
Kramer, Oliver, and Oliver Kramer. "Scikit-learn." Machine learning for evolution strategies (2016): 45-53.
Virtanen, Pauli, et al. "SciPy 1.0: fundamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
Other Entropy:
cross.entropy(),
relative.entropy(),
shannon.entropy()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted response ## probabilities actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) response <- runif(n = 1e3) ## Generate sample ## weights sample_weights <- runif( n = 1e3 ) ## Evaluate performance SLmetrics::weighted.logloss( actual = actual_classes, response = cbind( response, 1 - response ), w = sample_weights ) ## Generate observed ## frequencies actual_frequency <- sample(10L:100L, size = 1e3, replace = TRUE) SLmetrics::weighted.logloss( actual = actual_frequency, response = response, w = sample_weights )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted response ## probabilities actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) response <- runif(n = 1e3) ## Generate sample ## weights sample_weights <- runif( n = 1e3 ) ## Evaluate performance SLmetrics::weighted.logloss( actual = actual_classes, response = cbind( response, 1 - response ), w = sample_weights ) ## Generate observed ## frequencies actual_frequency <- sample(10L:100L, size = 1e3, replace = TRUE) SLmetrics::weighted.logloss( actual = actual_frequency, response = response, w = sample_weights )
A generic S3 function to compute the logarithmic loss score for a classification model. This function dispatches to S3 methods in logloss() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because logloss() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap logloss() in a "safe" validator that checks for NA values and matching length, for example:
safe_logloss <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
logloss(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## S3 method for class 'integer' weighted.logloss(actual, response, w, normalize = TRUE, ...)## S3 method for class 'integer' weighted.logloss(actual, response, w, normalize = TRUE, ...)
actual |
|
response |
A |
w |
A <double> vector of sample weights. |
normalize |
A <logical>-value (default: TRUE). If TRUE, the mean cross-entropy across all observations is returned; otherwise, the sum of cross-entropies is returned. |
... |
Arguments passed into other methods. |
A <double>
MacKay, David JC. Information theory, inference and learning algorithms. Cambridge university press, 2003.
Kramer, Oliver, and Oliver Kramer. "Scikit-learn." Machine learning for evolution strategies (2016): 45-53.
Virtanen, Pauli, et al. "SciPy 1.0: fundamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
Other Entropy:
cross.entropy(),
relative.entropy(),
shannon.entropy()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted response ## probabilities actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) response <- runif(n = 1e3) ## Generate sample ## weights sample_weights <- runif( n = 1e3 ) ## Evaluate performance SLmetrics::weighted.logloss( actual = actual_classes, response = cbind( response, 1 - response ), w = sample_weights ) ## Generate observed ## frequencies actual_frequency <- sample(10L:100L, size = 1e3, replace = TRUE) SLmetrics::weighted.logloss( actual = actual_frequency, response = response, w = sample_weights )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted response ## probabilities actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) response <- runif(n = 1e3) ## Generate sample ## weights sample_weights <- runif( n = 1e3 ) ## Evaluate performance SLmetrics::weighted.logloss( actual = actual_classes, response = cbind( response, 1 - response ), w = sample_weights ) ## Generate observed ## frequencies actual_frequency <- sample(10L:100L, size = 1e3, replace = TRUE) SLmetrics::weighted.logloss( actual = actual_frequency, response = response, w = sample_weights )
A generic S3 function to compute the mean arctangent absolute percentage error score for a regression model. This function dispatches to S3 methods in maape() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because maape() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap maape() in a "safe" validator that checks for NA values and matching length, for example:
safe_maape <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
maape(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## S3 method for class 'numeric' weighted.maape(actual, predicted, w, ...)## S3 method for class 'numeric' weighted.maape(actual, predicted, w, ...)
actual, predicted
|
|
w |
A <double> vector of sample weights. |
... |
Arguments passed into other methods |
A <double> value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Virtanen, Pauli, et al. "SciPy 1.0: fundamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Regression:
ccc(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
gmse(),
huberloss(),
mae(),
mape(),
mpe(),
mse(),
pinball(),
rae(),
rmse(),
rmsle(),
rrmse(),
rrse(),
rsq(),
smape()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Generate sample ## weights sample_weights <- c(0.3, 0.5, 0.3, 0, 0.8, 0.8, 1) ## Evaluate performance SLmetrics::weighted.maape( actual = actual_values, predicted = predicted_values, w = sample_weights )## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Generate sample ## weights sample_weights <- c(0.3, 0.5, 0.3, 0, 0.8, 0.8, 1) ## Evaluate performance SLmetrics::weighted.maape( actual = actual_values, predicted = predicted_values, w = sample_weights )
A generic S3 function to compute the mean absolute error score for a regression model. This function dispatches to S3 methods in mae() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because mae() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap mae() in a "safe" validator that checks for NA values and matching length, for example:
safe_mae <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
mae(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## S3 method for class 'numeric' weighted.mae(actual, predicted, w, ...)## S3 method for class 'numeric' weighted.mae(actual, predicted, w, ...)
actual, predicted
|
|
w |
A <double> vector of sample weights. |
... |
Arguments passed into other methods |
A <double> value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Virtanen, Pauli, et al. "SciPy 1.0: fundamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Regression:
ccc(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
gmse(),
huberloss(),
maape(),
mape(),
mpe(),
mse(),
pinball(),
rae(),
rmse(),
rmsle(),
rrmse(),
rrse(),
rsq(),
smape()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Generate sample ## weights sample_weights <- c(0.3, 0.5, 0.3, 0, 0.8, 0.8, 1) ## Evaluate performance SLmetrics::weighted.mae( actual = actual_values, predicted = predicted_values, w = sample_weights )## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Generate sample ## weights sample_weights <- c(0.3, 0.5, 0.3, 0, 0.8, 0.8, 1) ## Evaluate performance SLmetrics::weighted.mae( actual = actual_values, predicted = predicted_values, w = sample_weights )
A generic S3 function to compute the mean absolute percentage error score for a regression model. This function dispatches to S3 methods in mape() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because mape() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap mape() in a "safe" validator that checks for NA values and matching length, for example:
safe_mape <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
mape(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## S3 method for class 'numeric' weighted.mape(actual, predicted, w, ...)## S3 method for class 'numeric' weighted.mape(actual, predicted, w, ...)
actual, predicted
|
|
w |
A <double> vector of sample weights. |
... |
Arguments passed into other methods |
A <double> value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Virtanen, Pauli, et al. "SciPy 1.0: fundamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Regression:
ccc(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
gmse(),
huberloss(),
maape(),
mae(),
mpe(),
mse(),
pinball(),
rae(),
rmse(),
rmsle(),
rrmse(),
rrse(),
rsq(),
smape()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Generate sample ## weights sample_weights <- c(0.3, 0.5, 0.3, 0, 0.8, 0.8, 1) ## Evaluate performance SLmetrics::weighted.mape( actual = actual_values, predicted = predicted_values, w = sample_weights )## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Generate sample ## weights sample_weights <- c(0.3, 0.5, 0.3, 0, 0.8, 0.8, 1) ## Evaluate performance SLmetrics::weighted.mape( actual = actual_values, predicted = predicted_values, w = sample_weights )
A generic S3 function to compute the matthews correlation coefficient score for a classification model. This function dispatches to S3 methods in mcc() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because mcc() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap mcc() in a "safe" validator that checks for NA values and matching length, for example:
safe_mcc <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
mcc(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate matthews correlation coefficient ## via S3 dispatching mcc(confusion_matrix) ## additional performance metrics ## below
The mcc.factor() method calls cmatrix() internally, so explicitly invoking mcc.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## S3 method for class 'factor' weighted.mcc(actual, predicted, w, ...)## S3 method for class 'factor' weighted.mcc(actual, predicted, w, ...)
actual, predicted
|
A pair of <integer> or <factor> vectors of length |
w |
A <double> vector of sample weights. |
... |
Arguments passed into other methods. |
A <double>-value
The Matthews Correlation Coefficient has other names depending on research field:
-coefficient, phi()
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Generate sample ## weights sample_weights <- runif( n = length(actual_classes) ) ## Evaluate performance SLmetrics::weighted.mcc( actual = actual_classes, predicted = predicted_classes, w = sample_weights )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Generate sample ## weights sample_weights <- runif( n = length(actual_classes) ) ## Evaluate performance SLmetrics::weighted.mcc( actual = actual_classes, predicted = predicted_classes, w = sample_weights )
A generic S3 function to compute the mean percentage error score for a regression model. This function dispatches to S3 methods in mpe() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because mpe() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap mpe() in a "safe" validator that checks for NA values and matching length, for example:
safe_mpe <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
mpe(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## S3 method for class 'numeric' weighted.mpe(actual, predicted, w, ...)## S3 method for class 'numeric' weighted.mpe(actual, predicted, w, ...)
actual, predicted
|
|
w |
A <double> vector of sample weights. |
... |
Arguments passed into other methods |
A <double> value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Virtanen, Pauli, et al. "SciPy 1.0: fundamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Regression:
ccc(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
gmse(),
huberloss(),
maape(),
mae(),
mape(),
mse(),
pinball(),
rae(),
rmse(),
rmsle(),
rrmse(),
rrse(),
rsq(),
smape()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Generate sample ## weights sample_weights <- c(0.3, 0.5, 0.3, 0, 0.8, 0.8, 1) ## Evaluate performance SLmetrics::weighted.mpe( actual = actual_values, predicted = predicted_values, w = sample_weights )## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Generate sample ## weights sample_weights <- c(0.3, 0.5, 0.3, 0, 0.8, 0.8, 1) ## Evaluate performance SLmetrics::weighted.mpe( actual = actual_values, predicted = predicted_values, w = sample_weights )
A generic S3 function to compute the mean squared error score for a regression model. This function dispatches to S3 methods in mse() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because mse() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap mse() in a "safe" validator that checks for NA values and matching length, for example:
safe_mse <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
mse(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## S3 method for class 'numeric' weighted.mse(actual, predicted, w, ...)## S3 method for class 'numeric' weighted.mse(actual, predicted, w, ...)
actual, predicted
|
|
w |
A <double> vector of sample weights. |
... |
Arguments passed into other methods |
A <double> value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Virtanen, Pauli, et al. "SciPy 1.0: fundamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Regression:
ccc(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
gmse(),
huberloss(),
maape(),
mae(),
mape(),
mpe(),
pinball(),
rae(),
rmse(),
rmsle(),
rrmse(),
rrse(),
rsq(),
smape()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Generate sample ## weights sample_weights <- c(0.3, 0.5, 0.3, 0, 0.8, 0.8, 1) ## Evaluate performance SLmetrics::weighted.mse( actual = actual_values, predicted = predicted_values, w = sample_weights )## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Generate sample ## weights sample_weights <- c(0.3, 0.5, 0.3, 0, 0.8, 0.8, 1) ## Evaluate performance SLmetrics::weighted.mse( actual = actual_values, predicted = predicted_values, w = sample_weights )
A generic S3 function to compute the negative likelihood ratio score for a classification model. This function dispatches to S3 methods in nlr() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because nlr() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap nlr() in a "safe" validator that checks for NA values and matching length, for example:
safe_nlr <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
nlr(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate negative likelihood ratio ## via S3 dispatching nlr(confusion_matrix) ## additional performance metrics ## below
The nlr.factor() method calls cmatrix() internally, so explicitly invoking nlr.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## S3 method for class 'factor' weighted.nlr(actual, predicted, w, ...)## S3 method for class 'factor' weighted.nlr(actual, predicted, w, ...)
actual, predicted
|
A pair of <integer> or <factor> vectors of length |
w |
A <double> vector of sample weights. |
... |
Arguments passed into other methods. |
A <double>-value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
The plr()-function for the Positive Likehood Ratio (LR+)
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Generate sample ## weights sample_weights <- runif( n = length(actual_classes) ) ## Evaluate performance SLmetrics::weighted.nlr( actual = actual_classes, predicted = predicted_classes, w = sample_weights )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Generate sample ## weights sample_weights <- runif( n = length(actual_classes) ) ## Evaluate performance SLmetrics::weighted.nlr( actual = actual_classes, predicted = predicted_classes, w = sample_weights )
A generic S3 function to compute the negative predictive value score for a classification model. This function dispatches to S3 methods in npv() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because npv() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap npv() in a "safe" validator that checks for NA values and matching length, for example:
safe_npv <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
npv(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate negative predictive value ## via S3 dispatching npv(confusion_matrix) ## additional performance metrics ## below
The npv.factor() method calls cmatrix() internally, so explicitly invoking npv.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## S3 method for class 'factor' weighted.npv(actual, predicted, w, estimator = 0L, na.rm = TRUE, ...)## S3 method for class 'factor' weighted.npv(actual, predicted, w, estimator = 0L, na.rm = TRUE, ...)
actual, predicted
|
A pair of <integer> or <factor> vectors of length |
w |
A <double> vector of sample weights. |
estimator |
|
na.rm |
A <logical> value of length |
... |
Arguments passed into other methods. |
If estimator is given as
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Generate sample ## weights sample_weights <- runif( n = length(actual_classes) ) ## Evaluate performance SLmetrics::weighted.npv( actual = actual_classes, predicted = predicted_classes, w = sample_weights )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Generate sample ## weights sample_weights <- runif( n = length(actual_classes) ) ## Evaluate performance SLmetrics::weighted.npv( actual = actual_classes, predicted = predicted_classes, w = sample_weights )
A generic S3 function to compute the pinball loss score for a regression model. This function dispatches to S3 methods in pinball() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because pinball() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap pinball() in a "safe" validator that checks for NA values and matching length, for example:
safe_pinball <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
pinball(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## S3 method for class 'numeric' weighted.pinball(actual, predicted, w, alpha = 0.5, deviance = FALSE, ...)## S3 method for class 'numeric' weighted.pinball(actual, predicted, w, alpha = 0.5, deviance = FALSE, ...)
actual, predicted
|
|
w |
A <double> vector of sample weights. |
alpha |
A <double>-value of length |
deviance |
A <logical>-value of length 1 (default: FALSE). If TRUE the function returns the |
... |
Arguments passed into other methods |
A <double> value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Virtanen, Pauli, et al. "SciPy 1.0: fundamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Regression:
ccc(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
gmse(),
huberloss(),
maape(),
mae(),
mape(),
mpe(),
mse(),
rae(),
rmse(),
rmsle(),
rrmse(),
rrse(),
rsq(),
smape()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Generate sample ## weights sample_weights <- c(0.3, 0.5, 0.3, 0, 0.8, 0.8, 1) ## Evaluate performance SLmetrics::weighted.pinball( actual = actual_values, predicted = predicted_values, w = sample_weights )## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Generate sample ## weights sample_weights <- c(0.3, 0.5, 0.3, 0, 0.8, 0.8, 1) ## Evaluate performance SLmetrics::weighted.pinball( actual = actual_values, predicted = predicted_values, w = sample_weights )
A generic S3 function to compute the positive likelihood ratio score for a classification model. This function dispatches to S3 methods in plr() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because plr() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap plr() in a "safe" validator that checks for NA values and matching length, for example:
safe_plr <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
plr(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate positive likelihood ratio ## via S3 dispatching plr(confusion_matrix) ## additional performance metrics ## below
The plr.factor() method calls cmatrix() internally, so explicitly invoking plr.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## S3 method for class 'factor' weighted.plr(actual, predicted, w, ...)## S3 method for class 'factor' weighted.plr(actual, predicted, w, ...)
actual, predicted
|
A pair of <integer> or <factor> vectors of length |
w |
A <double> vector of sample weights. |
... |
Arguments passed into other methods. |
A <double>-value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
The nlr()-function for the Negative Likehood Ratio (LR-)
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Generate sample ## weights sample_weights <- runif( n = length(actual_classes) ) ## Evaluate performance SLmetrics::weighted.plr( actual = actual_classes, predicted = predicted_classes, w = sample_weights )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Generate sample ## weights sample_weights <- runif( n = length(actual_classes) ) ## Evaluate performance SLmetrics::weighted.plr( actual = actual_classes, predicted = predicted_classes, w = sample_weights )
A generic S3 function to compute the precision recall curve score for a classification model. This function dispatches to S3 methods in pr.curve() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because pr.curve() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap pr.curve() in a "safe" validator that checks for NA values and matching length, for example:
safe_pr.curve <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
pr.curve(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
Use auc.pr.curve for calculating the area under the curve directly.
To avoid sorting the same probability matrix multiple times (once per class or curve), you can precompute a single set of sort indices and pass it via the indices argument. This reduces the overall cost from O(K·N log N) to O(N log N + K·N).
## presort response ## probabilities indices <- preorder(response, decreasing = TRUE) ## evaluate precision recall curve pr.curve(actual, response, indices = indices)
## S3 method for class 'factor' weighted.pr.curve(actual, response, w, thresholds = NULL, indices = NULL, ...)## S3 method for class 'factor' weighted.pr.curve(actual, response, w, thresholds = NULL, indices = NULL, ...)
actual |
|
response |
A |
w |
A <double> vector of sample weights. |
thresholds |
|
indices |
An optional |
... |
Arguments passed into other methods. |
A data.frame on the following form,
threshold |
<numeric> Thresholds used to determine |
level |
|
label |
|
recall |
<numeric> The recall |
precision |
<numeric> The precision |
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual classes ## and response probabilities actual_classes <- factor( x = sample( x = classes, size = 1e2, replace = TRUE, prob = c(0.7, 0.3) ) ) response_probabilities <- ifelse( actual_classes == "Kebab", rbeta(sum(actual_classes == "Kebab"), 2, 5), rbeta(sum(actual_classes == "Falafel"), 5, 2) ) ## Construct response ## matrix probability_matrix <- cbind( response_probabilities, 1 - response_probabilities ) sample_weights <- runif(1e2) ## Visualize plot( SLmetrics::weighted.pr.curve( actual = actual_classes, response = probability_matrix, w = sample_weights ) )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual classes ## and response probabilities actual_classes <- factor( x = sample( x = classes, size = 1e2, replace = TRUE, prob = c(0.7, 0.3) ) ) response_probabilities <- ifelse( actual_classes == "Kebab", rbeta(sum(actual_classes == "Kebab"), 2, 5), rbeta(sum(actual_classes == "Falafel"), 5, 2) ) ## Construct response ## matrix probability_matrix <- cbind( response_probabilities, 1 - response_probabilities ) sample_weights <- runif(1e2) ## Visualize plot( SLmetrics::weighted.pr.curve( actual = actual_classes, response = probability_matrix, w = sample_weights ) )
A generic S3 function to compute the precision score for a classification model. This function dispatches to S3 methods in precision() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because precision() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap precision() in a "safe" validator that checks for NA values and matching length, for example:
safe_precision <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
precision(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate precision ## via S3 dispatching precision(confusion_matrix) ## additional performance metrics ## below
The precision.factor() method calls cmatrix() internally, so explicitly invoking precision.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## S3 method for class 'factor' weighted.precision(actual, predicted, w, estimator = 0L, na.rm = TRUE, ...)## S3 method for class 'factor' weighted.precision(actual, predicted, w, estimator = 0L, na.rm = TRUE, ...)
actual, predicted
|
A pair of <integer> or <factor> vectors of length |
w |
A <double> vector of sample weights. |
estimator |
|
na.rm |
A <logical> value of length |
... |
Arguments passed into other methods. |
If estimator is given as
The precision has other names depending on research field:
Positive Predictive Value, ppv()
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Generate sample ## weights sample_weights <- runif( n = length(actual_classes) ) ## Evaluate performance SLmetrics::weighted.precision( actual = actual_classes, predicted = predicted_classes, w = sample_weights )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Generate sample ## weights sample_weights <- runif( n = length(actual_classes) ) ## Evaluate performance SLmetrics::weighted.precision( actual = actual_classes, predicted = predicted_classes, w = sample_weights )
A generic S3 function to compute the relative absolute error score for a regression model. This function dispatches to S3 methods in rae() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because rae() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap rae() in a "safe" validator that checks for NA values and matching length, for example:
safe_rae <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
rae(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## S3 method for class 'numeric' weighted.rae(actual, predicted, w, ...)## S3 method for class 'numeric' weighted.rae(actual, predicted, w, ...)
actual, predicted
|
|
w |
A <double> vector of sample weights. |
... |
Arguments passed into other methods |
A <double> value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Virtanen, Pauli, et al. "SciPy 1.0: fundamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Regression:
ccc(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
gmse(),
huberloss(),
maape(),
mae(),
mape(),
mpe(),
mse(),
pinball(),
rmse(),
rmsle(),
rrmse(),
rrse(),
rsq(),
smape()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Generate sample ## weights sample_weights <- c(0.3, 0.5, 0.3, 0, 0.8, 0.8, 1) ## Evaluate performance SLmetrics::weighted.rae( actual = actual_values, predicted = predicted_values, w = sample_weights )## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Generate sample ## weights sample_weights <- c(0.3, 0.5, 0.3, 0, 0.8, 0.8, 1) ## Evaluate performance SLmetrics::weighted.rae( actual = actual_values, predicted = predicted_values, w = sample_weights )
A generic S3 function to compute the recall score for a classification model. This function dispatches to S3 methods in recall() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because recall() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap recall() in a "safe" validator that checks for NA values and matching length, for example:
safe_recall <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
recall(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate recall ## via S3 dispatching recall(confusion_matrix) ## additional performance metrics ## below
The recall.factor() method calls cmatrix() internally, so explicitly invoking recall.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## S3 method for class 'factor' weighted.recall(actual, predicted, w, estimator = 0L, na.rm = TRUE, ...)## S3 method for class 'factor' weighted.recall(actual, predicted, w, estimator = 0L, na.rm = TRUE, ...)
actual, predicted
|
A pair of <integer> or <factor> vectors of length |
w |
A <double> vector of sample weights. |
estimator |
|
na.rm |
A <logical> value of length |
... |
Arguments passed into other methods. |
If estimator is given as
The Recall has other names depending on research field:
Sensitivity, sensitivity()
True Positive Rate, tpr()
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Generate sample ## weights sample_weights <- runif( n = length(actual_classes) ) ## Evaluate performance SLmetrics::weighted.recall( actual = actual_classes, predicted = predicted_classes, w = sample_weights )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Generate sample ## weights sample_weights <- runif( n = length(actual_classes) ) ## Evaluate performance SLmetrics::weighted.recall( actual = actual_classes, predicted = predicted_classes, w = sample_weights )
A generic S3 function to compute the root mean squared error score for a regression model. This function dispatches to S3 methods in rmse() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because rmse() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap rmse() in a "safe" validator that checks for NA values and matching length, for example:
safe_rmse <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
rmse(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## S3 method for class 'numeric' weighted.rmse(actual, predicted, w, ...)## S3 method for class 'numeric' weighted.rmse(actual, predicted, w, ...)
actual, predicted
|
|
w |
A <double> vector of sample weights. |
... |
Arguments passed into other methods |
A <double> value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Virtanen, Pauli, et al. "SciPy 1.0: fundamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Regression:
ccc(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
gmse(),
huberloss(),
maape(),
mae(),
mape(),
mpe(),
mse(),
pinball(),
rae(),
rmsle(),
rrmse(),
rrse(),
rsq(),
smape()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Generate sample ## weights sample_weights <- c(0.3, 0.5, 0.3, 0, 0.8, 0.8, 1) ## Evaluate performance SLmetrics::weighted.rmse( actual = actual_values, predicted = predicted_values, w = sample_weights )## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Generate sample ## weights sample_weights <- c(0.3, 0.5, 0.3, 0, 0.8, 0.8, 1) ## Evaluate performance SLmetrics::weighted.rmse( actual = actual_values, predicted = predicted_values, w = sample_weights )
A generic S3 function to compute the root mean squared logarithmic error score for a regression model. This function dispatches to S3 methods in rmsle() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because rmsle() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap rmsle() in a "safe" validator that checks for NA values and matching length, for example:
safe_rmsle <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
rmsle(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## S3 method for class 'numeric' weighted.rmsle(actual, predicted, w, ...)## S3 method for class 'numeric' weighted.rmsle(actual, predicted, w, ...)
actual, predicted
|
|
w |
A <double> vector of sample weights. |
... |
Arguments passed into other methods |
A <double> value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Virtanen, Pauli, et al. "SciPy 1.0: fundamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Regression:
ccc(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
gmse(),
huberloss(),
maape(),
mae(),
mape(),
mpe(),
mse(),
pinball(),
rae(),
rmse(),
rrmse(),
rrse(),
rsq(),
smape()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Generate sample ## weights sample_weights <- c(0.3, 0.5, 0.3, 0, 0.8, 0.8, 1) ## Evaluate performance SLmetrics::weighted.rmsle( actual = actual_values, predicted = predicted_values, w = sample_weights )## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Generate sample ## weights sample_weights <- c(0.3, 0.5, 0.3, 0, 0.8, 0.8, 1) ## Evaluate performance SLmetrics::weighted.rmsle( actual = actual_values, predicted = predicted_values, w = sample_weights )
A generic S3 function to compute the reciever operator characteristics score for a classification model. This function dispatches to S3 methods in roc.curve() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because roc.curve() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap roc.curve() in a "safe" validator that checks for NA values and matching length, for example:
safe_roc.curve <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
roc.curve(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
Use auc.roc.curve for calculating the area under the curve directly.
To avoid sorting the same probability matrix multiple times (once per class or curve), you can precompute a single set of sort indices and pass it via the indices argument. This reduces the overall cost from O(K·N log N) to O(N log N + K·N).
## presort response ## probabilities indices <- preorder(response, decreasing = TRUE) ## evaluate reciever operator characteristics roc.curve(actual, response, indices = indices)
## S3 method for class 'factor' weighted.roc.curve(actual, response, w, thresholds = NULL, indices = NULL, ...)## S3 method for class 'factor' weighted.roc.curve(actual, response, w, thresholds = NULL, indices = NULL, ...)
actual |
|
response |
A |
w |
A <double> vector of sample weights. |
thresholds |
|
indices |
An optional |
... |
Arguments passed into other methods. |
A data.frame on the following form,
threshold |
|
level |
|
label |
|
fpr |
<numeric> The false positive rate |
tpr |
<numeric> The true positve rate |
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
shannon.entropy(),
specificity(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual classes ## and response probabilities actual_classes <- factor( x = sample( x = classes, size = 1e2, replace = TRUE, prob = c(0.7, 0.3) ) ) response_probabilities <- ifelse( actual_classes == "Kebab", rbeta(sum(actual_classes == "Kebab"), 2, 5), rbeta(sum(actual_classes == "Falafel"), 5, 2) ) ## Construct response ## matrix probability_matrix <- cbind( response_probabilities, 1 - response_probabilities ) sample_weights <- runif(1e2) ## Visualize plot( SLmetrics::weighted.roc.curve( actual = actual_classes, response = probability_matrix, w = sample_weights ) )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual classes ## and response probabilities actual_classes <- factor( x = sample( x = classes, size = 1e2, replace = TRUE, prob = c(0.7, 0.3) ) ) response_probabilities <- ifelse( actual_classes == "Kebab", rbeta(sum(actual_classes == "Kebab"), 2, 5), rbeta(sum(actual_classes == "Falafel"), 5, 2) ) ## Construct response ## matrix probability_matrix <- cbind( response_probabilities, 1 - response_probabilities ) sample_weights <- runif(1e2) ## Visualize plot( SLmetrics::weighted.roc.curve( actual = actual_classes, response = probability_matrix, w = sample_weights ) )
A generic S3 function to compute the relative root mean squared error score for a regression model. This function dispatches to S3 methods in rrmse() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because rrmse() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap rrmse() in a "safe" validator that checks for NA values and matching length, for example:
safe_rrmse <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
rrmse(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## S3 method for class 'numeric' weighted.rrmse(actual, predicted, w, normalization = 1L, ...)## S3 method for class 'numeric' weighted.rrmse(actual, predicted, w, normalization = 1L, ...)
actual, predicted
|
|
w |
A <double> vector of sample weights. |
normalization |
A <double>-value of length |
... |
Arguments passed into other methods |
A <double> value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Virtanen, Pauli, et al. "SciPy 1.0: fundamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Regression:
ccc(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
gmse(),
huberloss(),
maape(),
mae(),
mape(),
mpe(),
mse(),
pinball(),
rae(),
rmse(),
rmsle(),
rrse(),
rsq(),
smape()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Generate sample ## weights sample_weights <- c(0.3, 0.5, 0.3, 0, 0.8, 0.8, 1) ## Evaluate performance SLmetrics::weighted.rrmse( actual = actual_values, predicted = predicted_values, w = sample_weights )## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Generate sample ## weights sample_weights <- c(0.3, 0.5, 0.3, 0, 0.8, 0.8, 1) ## Evaluate performance SLmetrics::weighted.rrmse( actual = actual_values, predicted = predicted_values, w = sample_weights )
A generic S3 function to compute the root relative squared error score for a regression model. This function dispatches to S3 methods in rrse() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because rrse() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap rrse() in a "safe" validator that checks for NA values and matching length, for example:
safe_rrse <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
rrse(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## S3 method for class 'numeric' weighted.rrse(actual, predicted, w, ...)## S3 method for class 'numeric' weighted.rrse(actual, predicted, w, ...)
actual, predicted
|
|
w |
A <double> vector of sample weights. |
... |
Arguments passed into other methods |
A <double> value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Virtanen, Pauli, et al. "SciPy 1.0: fundamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Regression:
ccc(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
gmse(),
huberloss(),
maape(),
mae(),
mape(),
mpe(),
mse(),
pinball(),
rae(),
rmse(),
rmsle(),
rrmse(),
rsq(),
smape()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rsq(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Generate sample ## weights sample_weights <- c(0.3, 0.5, 0.3, 0, 0.8, 0.8, 1) ## Evaluate performance SLmetrics::weighted.rrse( actual = actual_values, predicted = predicted_values, w = sample_weights )## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Generate sample ## weights sample_weights <- c(0.3, 0.5, 0.3, 0, 0.8, 0.8, 1) ## Evaluate performance SLmetrics::weighted.rrse( actual = actual_values, predicted = predicted_values, w = sample_weights )
A generic S3 function to compute the score for a regression model. This function dispatches to S3 methods in rsq() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because rsq() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap rsq() in a "safe" validator that checks for NA values and matching length, for example:
safe_rsq <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
rsq(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## S3 method for class 'numeric' weighted.rsq(actual, predicted, w, k = 0, ...)## S3 method for class 'numeric' weighted.rsq(actual, predicted, w, k = 0, ...)
actual, predicted
|
|
w |
A <double> vector of sample weights. |
k |
A <double>-vector of length 1 (default: 0). For adjusted |
... |
Arguments passed into other methods |
A <double> value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Virtanen, Pauli, et al. "SciPy 1.0: fundamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Regression:
ccc(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
gmse(),
huberloss(),
maape(),
mae(),
mape(),
mpe(),
mse(),
pinball(),
rae(),
rmse(),
rmsle(),
rrmse(),
rrse(),
smape()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
shannon.entropy(),
smape(),
specificity(),
zerooneloss()
## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Generate sample ## weights sample_weights <- c(0.3, 0.5, 0.3, 0, 0.8, 0.8, 1) ## Evaluate performance SLmetrics::weighted.rsq( actual = actual_values, predicted = predicted_values, w = sample_weights )## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Generate sample ## weights sample_weights <- c(0.3, 0.5, 0.3, 0, 0.8, 0.8, 1) ## Evaluate performance SLmetrics::weighted.rsq( actual = actual_values, predicted = predicted_values, w = sample_weights )
A generic S3 function to compute the symmetric mean absolutte percentage error score for a regression model. This function dispatches to S3 methods in smape() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because smape() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap smape() in a "safe" validator that checks for NA values and matching length, for example:
safe_smape <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
smape(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
## S3 method for class 'numeric' weighted.smape(actual, predicted, w, ...)## S3 method for class 'numeric' weighted.smape(actual, predicted, w, ...)
actual, predicted
|
|
w |
A <double> vector of sample weights. |
... |
Arguments passed into other methods |
A <double> value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Virtanen, Pauli, et al. "SciPy 1.0: fundamental algorithms for scientific computing in Python." Nature methods 17.3 (2020): 261-272.
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Regression:
ccc(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
gmse(),
huberloss(),
maape(),
mae(),
mape(),
mpe(),
mse(),
pinball(),
rae(),
rmse(),
rmsle(),
rrmse(),
rrse(),
rsq()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
specificity(),
zerooneloss()
## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Generate sample ## weights sample_weights <- c(0.3, 0.5, 0.3, 0, 0.8, 0.8, 1) ## Evaluate performance SLmetrics::weighted.smape( actual = actual_values, predicted = predicted_values, w = sample_weights )## Generate actual ## and predicted values actual_values <- c(1.3, 0.4, 1.2, 1.4, 1.9, 1.0, 1.2) predicted_values <- c(0.7, 0.5, 1.1, 1.2, 1.8, 1.1, 0.2) ## Generate sample ## weights sample_weights <- c(0.3, 0.5, 0.3, 0, 0.8, 0.8, 1) ## Evaluate performance SLmetrics::weighted.smape( actual = actual_values, predicted = predicted_values, w = sample_weights )
A generic S3 function to compute the specificity score for a classification model. This function dispatches to S3 methods in specificity() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because specificity() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap specificity() in a "safe" validator that checks for NA values and matching length, for example:
safe_specificity <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
specificity(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate specificity ## via S3 dispatching specificity(confusion_matrix) ## additional performance metrics ## below
The specificity.factor() method calls cmatrix() internally, so explicitly invoking specificity.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## S3 method for class 'factor' weighted.specificity(actual, predicted, w, estimator = 0L, na.rm = TRUE, ...)## S3 method for class 'factor' weighted.specificity(actual, predicted, w, estimator = 0L, na.rm = TRUE, ...)
actual, predicted
|
A pair of <integer> or <factor> vectors of length |
w |
A <double> vector of sample weights. |
estimator |
|
na.rm |
A <logical> value of length |
... |
Arguments passed into other methods. |
If estimator is given as
The specificity has other names depending on research field:
True Negative Rate, tnr()
Selectivity, selectivity()
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
zerooneloss()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
zerooneloss()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Generate sample ## weights sample_weights <- runif( n = length(actual_classes) ) ## Evaluate performance SLmetrics::weighted.specificity( actual = actual_classes, predicted = predicted_classes, w = sample_weights )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Generate sample ## weights sample_weights <- runif( n = length(actual_classes) ) ## Evaluate performance SLmetrics::weighted.specificity( actual = actual_classes, predicted = predicted_classes, w = sample_weights )
A generic S3 function to compute the zero-one loss score for a classification model. This function dispatches to S3 methods in zerooneloss() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because zerooneloss() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap zerooneloss() in a "safe" validator that checks for NA values and matching length, for example:
safe_zerooneloss <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
zerooneloss(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate zero-one loss ## via S3 dispatching zerooneloss(confusion_matrix) ## additional performance metrics ## below
The zerooneloss.factor() method calls cmatrix() internally, so explicitly invoking zerooneloss.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## S3 method for class 'factor' weighted.zerooneloss(actual, predicted, w, ...)## S3 method for class 'factor' weighted.zerooneloss(actual, predicted, w, ...)
actual, predicted
|
A pair of <integer> or <factor> vectors of length |
w |
A <double> vector of sample weights. |
... |
Arguments passed into other methods. |
A <double>-value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Generate sample ## weights sample_weights <- runif( n = length(actual_classes) ) ## Evaluate performance SLmetrics::weighted.zerooneloss( actual = actual_classes, predicted = predicted_classes, w = sample_weights )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Generate sample ## weights sample_weights <- runif( n = length(actual_classes) ) ## Evaluate performance SLmetrics::weighted.zerooneloss( actual = actual_classes, predicted = predicted_classes, w = sample_weights )
This dataset contains measurements of various chemical properties of white wines along with their quality ratings and a quality classification. The dataset was obtained from the UCI Machine Learning Repository.
The data is provided as a list with two components:
A data frame containing the chemical properties of the wines. The variables include:
Fixed acidity (g/L).
Volatile acidity (g/L), mainly due to acetic acid.
Citric acid (g/L).
Residual sugar (g/L).
Chloride concentration (g/L).
Free sulfur dioxide (mg/L).
Total sulfur dioxide (mg/L).
Density of the wine (g/cm).
pH value of the wine.
Sulphates (g/L).
Alcohol content (% by volume).
A list containing two elements:
A numeric vector representing the wine quality scores (used as the regression target).
A factor with levels "High Quality", "Medium Quality", and "Low Quality",
where classification is determined as follows:
quality 7.
quality 4.
for all other quality scores.
data(wine.quality)data(wine.quality)
A list with two components:
A data frame with 11 chemical property variables.
A list with two elements: regression (wine quality scores) and class (quality classification).
Cortez, Paulo, et al. "Modeling wine preferences by data mining from physicochemical properties." Decision support systems 47.4 (2009): 547-553.
A generic S3 function to compute the zero-one loss score for a classification model. This function dispatches to S3 methods in zerooneloss() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because zerooneloss() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap zerooneloss() in a "safe" validator that checks for NA values and matching length, for example:
safe_zerooneloss <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
zerooneloss(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate zero-one loss ## via S3 dispatching zerooneloss(confusion_matrix) ## additional performance metrics ## below
The zerooneloss.factor() method calls cmatrix() internally, so explicitly invoking zerooneloss.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## Generic S3 method ## for Zero-One Loss zerooneloss(...) ## Generic S3 method ## for weighted Zero-One Loss weighted.zerooneloss(...)## Generic S3 method ## for Zero-One Loss zerooneloss(...) ## Generic S3 method ## for weighted Zero-One Loss weighted.zerooneloss(...)
... |
Arguments passed on to |
A <double>-value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::zerooneloss( actual = actual_classes, predicted = predicted_classes )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::zerooneloss( actual = actual_classes, predicted = predicted_classes )
A generic S3 function to compute the zero-one loss score for a classification model. This function dispatches to S3 methods in zerooneloss() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because zerooneloss() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap zerooneloss() in a "safe" validator that checks for NA values and matching length, for example:
safe_zerooneloss <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
zerooneloss(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate zero-one loss ## via S3 dispatching zerooneloss(confusion_matrix) ## additional performance metrics ## below
The zerooneloss.factor() method calls cmatrix() internally, so explicitly invoking zerooneloss.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## S3 method for class 'cmatrix' zerooneloss(x, ...)## S3 method for class 'cmatrix' zerooneloss(x, ...)
x |
A confusion matrix created |
... |
Arguments passed into other methods. |
A <double>-value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Construct confusion ## matrix confusion_matrix <- SLmetrics::cmatrix( actual = actual_classes, predicted = predicted_classes ) ## Evaluate performance SLmetrics::zerooneloss(confusion_matrix)## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Construct confusion ## matrix confusion_matrix <- SLmetrics::cmatrix( actual = actual_classes, predicted = predicted_classes ) ## Evaluate performance SLmetrics::zerooneloss(confusion_matrix)
A generic S3 function to compute the zero-one loss score for a classification model. This function dispatches to S3 methods in zerooneloss() and performs no input validation. If you supply NA values or vectors of unequal length (e.g. length(x) != length(y)), the underlying C++ code may trigger undefined behavior and crash your R session.
Because zerooneloss() operates on raw pointers, pointer-level faults (e.g. from NA or mismatched length) occur before any R-level error handling. Wrapping calls in try() or tryCatch() will not prevent R-session crashes.
To guard against this, wrap zerooneloss() in a "safe" validator that checks for NA values and matching length, for example:
safe_zerooneloss <- function(x, y, ...) {
stopifnot(
!anyNA(x), !anyNA(y),
length(x) == length(y)
)
zerooneloss(x, y, ...)
}
Apply the same pattern to any custom metric functions to ensure input sanity before calling the underlying C++ code.
For multiple performance evaluations of a classification model, first compute the confusion matrix once via cmatrix(). All other performance metrics can then be derived from this one object via S3 dispatching:
## compute confusion matrix confusion_matrix <- cmatrix(actual, predicted) ## evaluate zero-one loss ## via S3 dispatching zerooneloss(confusion_matrix) ## additional performance metrics ## below
The zerooneloss.factor() method calls cmatrix() internally, so explicitly invoking zerooneloss.cmatrix() yourself avoids duplicate computation, yielding significant speed and memory effciency gains when you need multiple evaluation metrics.
## S3 method for class 'factor' zerooneloss(actual, predicted, ...)## S3 method for class 'factor' zerooneloss(actual, predicted, ...)
actual, predicted
|
A pair of <integer> or <factor> vectors of length |
... |
Arguments passed into other methods. |
A <double>-value
James, Gareth, et al. An introduction to statistical learning. Vol. 112. No. 1. New York: springer, 2013.
Hastie, Trevor. "The elements of statistical learning: data mining, inference, and prediction." (2009).
Pedregosa, Fabian, et al. "Scikit-learn: Machine learning in Python." the Journal of machine Learning research 12 (2011): 2825-2830.
Other Classification:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ckappa(),
cmatrix(),
cross.entropy(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
hammingloss(),
jaccard(),
logloss(),
mcc(),
nlr(),
npv(),
plr(),
pr.curve(),
precision(),
recall(),
relative.entropy(),
roc.curve(),
shannon.entropy(),
specificity()
Other Supervised Learning:
accuracy(),
auc.pr.curve(),
auc.roc.curve(),
baccuracy(),
brier.score(),
ccc(),
ckappa(),
cmatrix(),
cross.entropy(),
deviance.gamma(),
deviance.poisson(),
deviance.tweedie(),
dor(),
fbeta(),
fdr(),
fer(),
fmi(),
fpr(),
gmse(),
hammingloss(),
huberloss(),
jaccard(),
logloss(),
maape(),
mae(),
mape(),
mcc(),
mpe(),
mse(),
nlr(),
npv(),
pinball(),
plr(),
pr.curve(),
precision(),
rae(),
recall(),
relative.entropy(),
rmse(),
rmsle(),
roc.curve(),
rrmse(),
rrse(),
rsq(),
shannon.entropy(),
smape(),
specificity()
## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::zerooneloss( actual = actual_classes, predicted = predicted_classes )## Classes and ## seed set.seed(1903) classes <- c("Kebab", "Falafel") ## Generate actual ## and predicted classes actual_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) predicted_classes <- factor( x = sample(x = classes, size = 1e3, replace = TRUE), levels = c("Kebab", "Falafel") ) ## Evaluate performance SLmetrics::zerooneloss( actual = actual_classes, predicted = predicted_classes )