Title: | Machine Learning Evaluation Metrics |
---|---|
Description: | A collection of evaluation metrics, including loss, score and utility functions, that measure regression, classification and ranking performance. |
Authors: | Yachen Yan [aut, cre] |
Maintainer: | Yachen Yan <[email protected]> |
License: | GPL-2 |
Version: | 1.1.3 |
Built: | 2025-01-09 03:53:49 UTC |
Source: | https://github.com/yanyachen/mlmetrics |
Compute the accuracy classification score.
Accuracy(y_pred, y_true)
Accuracy(y_pred, y_true)
y_pred |
Predicted labels vector, as returned by a classifier |
y_true |
Ground truth (correct) 0-1 labels vector |
Accuracy
data(cars) logreg <- glm(formula = vs ~ hp + wt, family = binomial(link = "logit"), data = mtcars) pred <- ifelse(logreg$fitted.values < 0.5, 0, 1) Accuracy(y_pred = pred, y_true = mtcars$vs)
data(cars) logreg <- glm(formula = vs ~ hp + wt, family = binomial(link = "logit"), data = mtcars) pred <- ifelse(logreg$fitted.values < 0.5, 0, 1) Accuracy(y_pred = pred, y_true = mtcars$vs)
Calculate the area under the curve.
Area_Under_Curve(x, y, method = c("trapezoid", "step", "spline"), na.rm = FALSE)
Area_Under_Curve(x, y, method = c("trapezoid", "step", "spline"), na.rm = FALSE)
x |
the x-points of the curve |
y |
the y-points of the curve |
method |
can be "trapezoid" (default), "step" or "spline" |
na.rm |
a logical value indicating whether NA values should be stripped before the computation proceeds |
Area Under the Curve (AUC)
x <- seq(0, pi, length.out = 200) plot(x = x, y = sin(x), type = "l") Area_Under_Curve(x = x, y = sin(x), method = "trapezoid", na.rm = TRUE)
x <- seq(0, pi, length.out = 200) plot(x = x, y = sin(x), type = "l") Area_Under_Curve(x = x, y = sin(x), method = "trapezoid", na.rm = TRUE)
Compute the Area Under the Receiver Operating Characteristic Curve (ROC AUC) from prediction scores.
AUC(y_pred, y_true)
AUC(y_pred, y_true)
y_pred |
Predicted probabilities vector, as returned by a classifier |
y_true |
Ground truth (correct) 0-1 labels vector |
Area Under the ROC Curve (ROC AUC)
data(cars) logreg <- glm(formula = vs ~ hp + wt, family = binomial(link = "logit"), data = mtcars) AUC(y_pred = logreg$fitted.values, y_true = mtcars$vs)
data(cars) logreg <- glm(formula = vs ~ hp + wt, family = binomial(link = "logit"), data = mtcars) AUC(y_pred = logreg$fitted.values, y_true = mtcars$vs)
Compute confusion matrix to evaluate the accuracy of a classification.
ConfusionMatrix(y_pred, y_true)
ConfusionMatrix(y_pred, y_true)
y_pred |
Predicted labels vector, as returned by a classifier |
y_true |
Ground truth (correct) 0-1 labels vector |
a table of Confusion Matrix
data(cars) logreg <- glm(formula = vs ~ hp + wt, family = binomial(link = "logit"), data = mtcars) pred <- ifelse(logreg$fitted.values < 0.5, 0, 1) ConfusionMatrix(y_pred = pred, y_true = mtcars$vs)
data(cars) logreg <- glm(formula = vs ~ hp + wt, family = binomial(link = "logit"), data = mtcars) pred <- ifelse(logreg$fitted.values < 0.5, 0, 1) ConfusionMatrix(y_pred = pred, y_true = mtcars$vs)
Compute the F1 Score.
F1_Score(y_true, y_pred, positive = NULL)
F1_Score(y_true, y_pred, positive = NULL)
y_true |
Ground truth (correct) 0-1 labels vector |
y_pred |
Predicted labels vector, as returned by a classifier |
positive |
An optional character string for the factor level that corresponds to a "positive" result |
F1 Score
data(cars) logreg <- glm(formula = vs ~ hp + wt, family = binomial(link = "logit"), data = mtcars) pred <- ifelse(logreg$fitted.values < 0.5, 0, 1) F1_Score(y_pred = pred, y_true = mtcars$vs, positive = "0") F1_Score(y_pred = pred, y_true = mtcars$vs, positive = "1")
data(cars) logreg <- glm(formula = vs ~ hp + wt, family = binomial(link = "logit"), data = mtcars) pred <- ifelse(logreg$fitted.values < 0.5, 0, 1) F1_Score(y_pred = pred, y_true = mtcars$vs, positive = "0") F1_Score(y_pred = pred, y_true = mtcars$vs, positive = "1")
Compute the F-Beta Score
FBeta_Score(y_true, y_pred, positive = NULL, beta = 1)
FBeta_Score(y_true, y_pred, positive = NULL, beta = 1)
y_true |
Ground truth (correct) 0-1 labels vector |
y_pred |
Predicted labels vector, as returned by a classifier |
positive |
An optional character string for the factor level that corresponds to a "positive" result |
beta |
Weight of precision in harmonic mean |
F-Beta Score
data(cars) logreg <- glm(formula = vs ~ hp + wt, family = binomial(link = "logit"), data = mtcars) pred <- ifelse(logreg$fitted.values < 0.5, 0, 1) FBeta_Score(y_pred = pred, y_true = mtcars$vs, positive = "0", beta = 2) FBeta_Score(y_pred = pred, y_true = mtcars$vs, positive = "1", beta = 2)
data(cars) logreg <- glm(formula = vs ~ hp + wt, family = binomial(link = "logit"), data = mtcars) pred <- ifelse(logreg$fitted.values < 0.5, 0, 1) FBeta_Score(y_pred = pred, y_true = mtcars$vs, positive = "0", beta = 2) FBeta_Score(y_pred = pred, y_true = mtcars$vs, positive = "1", beta = 2)
Compute the Area Under the Gain Chart from prediction scores.
GainAUC(y_pred, y_true)
GainAUC(y_pred, y_true)
y_pred |
Predicted probabilities vector, as returned by a classifier |
y_true |
Ground truth (correct) 0-1 labels vector |
Area Under the Gain Chart
data(cars) logreg <- glm(formula = vs ~ hp + wt, family = binomial(link = "logit"), data = mtcars) GainAUC(y_pred = logreg$fitted.values, y_true = mtcars$vs)
data(cars) logreg <- glm(formula = vs ~ hp + wt, family = binomial(link = "logit"), data = mtcars) GainAUC(y_pred = logreg$fitted.values, y_true = mtcars$vs)
Compute the Gini Coefficient.
Gini(y_pred, y_true)
Gini(y_pred, y_true)
y_pred |
Predicted probabilities vector, as returned by a classifier |
y_true |
Ground truth (correct) 0-1 labels vector |
Gini Coefficient
data(cars) logreg <- glm(formula = vs ~ hp + wt, family = binomial(link = "logit"), data = mtcars) Gini(y_pred = logreg$fitted.values, y_true = mtcars$vs)
data(cars) logreg <- glm(formula = vs ~ hp + wt, family = binomial(link = "logit"), data = mtcars) Gini(y_pred = logreg$fitted.values, y_true = mtcars$vs)
Compute the Kolmogorov-Smirnov statistic.
KS_Stat(y_pred, y_true)
KS_Stat(y_pred, y_true)
y_pred |
Predicted probabilities vector, as returned by a classifier |
y_true |
Ground truth (correct) 0-1 labels vector |
Kolmogorov-Smirnov statistic
data(cars) logreg <- glm(formula = vs ~ hp + wt, family = binomial(link = "logit"), data = mtcars) KS_Stat(y_pred = logreg$fitted.values, y_true = mtcars$vs)
data(cars) logreg <- glm(formula = vs ~ hp + wt, family = binomial(link = "logit"), data = mtcars) KS_Stat(y_pred = logreg$fitted.values, y_true = mtcars$vs)
Compute the Area Under the Lift Chart from prediction scores.
LiftAUC(y_pred, y_true)
LiftAUC(y_pred, y_true)
y_pred |
Predicted probabilities vector, as returned by a classifier |
y_true |
Ground truth (correct) 0-1 labels vector |
Area Under the Lift Chart
data(cars) logreg <- glm(formula = vs ~ hp + wt, family = binomial(link = "logit"), data = mtcars) LiftAUC(y_pred = logreg$fitted.values, y_true = mtcars$vs)
data(cars) logreg <- glm(formula = vs ~ hp + wt, family = binomial(link = "logit"), data = mtcars) LiftAUC(y_pred = logreg$fitted.values, y_true = mtcars$vs)
Compute the log loss/cross-entropy loss.
LogLoss(y_pred, y_true)
LogLoss(y_pred, y_true)
y_pred |
Predicted probabilities vector, as returned by a classifier |
y_true |
Ground truth (correct) 0-1 labels vector |
Log loss/Cross-Entropy Loss
data(cars) logreg <- glm(formula = vs ~ hp + wt, family = binomial(link = "logit"), data = mtcars) LogLoss(y_pred = logreg$fitted.values, y_true = mtcars$vs)
data(cars) logreg <- glm(formula = vs ~ hp + wt, family = binomial(link = "logit"), data = mtcars) LogLoss(y_pred = logreg$fitted.values, y_true = mtcars$vs)
Compute the mean absolute error regression loss.
MAE(y_pred, y_true)
MAE(y_pred, y_true)
y_pred |
Estimated target values vector |
y_true |
Ground truth (correct) target values vector |
Mean Absolute Error Loss
data(cars) reg <- lm(log(dist) ~ log(speed), data = cars) MAE(y_pred = exp(reg$fitted.values), y_true = cars$dist)
data(cars) reg <- lm(log(dist) ~ log(speed), data = cars) MAE(y_pred = exp(reg$fitted.values), y_true = cars$dist)
Compute the mean absolute percentage error regression loss.
MAPE(y_pred, y_true)
MAPE(y_pred, y_true)
y_pred |
Estimated target values vector |
y_true |
Ground truth (correct) target values vector |
Mean Absolute Percentage Error Loss
data(cars) reg <- lm(log(dist) ~ log(speed), data = cars) MAPE(y_pred = exp(reg$fitted.values), y_true = cars$dist)
data(cars) reg <- lm(log(dist) ~ log(speed), data = cars) MAPE(y_pred = exp(reg$fitted.values), y_true = cars$dist)
Compute the median absolute error regression loss.
MedianAE(y_pred, y_true)
MedianAE(y_pred, y_true)
y_pred |
Estimated target values vector |
y_true |
Ground truth (correct) target values vector |
Median Absolute Error Loss
data(cars) reg <- lm(log(dist) ~ log(speed), data = cars) MedianAE(y_pred = exp(reg$fitted.values), y_true = cars$dist)
data(cars) reg <- lm(log(dist) ~ log(speed), data = cars) MedianAE(y_pred = exp(reg$fitted.values), y_true = cars$dist)
Compute the Median absolute percentage error regression loss.
MedianAPE(y_pred, y_true)
MedianAPE(y_pred, y_true)
y_pred |
Estimated target values vector |
y_true |
Ground truth (correct) target values vector |
Median Absolute Percentage Error Loss
data(cars) reg <- lm(log(dist) ~ log(speed), data = cars) MedianAPE(y_pred = exp(reg$fitted.values), y_true = cars$dist)
data(cars) reg <- lm(log(dist) ~ log(speed), data = cars) MedianAPE(y_pred = exp(reg$fitted.values), y_true = cars$dist)
A collection of evaluation metrics, including loss, score and utility functions, that measure regression and classification performance.
Compute the mean squared error regression loss.
MSE(y_pred, y_true)
MSE(y_pred, y_true)
y_pred |
Estimated target values vector |
y_true |
Ground truth (correct) target values vector |
Mean Square Error Loss
data(cars) reg <- lm(log(dist) ~ log(speed), data = cars) MSE(y_pred = exp(reg$fitted.values), y_true = cars$dist)
data(cars) reg <- lm(log(dist) ~ log(speed), data = cars) MSE(y_pred = exp(reg$fitted.values), y_true = cars$dist)
Compute the multi class log loss.
MultiLogLoss(y_pred, y_true)
MultiLogLoss(y_pred, y_true)
y_pred |
Predicted probabilities matrix, as returned by a classifier |
y_true |
Ground truth (correct) labels vector or a matrix of correct labels indicating by 0-1, same format as probabilities matrix |
Multi Class Log Loss
data(iris) svm.model <- e1071::svm(Species~., data = iris, probability = TRUE) pred <- predict(svm.model, iris, probability = TRUE) MultiLogLoss(y_true = iris$Species, y_pred = attr(pred, "probabilities"))
data(iris) svm.model <- e1071::svm(Species~., data = iris, probability = TRUE) pred <- predict(svm.model, iris, probability = TRUE) MultiLogLoss(y_true = iris$Species, y_pred = attr(pred, "probabilities"))
Compute the Normalized Gini Coefficient.
NormalizedGini(y_pred, y_true)
NormalizedGini(y_pred, y_true)
y_pred |
Predicted labels vector, as returned by a model |
y_true |
Ground truth (correct) labels vector |
Normalized Gini Coefficient
d_AD <- data.frame(treatment = gl(3,3), outcome = gl(3,1,9), counts = c(18,17,15,20,10,20,25,13,12)) glm_poisson <- glm(counts ~ outcome + treatment, family = poisson(link = "log"), data = d_AD) NormalizedGini(y_pred = glm_poisson$fitted.values, y_true = d_AD$counts)
d_AD <- data.frame(treatment = gl(3,3), outcome = gl(3,1,9), counts = c(18,17,15,20,10,20,25,13,12)) glm_poisson <- glm(counts ~ outcome + treatment, family = poisson(link = "log"), data = d_AD) NormalizedGini(y_pred = glm_poisson$fitted.values, y_true = d_AD$counts)
Compute the log loss/cross-entropy loss.
Poisson_LogLoss(y_pred, y_true)
Poisson_LogLoss(y_pred, y_true)
y_pred |
Predicted labels vector, as returned by a model |
y_true |
Ground truth (correct) labels vector |
Log loss/Cross-Entropy Loss
d_AD <- data.frame(treatment = gl(3,3), outcome = gl(3,1,9), counts = c(18,17,15,20,10,20,25,13,12)) glm_poisson <- glm(counts ~ outcome + treatment, family = poisson(link = "log"), data = d_AD) Poisson_LogLoss(y_pred = glm_poisson$fitted.values, y_true = d_AD$counts)
d_AD <- data.frame(treatment = gl(3,3), outcome = gl(3,1,9), counts = c(18,17,15,20,10,20,25,13,12)) glm_poisson <- glm(counts ~ outcome + treatment, family = poisson(link = "log"), data = d_AD) Poisson_LogLoss(y_pred = glm_poisson$fitted.values, y_true = d_AD$counts)
Compute the Area Under the Precision-Recall Curve (PR AUC) from prediction scores.
PRAUC(y_pred, y_true)
PRAUC(y_pred, y_true)
y_pred |
Predicted probabilities vector, as returned by a classifier |
y_true |
Ground truth (correct) 0-1 labels vector |
Area Under the PR Curve (PR AUC)
data(cars) logreg <- glm(formula = vs ~ hp + wt, family = binomial(link = "logit"), data = mtcars) PRAUC(y_pred = logreg$fitted.values, y_true = mtcars$vs)
data(cars) logreg <- glm(formula = vs ~ hp + wt, family = binomial(link = "logit"), data = mtcars) PRAUC(y_pred = logreg$fitted.values, y_true = mtcars$vs)
Compute the precision score.
Precision(y_true, y_pred, positive = NULL)
Precision(y_true, y_pred, positive = NULL)
y_true |
Ground truth (correct) 0-1 labels vector |
y_pred |
Predicted labels vector, as returned by a classifier |
positive |
An optional character string for the factor level that corresponds to a "positive" result |
Precision
data(cars) logreg <- glm(formula = vs ~ hp + wt, family = binomial(link = "logit"), data = mtcars) pred <- ifelse(logreg$fitted.values < 0.5, 0, 1) Precision(y_pred = pred, y_true = mtcars$vs, positive = "0") Precision(y_pred = pred, y_true = mtcars$vs, positive = "1")
data(cars) logreg <- glm(formula = vs ~ hp + wt, family = binomial(link = "logit"), data = mtcars) pred <- ifelse(logreg$fitted.values < 0.5, 0, 1) Precision(y_pred = pred, y_true = mtcars$vs, positive = "0") Precision(y_pred = pred, y_true = mtcars$vs, positive = "1")
Compute the R-Squared (Coefficient of Determination) Regression Score.
R2_Score(y_pred, y_true)
R2_Score(y_pred, y_true)
y_pred |
Estimated target values vector |
y_true |
Ground truth (correct) target values vector |
R^2 Score
data(cars) reg <- lm(log(dist) ~ log(speed), data = cars) R2_Score(y_pred = exp(reg$fitted.values), y_true = cars$dist)
data(cars) reg <- lm(log(dist) ~ log(speed), data = cars) R2_Score(y_pred = exp(reg$fitted.values), y_true = cars$dist)
Compute the relative absolute error regression loss.
RAE(y_pred, y_true)
RAE(y_pred, y_true)
y_pred |
Estimated target values vector |
y_true |
Ground truth (correct) target values vector |
Relative Absolute Error Loss
data(cars) reg <- lm(log(dist) ~ log(speed), data = cars) RAE(y_pred = exp(reg$fitted.values), y_true = cars$dist)
data(cars) reg <- lm(log(dist) ~ log(speed), data = cars) RAE(y_pred = exp(reg$fitted.values), y_true = cars$dist)
Compute the recall score.
Recall(y_true, y_pred, positive = NULL)
Recall(y_true, y_pred, positive = NULL)
y_true |
Ground truth (correct) 0-1 labels vector |
y_pred |
Predicted labels vector, as returned by a classifier |
positive |
An optional character string for the factor level that corresponds to a "positive" result |
Recall
data(cars) logreg <- glm(formula = vs ~ hp + wt, family = binomial(link = "logit"), data = mtcars) pred <- ifelse(logreg$fitted.values < 0.5, 0, 1) Recall(y_pred = pred, y_true = mtcars$vs, positive = "0") Recall(y_pred = pred, y_true = mtcars$vs, positive = "1")
data(cars) logreg <- glm(formula = vs ~ hp + wt, family = binomial(link = "logit"), data = mtcars) pred <- ifelse(logreg$fitted.values < 0.5, 0, 1) Recall(y_pred = pred, y_true = mtcars$vs, positive = "0") Recall(y_pred = pred, y_true = mtcars$vs, positive = "1")
Compute the root mean squared error regression loss.
RMSE(y_pred, y_true)
RMSE(y_pred, y_true)
y_pred |
Estimated target values vector |
y_true |
Ground truth (correct) target values vector |
Root Mean Square Error Loss
data(cars) reg <- lm(log(dist) ~ log(speed), data = cars) RMSE(y_pred = exp(reg$fitted.values), y_true = cars$dist)
data(cars) reg <- lm(log(dist) ~ log(speed), data = cars) RMSE(y_pred = exp(reg$fitted.values), y_true = cars$dist)
Compute the root mean squared logarithmic error regression loss.
RMSLE(y_pred, y_true)
RMSLE(y_pred, y_true)
y_pred |
Estimated target values vector |
y_true |
Ground truth (correct) target values vector |
Root Mean Squared Logarithmic Error Loss
data(cars) reg <- lm(log(dist) ~ log(speed), data = cars) RMSLE(y_pred = exp(reg$fitted.values), y_true = cars$dist)
data(cars) reg <- lm(log(dist) ~ log(speed), data = cars) RMSLE(y_pred = exp(reg$fitted.values), y_true = cars$dist)
Compute the root mean squared percentage error regression loss.
RMSPE(y_pred, y_true)
RMSPE(y_pred, y_true)
y_pred |
Estimated target values vector |
y_true |
Ground truth (correct) target values vector |
Root Mean Squared Percentage Error Loss
data(cars) reg <- lm(log(dist) ~ log(speed), data = cars) RMSPE(y_pred = exp(reg$fitted.values), y_true = cars$dist)
data(cars) reg <- lm(log(dist) ~ log(speed), data = cars) RMSPE(y_pred = exp(reg$fitted.values), y_true = cars$dist)
Compute the root relative squared error regression loss.
RRSE(y_pred, y_true)
RRSE(y_pred, y_true)
y_pred |
Estimated target values vector |
y_true |
Ground truth (correct) target values vector |
Root Relative Squared Error Loss
data(cars) reg <- lm(log(dist) ~ log(speed), data = cars) RRSE(y_pred = exp(reg$fitted.values), y_true = cars$dist)
data(cars) reg <- lm(log(dist) ~ log(speed), data = cars) RRSE(y_pred = exp(reg$fitted.values), y_true = cars$dist)
Compute the sensitivity score.
Sensitivity(y_true, y_pred, positive = NULL)
Sensitivity(y_true, y_pred, positive = NULL)
y_true |
Ground truth (correct) 0-1 labels vector |
y_pred |
Predicted labels vector, as returned by a classifier |
positive |
An optional character string for the factor level that corresponds to a "positive" result |
Sensitivity
data(cars) logreg <- glm(formula = vs ~ hp + wt, family = binomial(link = "logit"), data = mtcars) pred <- ifelse(logreg$fitted.values < 0.5, 0, 1) Sensitivity(y_pred = pred, y_true = mtcars$vs, positive = "0") Sensitivity(y_pred = pred, y_true = mtcars$vs, positive = "1")
data(cars) logreg <- glm(formula = vs ~ hp + wt, family = binomial(link = "logit"), data = mtcars) pred <- ifelse(logreg$fitted.values < 0.5, 0, 1) Sensitivity(y_pred = pred, y_true = mtcars$vs, positive = "0") Sensitivity(y_pred = pred, y_true = mtcars$vs, positive = "1")
Compute the specificity score.
Specificity(y_true, y_pred, positive = NULL)
Specificity(y_true, y_pred, positive = NULL)
y_true |
Ground truth (correct) 0-1 labels vector |
y_pred |
Predicted labels vector, as returned by a classifier |
positive |
An optional character string for the factor level that corresponds to a "positive" result |
Specificity
data(cars) logreg <- glm(formula = vs ~ hp + wt, family = binomial(link = "logit"), data = mtcars) pred <- ifelse(logreg$fitted.values < 0.5, 0, 1) Specificity(y_pred = pred, y_true = mtcars$vs, positive = "0") Specificity(y_pred = pred, y_true = mtcars$vs, positive = "1")
data(cars) logreg <- glm(formula = vs ~ hp + wt, family = binomial(link = "logit"), data = mtcars) pred <- ifelse(logreg$fitted.values < 0.5, 0, 1) Specificity(y_pred = pred, y_true = mtcars$vs, positive = "0") Specificity(y_pred = pred, y_true = mtcars$vs, positive = "1")
Compute the normalized zero-one classification loss.
ZeroOneLoss(y_pred, y_true)
ZeroOneLoss(y_pred, y_true)
y_pred |
Predicted labels vector, as returned by a classifier |
y_true |
Ground truth (correct) 0-1 labels vector |
Zero-One Loss
data(cars) logreg <- glm(formula = vs ~ hp + wt, family = binomial(link = "logit"), data = mtcars) pred <- ifelse(logreg$fitted.values < 0.5, 0, 1) ZeroOneLoss(y_pred = pred, y_true = mtcars$vs)
data(cars) logreg <- glm(formula = vs ~ hp + wt, family = binomial(link = "logit"), data = mtcars) pred <- ifelse(logreg$fitted.values < 0.5, 0, 1) ZeroOneLoss(y_pred = pred, y_true = mtcars$vs)