Title: | Evaluation Metrics for Machine Learning |
---|---|
Description: | An implementation of evaluation metrics in R that are commonly used in supervised machine learning. It implements metrics for regression, time series, binary classification, classification, and information retrieval problems. It has zero dependencies and a consistent, simple interface for all functions. |
Authors: | Ben Hamner [aut, cph], Michael Frasco [aut, cre], Erin LeDell [ctb] |
Maintainer: | Michael Frasco <[email protected]> |
License: | BSD_3_clause + file LICENSE |
Version: | 0.1.4 |
Built: | 2024-11-09 03:36:31 UTC |
Source: | https://github.com/mfrasco/metrics |
accuracy
is defined as the proportion of elements in actual
that are
equal to the corresponding element in predicted
accuracy(actual, predicted)
accuracy(actual, predicted)
actual |
The ground truth vector, where elements of the vector can be any variable type. |
predicted |
The predicted vector, where elements of the vector represent a
prediction for the corresponding value in |
actual <- c('a', 'a', 'c', 'b', 'c') predicted <- c('a', 'b', 'c', 'b', 'a') accuracy(actual, predicted)
actual <- c('a', 'a', 'c', 'b', 'c') predicted <- c('a', 'b', 'c', 'b', 'a') accuracy(actual, predicted)
ae
computes the elementwise absolute difference between two numeric vectors.
ae(actual, predicted)
ae(actual, predicted)
actual |
The ground truth numeric vector. |
predicted |
The predicted numeric vector, where each element in the vector
is a prediction for the corresponding element in |
actual <- c(1.1, 1.9, 3.0, 4.4, 5.0, 5.6) predicted <- c(0.9, 1.8, 2.5, 4.5, 5.0, 6.2) ae(actual, predicted)
actual <- c(1.1, 1.9, 3.0, 4.4, 5.0, 5.6) predicted <- c(0.9, 1.8, 2.5, 4.5, 5.0, 6.2) ae(actual, predicted)
ape
computes the elementwise absolute percent difference between two numeric
vectors
ape(actual, predicted)
ape(actual, predicted)
actual |
The ground truth numeric vector. |
predicted |
The predicted numeric vector, where each element in the vector
is a prediction for the corresponding element in |
ape
is calculated as (actual
- predicted
) / abs(actual)
.
This means that the function will return -Inf
, Inf
, or NaN
if actual
is zero.
mape
smape
actual <- c(1.1, 1.9, 3.0, 4.4, 5.0, 5.6) predicted <- c(0.9, 1.8, 2.5, 4.5, 5.0, 6.2) ape(actual, predicted)
actual <- c(1.1, 1.9, 3.0, 4.4, 5.0, 5.6) predicted <- c(0.9, 1.8, 2.5, 4.5, 5.0, 6.2) ape(actual, predicted)
apk
computes the average precision at k, in the context of information
retrieval problems.
apk(k, actual, predicted)
apk(k, actual, predicted)
k |
The number of elements of |
actual |
The ground truth vector of relevant documents. The vector can contain
any numeric or character values, order does not matter, and the
vector does not need to be the same length as |
predicted |
The predicted vector of retrieved documents. The vector can
contain any numeric of character values. However, unlike |
apk
loops over the first k values of predicted
. For each value, if
the value is contained within actual
and has not been predicted before,
we increment the number of sucesses by one and increment our score by the number
of successes divided by k. Then, we return our final score divided by the number
of relevant documents (i.e. the length of actual
).
apk
will return NaN
if length(actual)
equals 0
.
actual <- c('a', 'b', 'd') predicted <- c('b', 'c', 'a', 'e', 'f') apk(3, actual, predicted)
actual <- c('a', 'b', 'd') predicted <- c('b', 'c', 'a', 'e', 'f') apk(3, actual, predicted)
auc
computes the area under the receiver-operator characteristic curve (AUC).
auc(actual, predicted)
auc(actual, predicted)
actual |
The ground truth binary numeric vector containing 1 for the positive class and 0 for the negative class. |
predicted |
A numeric vector of predicted values, where the smallest values correspond
to the observations most believed to be in the negative class
and the largest values indicate the observations most believed
to be in the positive class. Each element represents the
prediction for the corresponding element in |
auc
uses the fact that the area under the ROC curve is equal to the probability
that a randomly chosen positive observation has a higher predicted value than a
randomly chosen negative value. In order to compute this probability, we can
calculate the Mann-Whitney U statistic. This method is very fast, since we
do not need to compute the ROC curve first.
actual <- c(1, 1, 1, 0, 0, 0) predicted <- c(0.9, 0.8, 0.4, 0.5, 0.3, 0.2) auc(actual, predicted)
actual <- c(1, 1, 1, 0, 0, 0) predicted <- c(0.9, 0.8, 0.4, 0.5, 0.3, 0.2) auc(actual, predicted)
bias
computes the average amount by which actual
is greater than
predicted
.
bias(actual, predicted)
bias(actual, predicted)
actual |
The ground truth numeric vector. |
predicted |
The predicted numeric vector, where each element in the vector
is a prediction for the corresponding element in |
If a model is unbiased bias(actual, predicted)
should be close to zero.
Bias is calculated by taking the average of (actual
- predicted
).
actual <- c(1.1, 1.9, 3.0, 4.4, 5.0, 5.6) predicted <- c(0.9, 1.8, 2.5, 4.5, 5.0, 6.2) bias(actual, predicted)
actual <- c(1.1, 1.9, 3.0, 4.4, 5.0, 5.6) predicted <- c(0.9, 1.8, 2.5, 4.5, 5.0, 6.2) bias(actual, predicted)
ce
is defined as the proportion of elements in actual
that are not equal
to the corresponding element in predicted
.
ce(actual, predicted)
ce(actual, predicted)
actual |
The ground truth vector, where elements of the vector can be any variable type. |
predicted |
The predicted vector, where elements of the vector represent a
prediction for the corresponding value in |
actual <- c('a', 'a', 'c', 'b', 'c') predicted <- c('a', 'b', 'c', 'b', 'a') ce(actual, predicted)
actual <- c('a', 'a', 'c', 'b', 'c') predicted <- c('a', 'b', 'c', 'b', 'a') ce(actual, predicted)
explained_variation
computes the percentage of variation in one numeric vector
explained by another, also known as the coefficient of determination.
explained_variation(actual, predicted)
explained_variation(actual, predicted)
actual |
The ground truth numeric vector. |
predicted |
The predicted numeric vector, where each element in the vector
is a prediction for the corresponding element in |
explained_variation
subtracts the relative squared error, rse(actual, predicted)
,
from 1, meaning it can return negative values if the predictions are on average further from
the actual values than predictions from a naive model that predicts the mean for every data
point.
actual <- c(1.1, 1.9, 3.0, 4.4, 5.0, 5.6) predicted <- c(0.9, 1.8, 2.5, 4.5, 5.0, 6.2) explained_variation(actual, predicted)
actual <- c(1.1, 1.9, 3.0, 4.4, 5.0, 5.6) predicted <- c(0.9, 1.8, 2.5, 4.5, 5.0, 6.2) explained_variation(actual, predicted)
f1
computes the F1 Score in the context of information retrieval problems.
f1(actual, predicted)
f1(actual, predicted)
actual |
The ground truth vector of relevant documents. The vector can contain
any numeric or character values, order does not matter, and the
vector does not need to be the same length as |
predicted |
The predicted vector of retrieved documents. The vector can contain
any numeric or character values, order does not matter, and the
vector does not need to be the same length as |
f1
is defined as . In the
context of information retrieval problems, precision is the proportion of retrieved
documents that are relevant to a query and recall is the proportion of relevant
documents that are successfully retrieved by a query. If there are zero relevant
documents that are retrieved, zero relevant documents, or zero predicted documents,
f1
is defined as 0
.
actual <- c('a', 'c', 'd') predicted <- c('d', 'e') f1(actual, predicted)
actual <- c('a', 'c', 'd') predicted <- c('d', 'e') f1(actual, predicted)
fbeta_score
computes a weighted harmonic mean of Precision and Recall.
The beta
parameter controls the weighting.
fbeta_score(actual, predicted, beta = 1)
fbeta_score(actual, predicted, beta = 1)
actual |
The ground truth binary numeric vector containing 1 for the positive class and 0 for the negative class. |
predicted |
The predicted binary numeric vector containing 1 for the positive
class and 0 for the negative class. Each element represents the
prediction for the corresponding element in |
beta |
A non-negative real number controlling how close the F-beta score is to
either Precision or Recall. When |
actual <- c(1, 1, 1, 0, 0, 0) predicted <- c(1, 0, 1, 1, 1, 1) recall(actual, predicted)
actual <- c(1, 1, 1, 0, 0, 0) predicted <- c(1, 0, 1, 1, 1, 1) recall(actual, predicted)
ll
computes the elementwise log loss between two numeric vectors.
ll(actual, predicted)
ll(actual, predicted)
actual |
The ground truth binary numeric vector containing 1 for the positive class and 0 for the negative class. |
predicted |
A numeric vector of predicted values, where the values correspond
to the probabilities that each observation in |
actual <- c(1, 1, 1, 0, 0, 0) predicted <- c(0.9, 0.8, 0.4, 0.5, 0.3, 0.2) ll(actual, predicted)
actual <- c(1, 1, 1, 0, 0, 0) predicted <- c(0.9, 0.8, 0.4, 0.5, 0.3, 0.2) ll(actual, predicted)
logLoss
computes the average log loss between two numeric vectors.
logLoss(actual, predicted)
logLoss(actual, predicted)
actual |
The ground truth binary numeric vector containing 1 for the positive class and 0 for the negative class. |
predicted |
A numeric vector of predicted values, where the values correspond
to the probabilities that each observation in |
actual <- c(1, 1, 1, 0, 0, 0) predicted <- c(0.9, 0.8, 0.4, 0.5, 0.3, 0.2) logLoss(actual, predicted)
actual <- c(1, 1, 1, 0, 0, 0) predicted <- c(0.9, 0.8, 0.4, 0.5, 0.3, 0.2) logLoss(actual, predicted)
mae
computes the average absolute difference between two numeric vectors.
mae(actual, predicted)
mae(actual, predicted)
actual |
The ground truth numeric vector. |
predicted |
The predicted numeric vector, where each element in the vector
is a prediction for the corresponding element in |
actual <- c(1.1, 1.9, 3.0, 4.4, 5.0, 5.6) predicted <- c(0.9, 1.8, 2.5, 4.5, 5.0, 6.2) mae(actual, predicted)
actual <- c(1.1, 1.9, 3.0, 4.4, 5.0, 5.6) predicted <- c(0.9, 1.8, 2.5, 4.5, 5.0, 6.2) mae(actual, predicted)
mape
computes the average absolute percent difference between two numeric vectors.
mape(actual, predicted)
mape(actual, predicted)
actual |
The ground truth numeric vector. |
predicted |
The predicted numeric vector, where each element in the vector
is a prediction for the corresponding element in |
mape
is calculated as the average of (actual
- predicted
) / abs(actual)
.
This means that the function will return -Inf
, Inf
, or NaN
if actual
is zero. Due to the instability at or near zero, smape
or
mase
are often used as alternatives.
actual <- c(1.1, 1.9, 3.0, 4.4, 5.0, 5.6) predicted <- c(0.9, 1.8, 2.5, 4.5, 5.0, 6.2) mape(actual, predicted)
actual <- c(1.1, 1.9, 3.0, 4.4, 5.0, 5.6) predicted <- c(0.9, 1.8, 2.5, 4.5, 5.0, 6.2) mape(actual, predicted)
mapk
computes the mean average precision at k for a set of predictions, in
the context of information retrieval problems.
mapk(k, actual, predicted)
mapk(k, actual, predicted)
k |
The number of elements of |
actual |
A list of vectors, where each vector represents a ground truth vector of relevant documents. In each vector, the elements can be numeric or character values, and the order of the elements does not matter. |
predicted |
A list of vectors, where each vector represents the predicted vector
of retrieved documents for the corresponding element of |
mapk
evaluates apk
for each pair of elements from actual
and
predicted
.
actual <- list(c('a', 'b'), c('a'), c('x', 'y', 'b')) predicted <- list(c('a', 'c', 'd'), c('x', 'b', 'a', 'b'), c('y')) mapk(2, actual, predicted) actual <- list(c(1, 5, 7, 9), c(2, 3), c(2, 5, 6)) predicted <- list(c(5, 6, 7, 8, 9), c(1, 2, 3), c(2, 4, 6, 8)) mapk(3, actual, predicted)
actual <- list(c('a', 'b'), c('a'), c('x', 'y', 'b')) predicted <- list(c('a', 'c', 'd'), c('x', 'b', 'a', 'b'), c('y')) mapk(2, actual, predicted) actual <- list(c(1, 5, 7, 9), c(2, 3), c(2, 5, 6)) predicted <- list(c(5, 6, 7, 8, 9), c(1, 2, 3), c(2, 4, 6, 8)) mapk(3, actual, predicted)
mase
computes the mean absolute scaled error between two numeric
vectors. This function is only intended for time series data, where
actual
and numeric
are numeric vectors ordered by time.
mase(actual, predicted, step_size = 1)
mase(actual, predicted, step_size = 1)
actual |
The ground truth numeric vector ordered in time, with most recent observation at the end of the vector. |
predicted |
The predicted numeric vector ordered in time, where each element
of the vector represents a prediction for the corresponding
element of |
step_size |
A positive integer that specifies how many observations to look back
in time in order to compute the naive forecast. The default is
However, if |
actual <- c(1.1, 1.9, 3.0, 4.4, 5.0, 5.6) predicted <- c(0.9, 1.8, 2.5, 4.5, 5.0, 6.2) step_size <- 1 mase(actual, predicted, step_size)
actual <- c(1.1, 1.9, 3.0, 4.4, 5.0, 5.6) predicted <- c(0.9, 1.8, 2.5, 4.5, 5.0, 6.2) step_size <- 1 mase(actual, predicted, step_size)
mdae
computes the median absolute difference between two numeric vectors.
mdae(actual, predicted)
mdae(actual, predicted)
actual |
The ground truth numeric vector. |
predicted |
The predicted numeric vector, where each element in the vector
is a prediction for the corresponding element in |
actual <- c(1.1, 1.9, 3.0, 4.4, 5.0, 5.6) predicted <- c(0.9, 1.8, 2.5, 4.5, 5.0, 6.2) mdae(actual, predicted)
actual <- c(1.1, 1.9, 3.0, 4.4, 5.0, 5.6) predicted <- c(0.9, 1.8, 2.5, 4.5, 5.0, 6.2) mdae(actual, predicted)
MeanQuadraticWeightedKappa
computes the mean quadratic weighted kappa,
which can optionally be weighted
MeanQuadraticWeightedKappa(kappas, weights = rep(1, length(kappas)))
MeanQuadraticWeightedKappa(kappas, weights = rep(1, length(kappas)))
kappas |
A numeric vector of possible kappas. |
weights |
An optional numeric vector of ratings. |
kappas <- c(0.3 ,0.2, 0.2, 0.5, 0.1, 0.2) weights <- c(1.0, 2.5, 1.0, 1.0, 2.0, 3.0) MeanQuadraticWeightedKappa(kappas, weights)
kappas <- c(0.3 ,0.2, 0.2, 0.5, 0.1, 0.2) weights <- c(1.0, 2.5, 1.0, 1.0, 2.0, 3.0) MeanQuadraticWeightedKappa(kappas, weights)
mse
computes the average squared difference between two numeric vectors.
mse(actual, predicted)
mse(actual, predicted)
actual |
The ground truth numeric vector. |
predicted |
The predicted numeric vector, where each element in the vector
is a prediction for the corresponding element in |
actual <- c(1.1, 1.9, 3.0, 4.4, 5.0, 5.6) predicted <- c(0.9, 1.8, 2.5, 4.5, 5.0, 6.2) mse(actual, predicted)
actual <- c(1.1, 1.9, 3.0, 4.4, 5.0, 5.6) predicted <- c(0.9, 1.8, 2.5, 4.5, 5.0, 6.2) mse(actual, predicted)
msle
computes the average of squared log error between two numeric vectors.
msle(actual, predicted)
msle(actual, predicted)
actual |
The ground truth non-negative vector |
predicted |
The predicted non-negative vector, where each element in the vector
is a prediction for the corresponding element in |
msle
adds one to both actual
and predicted
before taking
the natural logarithm to avoid taking the natural log of zero. As a result,
the function can be used if actual
or predicted
have zero-valued
elements. But this function is not appropriate if either are negative valued.
actual <- c(1.1, 1.9, 3.0, 4.4, 5.0, 5.6) predicted <- c(0.9, 1.8, 2.5, 4.5, 5.0, 6.2) msle(actual, predicted)
actual <- c(1.1, 1.9, 3.0, 4.4, 5.0, 5.6) predicted <- c(0.9, 1.8, 2.5, 4.5, 5.0, 6.2) msle(actual, predicted)
This object provides the documentation for the parameters of functions that provide binary classification metrics
actual |
The ground truth binary numeric vector containing 1 for the positive class and 0 for the negative class. |
predicted |
The predicted binary numeric vector containing 1 for the positive
class and 0 for the negative class. Each element represents the
prediction for the corresponding element in |
This object provides the documentation for the parameters of functions that provide classification metrics
actual |
The ground truth vector, where elements of the vector can be any variable type. |
predicted |
The predicted vector, where elements of the vector represent a
prediction for the corresponding value in |
This object provides the documentation for the parameters of functions that provide regression metrics
actual |
The ground truth numeric vector. |
predicted |
The predicted numeric vector, where each element in the vector
is a prediction for the corresponding element in |
percent_bias
computes the average amount that actual
is greater
than predicted
as a percentage of the absolute value of actual
.
percent_bias(actual, predicted)
percent_bias(actual, predicted)
actual |
The ground truth numeric vector. |
predicted |
The predicted numeric vector, where each element in the vector
is a prediction for the corresponding element in |
If a model is unbiased percent_bias(actual, predicted)
should be close
to zero. Percent Bias is calculated by taking the average of
(actual
- predicted
) / abs(actual)
across all observations.
percent_bias
will give -Inf
, Inf
, or NaN
, if any
elements of actual
are 0
.
actual <- c(1.1, 1.9, 3.0, 4.4, 5.0, 5.6) predicted <- c(0.9, 1.8, 2.5, 4.5, 5.0, 6.2) percent_bias(actual, predicted)
actual <- c(1.1, 1.9, 3.0, 4.4, 5.0, 5.6) predicted <- c(0.9, 1.8, 2.5, 4.5, 5.0, 6.2) percent_bias(actual, predicted)
precision
computes proportion of observations predicted to be in the
positive class (i.e. the element in predicted
equals 1)
that actually belong to the positive class (i.e. the element
in actual
equals 1)
precision(actual, predicted)
precision(actual, predicted)
actual |
The ground truth binary numeric vector containing 1 for the positive class and 0 for the negative class. |
predicted |
The predicted binary numeric vector containing 1 for the positive
class and 0 for the negative class. Each element represents the
prediction for the corresponding element in |
actual <- c(1, 1, 1, 0, 0, 0) predicted <- c(1, 1, 1, 1, 1, 1) precision(actual, predicted)
actual <- c(1, 1, 1, 0, 0, 0) predicted <- c(1, 1, 1, 1, 1, 1) precision(actual, predicted)
rae
computes the relative absolute error between two numeric vectors.
rae(actual, predicted)
rae(actual, predicted)
actual |
The ground truth numeric vector. |
predicted |
The predicted numeric vector, where each element in the vector
is a prediction for the corresponding element in |
rae
divides sum(ae(actual, predicted))
by sum(ae(actual, mean(actual)))
,
meaning that it provides the absolute error of the predictions relative to a naive model that
predicted the mean for every data point.
actual <- c(1.1, 1.9, 3.0, 4.4, 5.0, 5.6) predicted <- c(0.9, 1.8, 2.5, 4.5, 5.0, 6.2) rrse(actual, predicted)
actual <- c(1.1, 1.9, 3.0, 4.4, 5.0, 5.6) predicted <- c(0.9, 1.8, 2.5, 4.5, 5.0, 6.2) rrse(actual, predicted)
recall
computes proportion of observations in the positive class
(i.e. the element in actual
equals 1) that are predicted
to be in the positive class (i.e. the element in predicted
equals 1)
recall(actual, predicted)
recall(actual, predicted)
actual |
The ground truth binary numeric vector containing 1 for the positive class and 0 for the negative class. |
predicted |
The predicted binary numeric vector containing 1 for the positive
class and 0 for the negative class. Each element represents the
prediction for the corresponding element in |
actual <- c(1, 1, 1, 0, 0, 0) predicted <- c(1, 0, 1, 1, 1, 1) recall(actual, predicted)
actual <- c(1, 1, 1, 0, 0, 0) predicted <- c(1, 0, 1, 1, 1, 1) recall(actual, predicted)
rmse
computes the root mean squared error between two numeric vectors
rmse(actual, predicted)
rmse(actual, predicted)
actual |
The ground truth numeric vector. |
predicted |
The predicted numeric vector, where each element in the vector
is a prediction for the corresponding element in |
actual <- c(1.1, 1.9, 3.0, 4.4, 5.0, 5.6) predicted <- c(0.9, 1.8, 2.5, 4.5, 5.0, 6.2) rmse(actual, predicted)
actual <- c(1.1, 1.9, 3.0, 4.4, 5.0, 5.6) predicted <- c(0.9, 1.8, 2.5, 4.5, 5.0, 6.2) rmse(actual, predicted)
rmsle
computes the root mean squared log error between two numeric vectors.
rmsle(actual, predicted)
rmsle(actual, predicted)
actual |
The ground truth non-negative vector |
predicted |
The predicted non-negative vector, where each element in the vector
is a prediction for the corresponding element in |
rmsle
adds one to both actual
and predicted
before taking
the natural logarithm to avoid taking the natural log of zero. As a result,
the function can be used if actual
or predicted
have zero-valued
elements. But this function is not appropriate if either are negative valued.
actual <- c(1.1, 1.9, 3.0, 4.4, 5.0, 5.6) predicted <- c(0.9, 1.8, 2.5, 4.5, 5.0, 6.2) rmsle(actual, predicted)
actual <- c(1.1, 1.9, 3.0, 4.4, 5.0, 5.6) predicted <- c(0.9, 1.8, 2.5, 4.5, 5.0, 6.2) rmsle(actual, predicted)
rrse
computes the root relative squared error between two numeric vectors.
rrse(actual, predicted)
rrse(actual, predicted)
actual |
The ground truth numeric vector. |
predicted |
The predicted numeric vector, where each element in the vector
is a prediction for the corresponding element in |
rrse
takes the square root of sse(actual, predicted)
divided by
sse(actual, mean(actual))
, meaning that it provides the squared error of the
predictions relative to a naive model that predicted the mean for every data point.
actual <- c(1.1, 1.9, 3.0, 4.4, 5.0, 5.6) predicted <- c(0.9, 1.8, 2.5, 4.5, 5.0, 6.2) rrse(actual, predicted)
actual <- c(1.1, 1.9, 3.0, 4.4, 5.0, 5.6) predicted <- c(0.9, 1.8, 2.5, 4.5, 5.0, 6.2) rrse(actual, predicted)
rse
computes the relative squared error between two numeric vectors.
rse(actual, predicted)
rse(actual, predicted)
actual |
The ground truth numeric vector. |
predicted |
The predicted numeric vector, where each element in the vector
is a prediction for the corresponding element in |
rse
divides sse(actual, predicted)
by sse(actual, mean(actual))
,
meaning that it provides the squared error of the predictions relative to a naive model that
predicted the mean for every data point.
actual <- c(1.1, 1.9, 3.0, 4.4, 5.0, 5.6) predicted <- c(0.9, 1.8, 2.5, 4.5, 5.0, 6.2) rse(actual, predicted)
actual <- c(1.1, 1.9, 3.0, 4.4, 5.0, 5.6) predicted <- c(0.9, 1.8, 2.5, 4.5, 5.0, 6.2) rse(actual, predicted)
ScoreQuadraticWeightedKappa
computes the quadratic weighted kappa between
two vectors of integers
ScoreQuadraticWeightedKappa(rater.a, rater.b, min.rating = min(c(rater.a, rater.b)), max.rating = max(c(rater.a, rater.b)))
ScoreQuadraticWeightedKappa(rater.a, rater.b, min.rating = min(c(rater.a, rater.b)), max.rating = max(c(rater.a, rater.b)))
rater.a |
An integer vector of the first rater's ratings. |
rater.b |
An integer vector of the second rater's ratings. |
min.rating |
The minimum possible rating. |
max.rating |
The maximum possible rating. |
rater.a <- c(1, 4, 5, 5, 2, 1) rater.b <- c(2, 2, 4, 5, 3, 3) ScoreQuadraticWeightedKappa(rater.a, rater.b, 1, 5)
rater.a <- c(1, 4, 5, 5, 2, 1) rater.b <- c(2, 2, 4, 5, 3, 3) ScoreQuadraticWeightedKappa(rater.a, rater.b, 1, 5)
se
computes the elementwise squared difference between two numeric vectors.
se(actual, predicted)
se(actual, predicted)
actual |
The ground truth numeric vector. |
predicted |
The predicted numeric vector, where each element in the vector
is a prediction for the corresponding element in |
actual <- c(1.1, 1.9, 3.0, 4.4, 5.0, 5.6) predicted <- c(0.9, 1.8, 2.5, 4.5, 5.0, 6.2) se(actual, predicted)
actual <- c(1.1, 1.9, 3.0, 4.4, 5.0, 5.6) predicted <- c(0.9, 1.8, 2.5, 4.5, 5.0, 6.2) se(actual, predicted)
sle
computes the elementwise squares of the differences in the logs of two numeric vectors.
sle(actual, predicted)
sle(actual, predicted)
actual |
The ground truth non-negative vector |
predicted |
The predicted non-negative vector, where each element in the vector
is a prediction for the corresponding element in |
sle
adds one to both actual
and predicted
before taking
the natural logarithm of each to avoid taking the natural log of zero. As a result,
the function can be used if actual
or predicted
have zero-valued
elements. But this function is not appropriate if either are negative valued.
actual <- c(1.1, 1.9, 3.0, 4.4, 5.0, 5.6) predicted <- c(0.9, 1.8, 2.5, 4.5, 5.0, 6.2) sle(actual, predicted)
actual <- c(1.1, 1.9, 3.0, 4.4, 5.0, 5.6) predicted <- c(0.9, 1.8, 2.5, 4.5, 5.0, 6.2) sle(actual, predicted)
smape
computes the symmetric mean absolute percentage error between
two numeric vectors.
smape(actual, predicted)
smape(actual, predicted)
actual |
The ground truth numeric vector. |
predicted |
The predicted numeric vector, where each element in the vector
is a prediction for the corresponding element in |
smape
is defined as two times the average of abs(actual - predicted) / (abs(actual) + abs(predicted))
.
Therefore, at the elementwise level, it will provide NaN
only if actual
and predicted
are both zero. It has an upper bound of 2
, when either actual
or
predicted
are zero or when actual
and predicted
are opposite
signs.
smape
is symmetric in the sense that smape(x, y) = smape(y, x)
.
actual <- c(1.1, 1.9, 3.0, 4.4, 5.0, 5.6) predicted <- c(0.9, 1.8, 2.5, 4.5, 5.0, 6.2) smape(actual, predicted)
actual <- c(1.1, 1.9, 3.0, 4.4, 5.0, 5.6) predicted <- c(0.9, 1.8, 2.5, 4.5, 5.0, 6.2) smape(actual, predicted)
sse
computes the sum of the squared differences between two numeric vectors.
sse(actual, predicted)
sse(actual, predicted)
actual |
The ground truth numeric vector. |
predicted |
The predicted numeric vector, where each element in the vector
is a prediction for the corresponding element in |
actual <- c(1.1, 1.9, 3.0, 4.4, 5.0, 5.6) predicted <- c(0.9, 1.8, 2.5, 4.5, 5.0, 6.2) sse(actual, predicted)
actual <- c(1.1, 1.9, 3.0, 4.4, 5.0, 5.6) predicted <- c(0.9, 1.8, 2.5, 4.5, 5.0, 6.2) sse(actual, predicted)