Metrics/0000755000176200001440000000000013320562332011657 5ustar liggesusersMetrics/tests/0000755000176200001440000000000013201251161013012 5ustar liggesusersMetrics/tests/testthat.R0000644000176200001440000000010313201251161014767 0ustar liggesuserslibrary(testthat) library(Metrics) testthat::test_check("Metrics")Metrics/tests/testthat/0000755000176200001440000000000013320562332014661 5ustar liggesusersMetrics/tests/testthat/test-information_retrieval.R0000644000176200001440000000213713201251161022357 0ustar liggesuserscontext('Information Retrieval') test_that('f1 score is calculated correctly', { expect_equal(f1(c(3,4,5),c(3,4)), 0.8) expect_equal(f1(7,1), 0) expect_equal(f1(7,c(1,1)), 0) }) test_that('average precision at k is calculated correctly', { expect_equal(apk(2, 1:5, c(6,4,7,1,2)), 1/4) expect_equal(apk(5, 1:5, c(1,1,1,1,1)), 0.2) expect_equal(apk(20, 1:100, c(1:20,200:600)), 1) expect_equal(apk(3, c(1,3), 1:5), 5/6) expect_equal(apk(3, 1:3, c(1,1,1)), 1/3) expect_equal(apk(3, 1:3, c(1,2,1)), 2/3) }) test_that('mean average precision at k is calculated correctly', { expect_equal(mapk(10, list(1:5,1:3), list(1:10,c(1:2,4:11,3))), 5/6) expect_equal(mapk(3, list(1:4), list(1:4)), 1.0) expect_equal(mapk(3, list(c(1,3,4),c(1,2,4),c(1,3)), list(1:5,1:5,1:5)), 0.685185185185185) expect_equal(mapk(5, list(1:5,1:5), list(c(6,4,7,1,2),c(1,1,1,1,1))), 0.26) expect_equal(mapk(3, list(c(1,3),1:3,1:3), list(1:5,c(1,1,1),c(1,2,1))), 11/18) }) test_that('mean average precision at k throws a warning if passed a vector', { expect_warning(mapk(3, 2:6, 1:5)) }) Metrics/tests/testthat/test-binary_classification.R0000644000176200001440000000277513307037336022341 0ustar liggesuserscontext('binary classification') test_that('area under ROC curve is calculated correctly', { expect_equal(auc(c(1,0,1,1), c(.32,.52,.26,.86)), 1/3) expect_equal(auc(c(1,0,1,0,1),c(.9,.1,.8,.1,.7)), 1) expect_equal(auc(c(0,1,1,0),c(.2,.1,.3,.4)), 1/4) expect_equal(auc(c(1,1,1,1,0,0,0,0,0,0),0*(1:10)), 0.5) expect_warning(auc(c(0, 1, 0), rnorm(2)), regexp = 'longer object') }) test_that('log loss is calculated correctly', { expect_equal(ll(1,1), 0) expect_equal(ll(1,0), Inf) expect_equal(ll(0,1), Inf) expect_equal(ll(1,0.5), -log(0.5)) }) test_that('mean los loss is calculated correctly', { expect_equal(logLoss(c(1,1,0,0),c(1,1,0,0)), 0) expect_equal(logLoss(c(1,1,0,0),c(1,1,1,0)), Inf) expect_equal(logLoss(c(1,1,1,0,0,0),c(.5,.1,.01,.9,.75,.001)), 1.881797068998267) }) test_that('precision is calculated correctly', { expect_equal(precision(c(1,1,0,0),c(1,1,0,0)), 1) expect_equal(precision(c(0,0,1,1),c(1,1,0,0)), 0) expect_equal(precision(c(1,1,0,0),c(1,1,1,1)), 1/2) }) test_that('recall is calculated correctly', { expect_equal(recall(c(1,1,0,0),c(1,1,0,0)), 1) expect_equal(recall(c(0,0,1,1),c(1,1,0,0)), 0) expect_equal(recall(c(1,1,1,1),c(1,0,0,1)), 1/2) }) test_that('f-beta score is calculated correctly',{ expect_equal(fbeta_score(c(1,1,0,0),c(1,1,0,0)), 1) expect_equal(fbeta_score(c(0,0,1,1),c(1,1,1,0)), 2/5) expect_equal(fbeta_score(c(1,1,1,1),c(1,0,0,1)), 2/3) expect_equal(fbeta_score(c(1,1,0,0),c(1,1,1,1),beta=0), 1/2) }) Metrics/tests/testthat/test-regression.R0000644000176200001440000000607313261056363020155 0ustar liggesuserscontext('Regression metrics.') test_that('bias is calculated correctly', { expect_equal(bias(1, 1), 0) expect_equal(bias(c(-1, -100, 17.5), c(0, 0, 0)), mean(c(-1, -100, 17.5))) }) test_that('percent_bias is calculated correctly', { expect_equal(percent_bias(c(1, 2, 3), c(1, 3, 2)), mean(c(0, -1/2, 1/3))) expect_equal(percent_bias(c(1, 2, 0), c(1, 2, 1)), -Inf) expect_equal(percent_bias(0, 0), NaN) expect_equal(percent_bias(c(-1.1, 1.1), c(-1, 1)), 0) }) test_that('squared error is calculated correctly', { expect_equal(se(3.4, 4.4), 1) expect_equal(se(9:11, 11:9), c(4, 0, 4)) }) test_that('sum of squared errors is calculated correctly', { expect_equal(sse(c(1, 3, 2), c(2, 3, 4)), 5) }) test_that('mean squared error is calculated correctly', { expect_equal(mse(1:4, c(2, 3, 4, 4)), 3 / 4) }) test_that('root mean squared error is calculated correctly', { expect_equal(rmse(1:4, c(1, 2, 3, 5)), sqrt(1 / 4)) expect_equal(rmse(1:4, 1:4), 0) }) test_that('absolute error is calculated correctly', { expect_equal(ae(3.4, 4.4), 1) expect_equal(ae(9:11, 11:9), c(2, 0, 2)) }) test_that('mean absolute error is calculated correctly', { expect_equal(mae(1:4, c(1, 2, 3, 5)), 0.25) }) test_that('median absolute error is calculated correctly', { expect_equal(mdae(1:4, c(1, 2, 4, 50)), 0.5) }) test_that('absolute percent error is calculated correctly', { expect_equal(ape(0:3, 1:4), c(Inf, 1, 1/2, 1/3)) expect_equal(ape(0:2, c(0, 0, 0)), c(NaN, 1, 1)) expect_equal(ape(c(-1.1, 1.1), c(-1, 1)), c(1 / 11, 1 / 11)) }) test_that('mean absolute percent error is calculated correctly', { expect_equal(mape(1:3, 2:4), mean(c(1, 1/2, 1/3))) expect_equal(mape(c(-1.1, 1.1), c(-1, 1)), 1 / 11) }) test_that('symmetric mean absolute percent error is calculated correctly', { expect_equal(smape(0, 0), NaN) expect_equal(smape(1, -1), 2) expect_equal(smape(1, 0), 2) expect_equal(smape(c(1, 2, 3), c(2, 5, 4)), smape(c(2, 5, 4), c(1, 2, 3))) }) test_that('squared log error is calculated correctly', { expect_equal(sle(c(0, 1, 3.4), c(1, 0, 3.4)), c(log(2), log(2), 0) ^ 2) expect_equal(sle(exp(2) - 1,exp(1) - 1), 1) }) test_that('mean squared log error is calculated correctly', { expect_equal(msle(c(1, 2, exp(1) - 1),c(1, 2, exp(2)-1)), 1 / 3) }) test_that('root mean squared log error is calculated correctly', { expect_equal(rmsle(c(exp(5) - 1), c(exp(1) - 1)), 4) }) test_that('relative absolute error is calculated correctly', { expect_equal(rae(0:10, 30:40), 11) expect_equal(rae(seq(0,2,0.5), seq(0,2,0.5)), 0.0) expect_equal(rae(1:4, c(1,2,3,5)), 0.25) }) test_that('root relative squared error is calculated correctly', { expect_equal(rrse(0:10, 2:12), sqrt(0.4)) expect_equal(rrse(seq(0,2,0.5), seq(0,2,0.5)), 0.0) expect_equal(rrse(1:4, c(1,2,3,5)), sqrt(0.2)) }) test_that('relative squared error is calculated correctly', { expect_equal(rse(0:10, 2:12), 0.4) expect_equal(rse(seq(0,2,0.5), seq(0,2,0.5)), 0.0) expect_equal(rse(1:4, c(1,2,3,5)), 0.2) }) Metrics/tests/testthat/test-classification.R0000644000176200001440000000311013201251161020740 0ustar liggesuserscontext('Classification metrics') test_that('classification error is calculated correctly', { expect_equal(ce(c(1,1,1,0,0,0),c(1,1,1,0,0,0)), 0.0) expect_equal(ce(c(1,1,1,0,0,0),c(1,1,1,1,0,0)), 1/6) expect_equal(ce(c(1,2,3,4),c(1,2,3,3)), 1/4) expect_equal(ce(c("cat","dog","bird"),c("cat","dog","fish")), 1/3) expect_equal(ce(c("cat","dog","bird"),c("caat","doog","biird")), 1.0) }) test_that('quadratic weighted kappa is calculated correctly', { rater.a <- c(1, 2, 1) rater.b <- c(1, 2, 2) kappa <- ScoreQuadraticWeightedKappa(rater.a, rater.b) expect_equal(kappa, 0.4) rater.a <- c(1, 2, 3, 1, 2, 3) rater.b <- c(1, 2, 3, 1, 3, 2) kappa <- ScoreQuadraticWeightedKappa(rater.a, rater.b) expect_equal(kappa, 0.75) rater.a <- c(1, 2, 3) rater.b <- c(1, 2, 3) kappa <- ScoreQuadraticWeightedKappa(rater.a, rater.b) expect_equal(kappa, 1.0) rater.a <- c(1, 3, 5) rater.b <- c(2, 4, 6) kappa <- ScoreQuadraticWeightedKappa(rater.a, rater.b) expect_equal(kappa, 0.8421052631578947) rater.a <- c(1, 3, 3, 5) rater.b <- c(2, 4, 5, 6) kappa <- ScoreQuadraticWeightedKappa(rater.a, rater.b, 1, 6) expect_equal(kappa, 0.6956521739130435) }) test_that('mean quadratic weighted kappa is calculated correctly', { kappa <- MeanQuadraticWeightedKappa( c(1, 1) ) expect_equal(kappa, 0.999) kappa <- MeanQuadraticWeightedKappa( c(1, -1) ) expect_equal(kappa, 0.0) kappa <- MeanQuadraticWeightedKappa( c(.5, .8), c(1.0, .5) ) expect_equal(kappa, 0.624536446425734) })Metrics/tests/testthat/test-time_series.R0000644000176200001440000000055613201251161020270 0ustar liggesuserscontext('Time series metrics.') test_that('mean absolute scaled error is computed correctly', { 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 expect_equal(mase(actual, predicted, step_size), 1.5 / 5.4) step_size <- 2 expect_equal(mase(actual, predicted, step_size), 1.5 / 11.4) })Metrics/NAMESPACE0000644000176200001440000000104013307037336013077 0ustar liggesusers# Generated by roxygen2: do not edit by hand export(MeanQuadraticWeightedKappa) export(ScoreQuadraticWeightedKappa) export(accuracy) export(ae) export(ape) export(apk) export(auc) export(bias) export(ce) export(f1) export(fbeta_score) export(ll) export(logLoss) export(mae) export(mape) export(mapk) export(mase) export(mdae) export(mse) export(msle) export(percent_bias) export(precision) export(rae) export(recall) export(rmse) export(rmsle) export(rrse) export(rse) export(se) export(sle) export(smape) export(sse) importFrom(stats,median) Metrics/R/0000755000176200001440000000000013307037336012066 5ustar liggesusersMetrics/R/binary_classification.R0000644000176200001440000001251013307037336016547 0ustar liggesusers#' @title Inherit Documentation for Binary Classification Metrics #' @name params_binary #' @description This object provides the documentation for the parameters of functions #' that provide binary classification metrics #' @param actual The ground truth binary numeric vector containing 1 for the positive #' class and 0 for the negative class. #' @param 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 \code{actual}. NULL #' Area under the ROC curve (AUC) #' #' \code{auc} computes the area under the receiver-operator characteristic curve (AUC). #' #' \code{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. #' #' @inheritParams params_binary #' @param 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 \code{actual}. #' @export #' @examples #' 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) auc <- function(actual, predicted) { if (length(actual) != length(predicted)) { msg <- "longer object length is not a multiple of shorter object length" warning(msg) } r <- rank(predicted) n_pos <- as.numeric(sum(actual == 1)) n_neg <- length(actual) - n_pos return((sum(r[actual == 1]) - n_pos * (n_pos + 1) / 2) / (n_pos * n_neg)) } #' Log Loss #' #' \code{ll} computes the elementwise log loss between two numeric vectors. #' #' @inheritParams params_binary #' @param predicted A numeric vector of predicted values, where the values correspond #' to the probabilities that each observation in \code{actual} #' belongs to the positive class #' @export #' @seealso \code{\link{logLoss}} #' @examples #' 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) ll <- function(actual, predicted) { score <- -(actual * log(predicted) + (1 - actual) * log(1 - predicted)) score[actual == predicted] <- 0 score[is.nan(score)] <- Inf return(score) } #' Mean Log Loss #' #' \code{logLoss} computes the average log loss between two numeric vectors. #' #' @inheritParams ll #' @export #' @seealso \code{\link{ll}} #' @examples #' 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) logLoss <- function(actual, predicted) { return(mean(ll(actual, predicted))) } #' Precision #' #' \code{precision} computes proportion of observations predicted to be in the #' positive class (i.e. the element in \code{predicted} equals 1) #' that actually belong to the positive class (i.e. the element #' in \code{actual} equals 1) #' #' @inheritParams params_binary #' @export #' @seealso \code{\link{recall}} \code{\link{fbeta_score}} #' @examples #' actual <- c(1, 1, 1, 0, 0, 0) #' predicted <- c(1, 1, 1, 1, 1, 1) #' precision(actual, predicted) precision <- function(actual, predicted) { return(mean(actual[predicted == 1])) } #' Recall #' #' \code{recall} computes proportion of observations in the positive class #' (i.e. the element in \code{actual} equals 1) that are predicted #' to be in the positive class (i.e. the element in \code{predicted} #' equals 1) #' #' @inheritParams params_binary #' @export #' @seealso \code{\link{precision}} \code{\link{fbeta_score}} #' @examples #' actual <- c(1, 1, 1, 0, 0, 0) #' predicted <- c(1, 0, 1, 1, 1, 1) #' recall(actual, predicted) recall <- function(actual, predicted) { return(mean(predicted[actual == 1])) } #' F-beta Score #' #' \code{fbeta_score} computes a weighted harmonic mean of Precision and Recall. #' The \code{beta} parameter controls the weighting. #' #' @inheritParams params_binary #' @param beta A non-negative real number controlling how close the F-beta score is to #' either Precision or Recall. When \code{beta} is at the default of 1, #' the F-beta Score is exactly an equally weighted harmonic mean. #' The F-beta score will weight toward Precision when \code{beta} is less #' than one. The F-beta score will weight toward Recall when \code{beta} is #' greater than one. #' @export #' @seealso \code{\link{precision}} \code{\link{recall}} #' @examples #' actual <- c(1, 1, 1, 0, 0, 0) #' predicted <- c(1, 0, 1, 1, 1, 1) #' recall(actual, predicted) fbeta_score <- function(actual, predicted, beta = 1) { prec <- precision(actual, predicted) rec <- recall(actual, predicted) return((1 + beta^2) * prec * rec / ((beta^2 * prec) + rec)) } Metrics/R/regression.R0000644000176200001440000002704013261056363014374 0ustar liggesusers#' @title Inherit Documentation for Regression Metrics #' @name params_regression #' @description This object provides the documentation for the parameters of functions #' that provide regression metrics #' @param actual The ground truth numeric vector. #' @param predicted The predicted numeric vector, where each element in the vector #' is a prediction for the corresponding element in \code{actual}. NULL #' Bias #' #' \code{bias} computes the average amount by which \code{actual} is greater than #' \code{predicted}. #' #' If a model is unbiased \code{bias(actual, predicted)} should be close to zero. #' Bias is calculated by taking the average of (\code{actual} - \code{predicted}). #' #' @inheritParams params_regression #' @export #' @seealso \code{\link{percent_bias}} #' @examples #' 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) bias <- function(actual, predicted) { return(mean(actual - predicted)) } #' Percent Bias #' #' \code{percent_bias} computes the average amount that \code{actual} is greater #' than \code{predicted} as a percentage of the absolute value of \code{actual}. #' #' If a model is unbiased \code{percent_bias(actual, predicted)} should be close #' to zero. Percent Bias is calculated by taking the average of #' (\code{actual} - \code{predicted}) / \code{abs(actual)} across all observations. #' #' \code{percent_bias} will give \code{-Inf}, \code{Inf}, or \code{NaN}, if any #' elements of \code{actual} are \code{0}. #' #' @inheritParams params_regression #' @export #' @seealso \code{\link{bias}} #' @examples #' 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) percent_bias <- function(actual, predicted) { return(mean((actual - predicted) / abs(actual))) } #' Squared Error #' #' \code{se} computes the elementwise squared difference between two numeric vectors. #' #' @inheritParams params_regression #' @export #' @seealso \code{\link{mse}} \code{\link{rmse}} #' @examples #' 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) se <- function(actual, predicted) { return((actual - predicted) ^ 2) } #' Sum of Squared Errors #' #' \code{sse} computes the sum of the squared differences between two numeric vectors. #' #' @inheritParams params_regression #' @export #' @seealso \code{\link{mse}} #' @examples #' 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) sse <- function(actual, predicted) { return(sum(se(actual, predicted))) } #' Mean Squared Error #' #' \code{mse} computes the average squared difference between two numeric vectors. #' #' @inheritParams params_regression #' @export #' @seealso \code{\link{rmse}} \code{\link{mae}} #' @examples #' 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) mse <- function(actual, predicted) { return(mean(se(actual, predicted))) } #' Root Mean Squared Error #' #' \code{rmse} computes the root mean squared error between two numeric vectors #' #' @inheritParams params_regression #' @export #' @seealso \code{\link{mse}} #' @examples #' 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) rmse <- function(actual, predicted) { return(sqrt(mse(actual, predicted))) } #' Absolute Error #' #' \code{ae} computes the elementwise absolute difference between two numeric vectors. #' #' @inheritParams params_regression #' @export #' @seealso \code{\link{mae}} \code{\link{mdae}} \code{\link{mape}} #' @examples #' 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) ae <- function(actual, predicted) { return(abs(actual - predicted)) } #' Mean Absolute Error #' #' \code{mae} computes the average absolute difference between two numeric vectors. #' #' @inheritParams params_regression #' @export #' @seealso \code{\link{mdae}} \code{\link{mape}} #' @examples #' 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) mae <- function(actual, predicted) { return(mean(ae(actual, predicted))) } #' Median Absolute Error #' #' \code{mdae} computes the median absolute difference between two numeric vectors. #' #' @importFrom stats median #' @inheritParams params_regression #' @export #' @seealso \code{\link{mae}} \code{\link{mape}} #' @examples #' 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) mdae <- function(actual, predicted) { return(stats::median(ae(actual, predicted))) } #' Absolute Percent Error #' #' \code{ape} computes the elementwise absolute percent difference between two numeric #' vectors #' #' \code{ape} is calculated as (\code{actual} - \code{predicted}) / \code{abs(actual)}. #' This means that the function will return \code{-Inf}, \code{Inf}, or \code{NaN} #' if \code{actual} is zero. #' #' @inheritParams params_regression #' @export #' @seealso \code{\link{mape}} \code{smape} #' @examples #' 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) ape <- function(actual, predicted) { return(ae(actual, predicted) / abs(actual)) } #' Mean Absolute Percent Error #' #' \code{mape} computes the average absolute percent difference between two numeric vectors. #' #' \code{mape} is calculated as the average of (\code{actual} - \code{predicted}) / \code{abs(actual)}. #' This means that the function will return \code{-Inf}, \code{Inf}, or \code{NaN} #' if \code{actual} is zero. Due to the instability at or near zero, \code{smape} or #' \code{mase} are often used as alternatives. #' #' @inheritParams params_regression #' @export #' @seealso \code{\link{mae}} \code{\link{smape}} \code{\link{mase}} #' @examples #' 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) mape <- function(actual, predicted) { return(mean(ape(actual, predicted))) } #' Symmetric Mean Absolute Percentage Error #' #' \code{smape} computes the symmetric mean absolute percentage error between #' two numeric vectors. #' #' \code{smape} is defined as two times the average of \code{abs(actual - predicted) / (abs(actual) + abs(predicted))}. #' Therefore, at the elementwise level, it will provide \code{NaN} only if \code{actual} and \code{predicted} #' are both zero. It has an upper bound of \code{2}, when either \code{actual} or #' \code{predicted} are zero or when \code{actual} and \code{predicted} are opposite #' signs. #' #' \code{smape} is symmetric in the sense that \code{smape(x, y) = smape(y, x)}. #' #' @inheritParams params_regression #' @export #' @seealso \code{\link{mape}} \code{\link{mase}} #' @examples #' 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) smape <- function(actual, predicted) { return(2 * mean(ae(actual, predicted) / (abs(actual) + abs(predicted)))) } #' Squared Log Error #' #' \code{sle} computes the elementwise squares of the differences in the logs of two numeric vectors. #' #' \code{sle} adds one to both \code{actual} and \code{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 \code{actual} or \code{predicted} have zero-valued #' elements. But this function is not appropriate if either are negative valued. #' #' @param actual The ground truth non-negative vector #' @param predicted The predicted non-negative vector, where each element in the vector #' is a prediction for the corresponding element in \code{actual}. #' @export #' @seealso \code{\link{msle}} \code{\link{rmsle}} #' @examples #' 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) sle <- function(actual, predicted) { return((log(1 + actual) - log(1 + predicted)) ^ 2) } #' Mean Squared Log Error #' #' \code{msle} computes the average of squared log error between two numeric vectors. #' #' \code{msle} adds one to both \code{actual} and \code{predicted} before taking #' the natural logarithm to avoid taking the natural log of zero. As a result, #' the function can be used if \code{actual} or \code{predicted} have zero-valued #' elements. But this function is not appropriate if either are negative valued. #' #' @inheritParams sle #' @export #' @seealso \code{\link{rmsle}} \code{\link{sle}} #' @examples #' 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) msle <- function(actual, predicted) { mean(sle(actual, predicted)) } #' Root Mean Squared Log Error #' #' \code{rmsle} computes the root mean squared log error between two numeric vectors. #' #' \code{rmsle} adds one to both \code{actual} and \code{predicted} before taking #' the natural logarithm to avoid taking the natural log of zero. As a result, #' the function can be used if \code{actual} or \code{predicted} have zero-valued #' elements. But this function is not appropriate if either are negative valued. #' #' @inheritParams sle #' @export #' @seealso \code{\link{msle}} \code{\link{sle}} #' @examples #' 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) rmsle <- function(actual, predicted) { sqrt(msle(actual, predicted)) } #' Relative Squared Error #' #' \code{rse} computes the relative squared error between two numeric vectors. #' #' \code{rse} divides \code{sse(actual, predicted)} by \code{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. #' #' @inheritParams params_regression #' @export #' @seealso \code{\link{rrse}} \code{\link{rae}} #' @examples #' 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) rse <- function (actual, predicted) { return(sse(actual, predicted) / sse(actual, mean(actual))) } #' Root Relative Squared Error #' #' \code{rrse} computes the root relative squared error between two numeric vectors. #' #' \code{rrse} takes the square root of \code{sse(actual, predicted)} divided by #' \code{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. #' #' @inheritParams params_regression #' @export #' @seealso \code{\link{rse}} \code{\link{rae}} #' @examples #' 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) rrse <- function(actual, predicted) { return(sqrt(rse(actual, predicted))) } #' Relative Absolute Error #' #' \code{rae} computes the relative absolute error between two numeric vectors. #' #' \code{rae} divides \code{sum(ae(actual, predicted))} by \code{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. #' #' @inheritParams params_regression #' @export #' @seealso \code{\link{rse}} \code{\link{rrse}} #' @examples #' 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) rae <- function(actual, predicted) { return(sum(ae(predicted, actual)) / sum(ae(actual, mean(actual)))) } Metrics/R/classification.R0000644000176200001440000001002113201251161015161 0ustar liggesusers#' @title Inherit Documentation for Classification Metrics #' @name params_classification #' @description This object provides the documentation for the parameters of functions #' that provide classification metrics #' @param actual The ground truth vector, where elements of the vector can be any variable type. #' @param predicted The predicted vector, where elements of the vector represent a #' prediction for the corresponding value in \code{actual}. NULL #' Classification Error #' #' \code{ce} is defined as the proportion of elements in \code{actual} that are not equal #' to the corresponding element in \code{predicted}. #' #' @inheritParams params_classification #' @export #' @seealso \code{\link{accuracy}} #' @examples #' actual <- c('a', 'a', 'c', 'b', 'c') #' predicted <- c('a', 'b', 'c', 'b', 'a') #' ce(actual, predicted) ce <- function(actual, predicted) { return(mean(actual != predicted)) } #' Accuracy #' #' \code{accuracy} is defined as the proportion of elements in \code{actual} that are #' equal to the corresponding element in \code{predicted} #' #' @inheritParams params_classification #' @export #' @seealso \code{\link{ce}} #' @examples #' actual <- c('a', 'a', 'c', 'b', 'c') #' predicted <- c('a', 'b', 'c', 'b', 'a') #' accuracy(actual, predicted) accuracy <- function(actual, predicted) { return(1 - ce(actual, predicted)) } #' Quadratic Weighted Kappa #' #' \code{ScoreQuadraticWeightedKappa} computes the quadratic weighted kappa between #' two vectors of integers #' #' @param rater.a An integer vector of the first rater's ratings. #' @param rater.b An integer vector of the second rater's ratings. #' @param min.rating The minimum possible rating. #' @param max.rating The maximum possible rating. #' @export #' @seealso \code{\link{MeanQuadraticWeightedKappa}} #' @examples #' 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) ScoreQuadraticWeightedKappa <- function(rater.a , rater.b , min.rating = min(c(rater.a, rater.b)) , max.rating = max(c(rater.a, rater.b)) ) { rater.a <- factor(rater.a, levels = min.rating:max.rating) rater.b <- factor(rater.b, levels = min.rating:max.rating) #pairwise frequencies confusion.mat <- table(data.frame(rater.a, rater.b)) confusion.mat <- confusion.mat / sum(confusion.mat) #get expected pairwise frequencies under independence histogram.a <- table(rater.a) / length(table(rater.a)) histogram.b <- table(rater.b) / length(table(rater.b)) expected.mat <- histogram.a %*% t(histogram.b) expected.mat <- expected.mat / sum(expected.mat) #get weights labels <- as.numeric( as.vector (names(table(rater.a)))) weights <- outer(labels, labels, FUN = function(x, y) (x - y) ^ 2) #calculate kappa return(1 - sum(weights * confusion.mat) / sum(weights * expected.mat)) } #' Mean Quadratic Weighted Kappa #' #' \code{MeanQuadraticWeightedKappa} computes the mean quadratic weighted kappa, #' which can optionally be weighted #' #' @param kappas A numeric vector of possible kappas. #' @param weights An optional numeric vector of ratings. #' @export #' @seealso \code{\link{ScoreQuadraticWeightedKappa}} #' @examples #' 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) MeanQuadraticWeightedKappa <- function(kappas , weights = rep(1, length(kappas)) ) { weights <- weights / mean(weights) max999 <- function(x) sign(x)*min(0.999,abs(x)) min001 <- function(x) sign(x)*max(0.001,abs(x)) kappas <- sapply(kappas, max999) kappas <- sapply(kappas, min001) r2z <- function(x) 0.5*log((1+x)/(1-x)) z2r <- function(x) (exp(2*x)-1) / (exp(2*x)+1) kappas <- sapply(kappas, r2z) kappas <- kappas * weights kappas <- mean(kappas) return(z2r(kappas)) } Metrics/R/time_series.R0000644000176200001440000000357713201251161014520 0ustar liggesusers#' Mean Absolute Scaled Error #' #' \code{mase} computes the mean absolute scaled error between two numeric #' vectors. This function is only intended for time series data, where #' \code{actual} and \code{numeric} are numeric vectors ordered by time. #' #' @param actual The ground truth numeric vector ordered in time, with most recent #' observation at the end of the vector. #' @param predicted The predicted numeric vector ordered in time, where each element #' of the vector represents a prediction for the corresponding #' element of \code{actual}. #' @param 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 #' \code{1}, which means that the naive forecast for the current time #' period is the actual value of the previous period. #' #' However, if \code{actual} and \code{predictions} were quarterly #' predictions over many years, letting \code{step_size = 4}, would #' mean that the naive forecast for the current time period would #' be the actual value from the same quarter last year. In this way, #' \code{mase} can account for seasonality. #' @export #' @seealso \code{\link{smape}} \code{\link{mape}} #' @examples #' 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) mase <- function(actual, predicted, step_size = 1) { naive_start <- step_size + 1 n <- as.numeric(length(actual)) naive_end <- n - step_size sum_errors <- sum(ae(actual, predicted)) naive_errors <- sum(ae(actual[naive_start:n], actual[1:naive_end])) return(sum_errors / (n * naive_errors / naive_end)) } Metrics/R/information_retrieval.R0000644000176200001440000001176113201251161016604 0ustar liggesusers#' F1 Score #' #' \code{f1} computes the F1 Score in the context of information retrieval problems. #' #' \code{f1} is defined as \eqn{2 * precision * recall / (precision + recall)}. 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, #' \code{f1} is defined as \code{0}. #' #' @export #' @seealso \code{\link{apk}} \code{\link{mapk}} #' @param 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 \code{predicted}. #' @param 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 \code{actual}. #' @examples #' actual <- c('a', 'c', 'd') #' predicted <- c('d', 'e') #' f1(actual, predicted) f1 <- function (actual, predicted) { act <- unique(actual) pred <- unique(predicted) tp <- length(intersect(act, pred)) fp <- length(setdiff(pred, act)) fn <- length(setdiff(act, pred)) if (tp == 0) { return(0) } else { precision <- tp / (tp + fp) recall <- tp / (tp + fn) return(2 * precision * recall / (precision + recall)) } } #' Average Precision at k #' #' \code{apk} computes the average precision at k, in the context of information #' retrieval problems. #' #' \code{apk} loops over the first k values of \code{predicted}. For each value, if #' the value is contained within \code{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 \code{actual}). #' #' \code{apk} will return \code{NaN} if \code{length(actual)} equals \code{0}. #' #' @param k The number of elements of \code{predicted} to consider in the calculation. #' @inheritParams f1 #' @param predicted The predicted vector of retrieved documents. The vector can #' contain any numeric of character values. However, unlike \code{actual}, #' order does matter, with the most documents deemed most likely to #' be relevant at the beginning. #' @export #' @seealso \code{\link{apk}} \code{\link{f1}} #' @examples #' actual <- c('a', 'b', 'd') #' predicted <- c('b', 'c', 'a', 'e', 'f') #' apk(3, actual, predicted) apk <- function(k, actual, predicted) { score <- 0.0 cnt <- 0.0 for (i in 1:min(k,length(predicted))) { if (predicted[i] %in% actual && !(predicted[i] %in% predicted[0:(i-1)])) { cnt <- cnt + 1 score <- score + cnt / i } } return(score / min(length(actual), k)) } #' Mean Average Precision at k #' #' \code{mapk} computes the mean average precision at k for a set of predictions, in #' the context of information retrieval problems. #' #' \code{mapk} evaluates \code{apk} for each pair of elements from \code{actual} and #' \code{predicted}. #' #' @inheritParams apk #' @param 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. #' @param predicted A list of vectors, where each vector represents the predicted vector #' of retrieved documents for the corresponding element of \code{actual}. #' In each vector, the order of the elements does matter, with the #' elements believed most likely to be relevant at the beginning. #' @export #' @seealso \code{\link{apk}} \code{\link{f1}} #' @examples #' 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) mapk <- function(k, actual, predicted) { if (length(actual) == 0 || length(predicted) == 0) { return(0.0) } convert_to_list <- function(x) { if (is.list(x)) { return(x) } else { arg_name <- deparse(substitute(x)) warning(paste(arg_name, 'should be a list of vectors. Converting to a list.')) return(list(x)) } } act <- convert_to_list(actual) pred <- convert_to_list(predicted) scores <- rep(0, length(act)) for (i in 1:length(scores)) { scores[i] <- apk(k, act[[i]], pred[[i]]) } return(mean(scores)) } Metrics/MD50000644000176200001440000000473313320562332012176 0ustar liggesusers65dd0f8e5c82d1e39b3d6fbf76631482 *DESCRIPTION 791422e25711b250471a5fe6438dc52d *LICENSE 2309c2fdf826ae4446f1929f9aa1f9b9 *NAMESPACE cec546791347fcf62f8fb2ee30ca0548 *R/binary_classification.R 7c4268754266c55e07d3a5231560107e *R/classification.R bd7c2873d0c1388196d8b8730e3336b2 *R/information_retrieval.R 1b03ebf1b028e45f1c92526a58fed053 *R/regression.R 9350394ff2cafc57f6857924a0c5c927 *R/time_series.R 95096d64e92ba362266c071355308f0f *man/MeanQuadraticWeightedKappa.Rd d95b8f69751e7fa9884132735b944ccd *man/ScoreQuadraticWeightedKappa.Rd 9ee63de51ae2a7f5e67ef61904e6946e *man/accuracy.Rd abf5977652e14c6a1d62a50cb22f6f45 *man/ae.Rd 3a51492b36ceb5f9f9f170ac11a256cc *man/ape.Rd f5afe0f72a0e27e69a3a582be1d6c8bd *man/apk.Rd 66977400c65790d66e9419f8956967e1 *man/auc.Rd 2e78e6def05661bb74c03203dcdade8d *man/bias.Rd 9f8b5245525b5e788bbd835a8367c6b9 *man/ce.Rd 3a6aa3c15011b948ed1162a1caa3c154 *man/f1.Rd 88aedde42d15faef23b29497e0211fb5 *man/fbeta_score.Rd 43a5011486c9026d13601352cbdf4f78 *man/ll.Rd be40b4aa172f79c63020ef561dadaff1 *man/logLoss.Rd c6499b6876be22758b428b437f1dff7e *man/mae.Rd 48361c78fe4350281e04fb2ca0831bb9 *man/mape.Rd 7c286573f18d315be12bed01a947d515 *man/mapk.Rd 2becf7fd06b710e127bd592ce8748965 *man/mase.Rd 3ab4c66d9c970ec8257ee83e4551f361 *man/mdae.Rd 3b00849c2ad674218b8ebb4b87d35c9a *man/mse.Rd c62455226ec946a7c792689a90fbd4c3 *man/msle.Rd 37ce9c0f232796374cbc8598a2525345 *man/params_binary.Rd 264d6c1aa6be7135a2388888ee8a18e7 *man/params_classification.Rd fa75d22313dac2698db11fd62ea720f8 *man/params_regression.Rd 2c3f931ad9a5ab53e61bfa879aa49ed2 *man/percent_bias.Rd ba92c89d70842a674cfd32367a363ba9 *man/precision.Rd f41d502411f796528227238d26a5c585 *man/rae.Rd 493ca4fc4503341dd1c1755977747a66 *man/recall.Rd cd4166ad08131dda1f7da5f5cc85249e *man/rmse.Rd ea2477f0dea13f1ae4ef18051ee1aacb *man/rmsle.Rd a1d853d6865871ff0011114c277a680f *man/rrse.Rd 3ab84f52e64f0dd61f9dc655d4438637 *man/rse.Rd 117634f41ba0eddae5db36dd655fd4ba *man/se.Rd cafed68603abac82c495cdfef08f6c98 *man/sle.Rd 5d57412dc717a69e063766e98ca47114 *man/smape.Rd a1b431aa17fea1c6eda7d2e573b35d84 *man/sse.Rd 0a6dd13415a44008eb1f86c1c86c5dbf *tests/testthat.R 76513e2b6fa2fe00f781b702789ba78d *tests/testthat/test-binary_classification.R a25c97f99a185ef91fd2ecf27fe15bf9 *tests/testthat/test-classification.R c778e0ab85136cd254762d9370097116 *tests/testthat/test-information_retrieval.R eae2eef244e719eccce3acefee60b883 *tests/testthat/test-regression.R 08afb950990c3759ab8c667a4a4a9e89 *tests/testthat/test-time_series.R Metrics/DESCRIPTION0000644000176200001440000000214513320562332013367 0ustar liggesusersPackage: Metrics Version: 0.1.4 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@R: c( person("Ben", "Hamner", role = c("aut", "cph"), email = "ben@benhamner.com"), person("Michael", "Frasco", role = c("aut", "cre"), email = "mfrasco6@gmail.com"), person("Erin", "LeDell", role = c("ctb"), email = "oss@ledell.org")) Maintainer: Michael Frasco Suggests: testthat URL: https://github.com/mfrasco/Metrics BugReports: https://github.com/mfrasco/Metrics/issues License: BSD_3_clause + file LICENSE RoxygenNote: 6.0.1 NeedsCompilation: no Packaged: 2018-07-09 03:33:50 UTC; mfrasco Author: Ben Hamner [aut, cph], Michael Frasco [aut, cre], Erin LeDell [ctb] Repository: CRAN Date/Publication: 2018-07-09 04:30:18 UTC Metrics/man/0000755000176200001440000000000013320553636012441 5ustar liggesusersMetrics/man/mase.Rd0000644000176200001440000000273413201251161013645 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/time_series.R \name{mase} \alias{mase} \title{Mean Absolute Scaled Error} \usage{ mase(actual, predicted, step_size = 1) } \arguments{ \item{actual}{The ground truth numeric vector ordered in time, with most recent observation at the end of the vector.} \item{predicted}{The predicted numeric vector ordered in time, where each element of the vector represents a prediction for the corresponding element of \code{actual}.} \item{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 \code{1}, which means that the naive forecast for the current time period is the actual value of the previous period. However, if \code{actual} and \code{predictions} were quarterly predictions over many years, letting \code{step_size = 4}, would mean that the naive forecast for the current time period would be the actual value from the same quarter last year. In this way, \code{mase} can account for seasonality.} } \description{ \code{mase} computes the mean absolute scaled error between two numeric vectors. This function is only intended for time series data, where \code{actual} and \code{numeric} are numeric vectors ordered by time. } \examples{ 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) } \seealso{ \code{\link{smape}} \code{\link{mape}} } Metrics/man/msle.Rd0000644000176200001440000000174213201251161013656 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/regression.R \name{msle} \alias{msle} \title{Mean Squared Log Error} \usage{ msle(actual, predicted) } \arguments{ \item{actual}{The ground truth non-negative vector} \item{predicted}{The predicted non-negative vector, where each element in the vector is a prediction for the corresponding element in \code{actual}.} } \description{ \code{msle} computes the average of squared log error between two numeric vectors. } \details{ \code{msle} adds one to both \code{actual} and \code{predicted} before taking the natural logarithm to avoid taking the natural log of zero. As a result, the function can be used if \code{actual} or \code{predicted} have zero-valued elements. But this function is not appropriate if either are negative valued. } \examples{ 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) } \seealso{ \code{\link{rmsle}} \code{\link{sle}} } Metrics/man/sle.Rd0000644000176200001440000000176113201251161013502 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/regression.R \name{sle} \alias{sle} \title{Squared Log Error} \usage{ sle(actual, predicted) } \arguments{ \item{actual}{The ground truth non-negative vector} \item{predicted}{The predicted non-negative vector, where each element in the vector is a prediction for the corresponding element in \code{actual}.} } \description{ \code{sle} computes the elementwise squares of the differences in the logs of two numeric vectors. } \details{ \code{sle} adds one to both \code{actual} and \code{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 \code{actual} or \code{predicted} have zero-valued elements. But this function is not appropriate if either are negative valued. } \examples{ 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) } \seealso{ \code{\link{msle}} \code{\link{rmsle}} } Metrics/man/mape.Rd0000644000176200001440000000176413261056363013661 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/regression.R \name{mape} \alias{mape} \title{Mean Absolute Percent Error} \usage{ mape(actual, predicted) } \arguments{ \item{actual}{The ground truth numeric vector.} \item{predicted}{The predicted numeric vector, where each element in the vector is a prediction for the corresponding element in \code{actual}.} } \description{ \code{mape} computes the average absolute percent difference between two numeric vectors. } \details{ \code{mape} is calculated as the average of (\code{actual} - \code{predicted}) / \code{abs(actual)}. This means that the function will return \code{-Inf}, \code{Inf}, or \code{NaN} if \code{actual} is zero. Due to the instability at or near zero, \code{smape} or \code{mase} are often used as alternatives. } \examples{ 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) } \seealso{ \code{\link{mae}} \code{\link{smape}} \code{\link{mase}} } Metrics/man/accuracy.Rd0000644000176200001440000000133413201251161014505 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/classification.R \name{accuracy} \alias{accuracy} \title{Accuracy} \usage{ accuracy(actual, predicted) } \arguments{ \item{actual}{The ground truth vector, where elements of the vector can be any variable type.} \item{predicted}{The predicted vector, where elements of the vector represent a prediction for the corresponding value in \code{actual}.} } \description{ \code{accuracy} is defined as the proportion of elements in \code{actual} that are equal to the corresponding element in \code{predicted} } \examples{ actual <- c('a', 'a', 'c', 'b', 'c') predicted <- c('a', 'b', 'c', 'b', 'a') accuracy(actual, predicted) } \seealso{ \code{\link{ce}} } Metrics/man/rmse.Rd0000644000176200001440000000117513201251161013664 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/regression.R \name{rmse} \alias{rmse} \title{Root Mean Squared Error} \usage{ rmse(actual, predicted) } \arguments{ \item{actual}{The ground truth numeric vector.} \item{predicted}{The predicted numeric vector, where each element in the vector is a prediction for the corresponding element in \code{actual}.} } \description{ \code{rmse} computes the root mean squared error between two numeric vectors } \examples{ 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) } \seealso{ \code{\link{mse}} } Metrics/man/fbeta_score.Rd0000644000176200001440000000235513307037336015210 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/binary_classification.R \name{fbeta_score} \alias{fbeta_score} \title{F-beta Score} \usage{ fbeta_score(actual, predicted, beta = 1) } \arguments{ \item{actual}{The ground truth binary numeric vector containing 1 for the positive class and 0 for the negative class.} \item{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 \code{actual}.} \item{beta}{A non-negative real number controlling how close the F-beta score is to either Precision or Recall. When \code{beta} is at the default of 1, the F-beta Score is exactly an equally weighted harmonic mean. The F-beta score will weight toward Precision when \code{beta} is less than one. The F-beta score will weight toward Recall when \code{beta} is greater than one.} } \description{ \code{fbeta_score} computes a weighted harmonic mean of Precision and Recall. The \code{beta} parameter controls the weighting. } \examples{ actual <- c(1, 1, 1, 0, 0, 0) predicted <- c(1, 0, 1, 1, 1, 1) recall(actual, predicted) } \seealso{ \code{\link{precision}} \code{\link{recall}} } Metrics/man/apk.Rd0000644000176200001440000000271713201251161013474 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/information_retrieval.R \name{apk} \alias{apk} \title{Average Precision at k} \usage{ apk(k, actual, predicted) } \arguments{ \item{k}{The number of elements of \code{predicted} to consider in the calculation.} \item{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 \code{predicted}.} \item{predicted}{The predicted vector of retrieved documents. The vector can contain any numeric of character values. However, unlike \code{actual}, order does matter, with the most documents deemed most likely to be relevant at the beginning.} } \description{ \code{apk} computes the average precision at k, in the context of information retrieval problems. } \details{ \code{apk} loops over the first k values of \code{predicted}. For each value, if the value is contained within \code{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 \code{actual}). \code{apk} will return \code{NaN} if \code{length(actual)} equals \code{0}. } \examples{ actual <- c('a', 'b', 'd') predicted <- c('b', 'c', 'a', 'e', 'f') apk(3, actual, predicted) } \seealso{ \code{\link{apk}} \code{\link{f1}} } Metrics/man/percent_bias.Rd0000644000176200001440000000210013261056363015356 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/regression.R \name{percent_bias} \alias{percent_bias} \title{Percent Bias} \usage{ percent_bias(actual, predicted) } \arguments{ \item{actual}{The ground truth numeric vector.} \item{predicted}{The predicted numeric vector, where each element in the vector is a prediction for the corresponding element in \code{actual}.} } \description{ \code{percent_bias} computes the average amount that \code{actual} is greater than \code{predicted} as a percentage of the absolute value of \code{actual}. } \details{ If a model is unbiased \code{percent_bias(actual, predicted)} should be close to zero. Percent Bias is calculated by taking the average of (\code{actual} - \code{predicted}) / \code{abs(actual)} across all observations. \code{percent_bias} will give \code{-Inf}, \code{Inf}, or \code{NaN}, if any elements of \code{actual} are \code{0}. } \examples{ 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) } \seealso{ \code{\link{bias}} } Metrics/man/rrse.Rd0000644000176200001440000000163213201251161013667 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/regression.R \name{rrse} \alias{rrse} \title{Root Relative Squared Error} \usage{ rrse(actual, predicted) } \arguments{ \item{actual}{The ground truth numeric vector.} \item{predicted}{The predicted numeric vector, where each element in the vector is a prediction for the corresponding element in \code{actual}.} } \description{ \code{rrse} computes the root relative squared error between two numeric vectors. } \details{ \code{rrse} takes the square root of \code{sse(actual, predicted)} divided by \code{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. } \examples{ 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) } \seealso{ \code{\link{rse}} \code{\link{rae}} } Metrics/man/ape.Rd0000644000176200001440000000154013261056363013474 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/regression.R \name{ape} \alias{ape} \title{Absolute Percent Error} \usage{ ape(actual, predicted) } \arguments{ \item{actual}{The ground truth numeric vector.} \item{predicted}{The predicted numeric vector, where each element in the vector is a prediction for the corresponding element in \code{actual}.} } \description{ \code{ape} computes the elementwise absolute percent difference between two numeric vectors } \details{ \code{ape} is calculated as (\code{actual} - \code{predicted}) / \code{abs(actual)}. This means that the function will return \code{-Inf}, \code{Inf}, or \code{NaN} if \code{actual} is zero. } \examples{ 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) } \seealso{ \code{\link{mape}} \code{smape} } Metrics/man/ll.Rd0000644000176200001440000000131213201251161013316 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/binary_classification.R \name{ll} \alias{ll} \title{Log Loss} \usage{ ll(actual, predicted) } \arguments{ \item{actual}{The ground truth binary numeric vector containing 1 for the positive class and 0 for the negative class.} \item{predicted}{A numeric vector of predicted values, where the values correspond to the probabilities that each observation in \code{actual} belongs to the positive class} } \description{ \code{ll} computes the elementwise log loss between two numeric vectors. } \examples{ 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) } \seealso{ \code{\link{logLoss}} } Metrics/man/mae.Rd0000644000176200001440000000121513201251161013453 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/regression.R \name{mae} \alias{mae} \title{Mean Absolute Error} \usage{ mae(actual, predicted) } \arguments{ \item{actual}{The ground truth numeric vector.} \item{predicted}{The predicted numeric vector, where each element in the vector is a prediction for the corresponding element in \code{actual}.} } \description{ \code{mae} computes the average absolute difference between two numeric vectors. } \examples{ 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) } \seealso{ \code{\link{mdae}} \code{\link{mape}} } Metrics/man/mdae.Rd0000644000176200001440000000122213201251161013615 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/regression.R \name{mdae} \alias{mdae} \title{Median Absolute Error} \usage{ mdae(actual, predicted) } \arguments{ \item{actual}{The ground truth numeric vector.} \item{predicted}{The predicted numeric vector, where each element in the vector is a prediction for the corresponding element in \code{actual}.} } \description{ \code{mdae} computes the median absolute difference between two numeric vectors. } \examples{ 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) } \seealso{ \code{\link{mae}} \code{\link{mape}} } Metrics/man/ce.Rd0000644000176200001440000000132513201251161013302 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/classification.R \name{ce} \alias{ce} \title{Classification Error} \usage{ ce(actual, predicted) } \arguments{ \item{actual}{The ground truth vector, where elements of the vector can be any variable type.} \item{predicted}{The predicted vector, where elements of the vector represent a prediction for the corresponding value in \code{actual}.} } \description{ \code{ce} is defined as the proportion of elements in \code{actual} that are not equal to the corresponding element in \code{predicted}. } \examples{ actual <- c('a', 'a', 'c', 'b', 'c') predicted <- c('a', 'b', 'c', 'b', 'a') ce(actual, predicted) } \seealso{ \code{\link{accuracy}} } Metrics/man/bias.Rd0000644000176200001440000000146213201251161013633 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/regression.R \name{bias} \alias{bias} \title{Bias} \usage{ bias(actual, predicted) } \arguments{ \item{actual}{The ground truth numeric vector.} \item{predicted}{The predicted numeric vector, where each element in the vector is a prediction for the corresponding element in \code{actual}.} } \description{ \code{bias} computes the average amount by which \code{actual} is greater than \code{predicted}. } \details{ If a model is unbiased \code{bias(actual, predicted)} should be close to zero. Bias is calculated by taking the average of (\code{actual} - \code{predicted}). } \examples{ 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) } \seealso{ \code{\link{percent_bias}} } Metrics/man/auc.Rd0000644000176200001440000000234513201251161013466 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/binary_classification.R \name{auc} \alias{auc} \title{Area under the ROC curve (AUC)} \usage{ auc(actual, predicted) } \arguments{ \item{actual}{The ground truth binary numeric vector containing 1 for the positive class and 0 for the negative class.} \item{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 \code{actual}.} } \description{ \code{auc} computes the area under the receiver-operator characteristic curve (AUC). } \details{ \code{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. } \examples{ 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) } Metrics/man/params_regression.Rd0000644000176200001440000000102713201251161016435 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/regression.R \name{params_regression} \alias{params_regression} \title{Inherit Documentation for Regression Metrics} \arguments{ \item{actual}{The ground truth numeric vector.} \item{predicted}{The predicted numeric vector, where each element in the vector is a prediction for the corresponding element in \code{actual}.} } \description{ This object provides the documentation for the parameters of functions that provide regression metrics } Metrics/man/rae.Rd0000644000176200001440000000157613201251161013472 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/regression.R \name{rae} \alias{rae} \title{Relative Absolute Error} \usage{ rae(actual, predicted) } \arguments{ \item{actual}{The ground truth numeric vector.} \item{predicted}{The predicted numeric vector, where each element in the vector is a prediction for the corresponding element in \code{actual}.} } \description{ \code{rae} computes the relative absolute error between two numeric vectors. } \details{ \code{rae} divides \code{sum(ae(actual, predicted))} by \code{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. } \examples{ 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) } \seealso{ \code{\link{rse}} \code{\link{rrse}} } Metrics/man/se.Rd0000644000176200001440000000120413201251161013316 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/regression.R \name{se} \alias{se} \title{Squared Error} \usage{ se(actual, predicted) } \arguments{ \item{actual}{The ground truth numeric vector.} \item{predicted}{The predicted numeric vector, where each element in the vector is a prediction for the corresponding element in \code{actual}.} } \description{ \code{se} computes the elementwise squared difference between two numeric vectors. } \examples{ 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) } \seealso{ \code{\link{mse}} \code{\link{rmse}} } Metrics/man/ScoreQuadraticWeightedKappa.Rd0000644000176200001440000000155613201251161020270 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/classification.R \name{ScoreQuadraticWeightedKappa} \alias{ScoreQuadraticWeightedKappa} \title{Quadratic Weighted Kappa} \usage{ ScoreQuadraticWeightedKappa(rater.a, rater.b, min.rating = min(c(rater.a, rater.b)), max.rating = max(c(rater.a, rater.b))) } \arguments{ \item{rater.a}{An integer vector of the first rater's ratings.} \item{rater.b}{An integer vector of the second rater's ratings.} \item{min.rating}{The minimum possible rating.} \item{max.rating}{The maximum possible rating.} } \description{ \code{ScoreQuadraticWeightedKappa} computes the quadratic weighted kappa between two vectors of integers } \examples{ 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) } \seealso{ \code{\link{MeanQuadraticWeightedKappa}} } Metrics/man/sse.Rd0000644000176200001440000000117613201251161013511 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/regression.R \name{sse} \alias{sse} \title{Sum of Squared Errors} \usage{ sse(actual, predicted) } \arguments{ \item{actual}{The ground truth numeric vector.} \item{predicted}{The predicted numeric vector, where each element in the vector is a prediction for the corresponding element in \code{actual}.} } \description{ \code{sse} computes the sum of the squared differences between two numeric vectors. } \examples{ 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) } \seealso{ \code{\link{mse}} } Metrics/man/rse.Rd0000644000176200001440000000156213201251161013507 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/regression.R \name{rse} \alias{rse} \title{Relative Squared Error} \usage{ rse(actual, predicted) } \arguments{ \item{actual}{The ground truth numeric vector.} \item{predicted}{The predicted numeric vector, where each element in the vector is a prediction for the corresponding element in \code{actual}.} } \description{ \code{rse} computes the relative squared error between two numeric vectors. } \details{ \code{rse} divides \code{sse(actual, predicted)} by \code{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. } \examples{ 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) } \seealso{ \code{\link{rrse}} \code{\link{rae}} } Metrics/man/ae.Rd0000644000176200001440000000123113201251161013274 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/regression.R \name{ae} \alias{ae} \title{Absolute Error} \usage{ ae(actual, predicted) } \arguments{ \item{actual}{The ground truth numeric vector.} \item{predicted}{The predicted numeric vector, where each element in the vector is a prediction for the corresponding element in \code{actual}.} } \description{ \code{ae} computes the elementwise absolute difference between two numeric vectors. } \examples{ 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) } \seealso{ \code{\link{mae}} \code{\link{mdae}} \code{\link{mape}} } Metrics/man/f1.Rd0000644000176200001440000000243013201251161013217 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/information_retrieval.R \name{f1} \alias{f1} \title{F1 Score} \usage{ f1(actual, predicted) } \arguments{ \item{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 \code{predicted}.} \item{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 \code{actual}.} } \description{ \code{f1} computes the F1 Score in the context of information retrieval problems. } \details{ \code{f1} is defined as \eqn{2 * precision * recall / (precision + recall)}. 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, \code{f1} is defined as \code{0}. } \examples{ actual <- c('a', 'c', 'd') predicted <- c('d', 'e') f1(actual, predicted) } \seealso{ \code{\link{apk}} \code{\link{mapk}} } Metrics/man/recall.Rd0000644000176200001440000000167613307037336014203 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/binary_classification.R \name{recall} \alias{recall} \title{Recall} \usage{ recall(actual, predicted) } \arguments{ \item{actual}{The ground truth binary numeric vector containing 1 for the positive class and 0 for the negative class.} \item{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 \code{actual}.} } \description{ \code{recall} computes proportion of observations in the positive class (i.e. the element in \code{actual} equals 1) that are predicted to be in the positive class (i.e. the element in \code{predicted} equals 1) } \examples{ actual <- c(1, 1, 1, 0, 0, 0) predicted <- c(1, 0, 1, 1, 1, 1) recall(actual, predicted) } \seealso{ \code{\link{precision}} \code{\link{fbeta_score}} } Metrics/man/params_binary.Rd0000644000176200001440000000126613201251161015546 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/binary_classification.R \name{params_binary} \alias{params_binary} \title{Inherit Documentation for Binary Classification Metrics} \arguments{ \item{actual}{The ground truth binary numeric vector containing 1 for the positive class and 0 for the negative class.} \item{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 \code{actual}.} } \description{ This object provides the documentation for the parameters of functions that provide binary classification metrics } Metrics/man/mse.Rd0000644000176200001440000000121213201251161013472 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/regression.R \name{mse} \alias{mse} \title{Mean Squared Error} \usage{ mse(actual, predicted) } \arguments{ \item{actual}{The ground truth numeric vector.} \item{predicted}{The predicted numeric vector, where each element in the vector is a prediction for the corresponding element in \code{actual}.} } \description{ \code{mse} computes the average squared difference between two numeric vectors. } \examples{ 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) } \seealso{ \code{\link{rmse}} \code{\link{mae}} } Metrics/man/rmsle.Rd0000644000176200001440000000175313201251161014042 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/regression.R \name{rmsle} \alias{rmsle} \title{Root Mean Squared Log Error} \usage{ rmsle(actual, predicted) } \arguments{ \item{actual}{The ground truth non-negative vector} \item{predicted}{The predicted non-negative vector, where each element in the vector is a prediction for the corresponding element in \code{actual}.} } \description{ \code{rmsle} computes the root mean squared log error between two numeric vectors. } \details{ \code{rmsle} adds one to both \code{actual} and \code{predicted} before taking the natural logarithm to avoid taking the natural log of zero. As a result, the function can be used if \code{actual} or \code{predicted} have zero-valued elements. But this function is not appropriate if either are negative valued. } \examples{ 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) } \seealso{ \code{\link{msle}} \code{\link{sle}} } Metrics/man/smape.Rd0000644000176200001440000000223413201251161014020 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/regression.R \name{smape} \alias{smape} \title{Symmetric Mean Absolute Percentage Error} \usage{ smape(actual, predicted) } \arguments{ \item{actual}{The ground truth numeric vector.} \item{predicted}{The predicted numeric vector, where each element in the vector is a prediction for the corresponding element in \code{actual}.} } \description{ \code{smape} computes the symmetric mean absolute percentage error between two numeric vectors. } \details{ \code{smape} is defined as two times the average of \code{abs(actual - predicted) / (abs(actual) + abs(predicted))}. Therefore, at the elementwise level, it will provide \code{NaN} only if \code{actual} and \code{predicted} are both zero. It has an upper bound of \code{2}, when either \code{actual} or \code{predicted} are zero or when \code{actual} and \code{predicted} are opposite signs. \code{smape} is symmetric in the sense that \code{smape(x, y) = smape(y, x)}. } \examples{ 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) } \seealso{ \code{\link{mape}} \code{\link{mase}} } Metrics/man/params_classification.Rd0000644000176200001440000000112313201251161017245 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/classification.R \name{params_classification} \alias{params_classification} \title{Inherit Documentation for Classification Metrics} \arguments{ \item{actual}{The ground truth vector, where elements of the vector can be any variable type.} \item{predicted}{The predicted vector, where elements of the vector represent a prediction for the corresponding value in \code{actual}.} } \description{ This object provides the documentation for the parameters of functions that provide classification metrics } Metrics/man/precision.Rd0000644000176200001440000000174313307037336014727 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/binary_classification.R \name{precision} \alias{precision} \title{Precision} \usage{ precision(actual, predicted) } \arguments{ \item{actual}{The ground truth binary numeric vector containing 1 for the positive class and 0 for the negative class.} \item{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 \code{actual}.} } \description{ \code{precision} computes proportion of observations predicted to be in the positive class (i.e. the element in \code{predicted} equals 1) that actually belong to the positive class (i.e. the element in \code{actual} equals 1) } \examples{ actual <- c(1, 1, 1, 0, 0, 0) predicted <- c(1, 1, 1, 1, 1, 1) precision(actual, predicted) } \seealso{ \code{\link{recall}} \code{\link{fbeta_score}} } Metrics/man/mapk.Rd0000644000176200001440000000260513201251161013645 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/information_retrieval.R \name{mapk} \alias{mapk} \title{Mean Average Precision at k} \usage{ mapk(k, actual, predicted) } \arguments{ \item{k}{The number of elements of \code{predicted} to consider in the calculation.} \item{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.} \item{predicted}{A list of vectors, where each vector represents the predicted vector of retrieved documents for the corresponding element of \code{actual}. In each vector, the order of the elements does matter, with the elements believed most likely to be relevant at the beginning.} } \description{ \code{mapk} computes the mean average precision at k for a set of predictions, in the context of information retrieval problems. } \details{ \code{mapk} evaluates \code{apk} for each pair of elements from \code{actual} and \code{predicted}. } \examples{ 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) } \seealso{ \code{\link{apk}} \code{\link{f1}} } Metrics/man/MeanQuadraticWeightedKappa.Rd0000644000176200001440000000132613201251161020070 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/classification.R \name{MeanQuadraticWeightedKappa} \alias{MeanQuadraticWeightedKappa} \title{Mean Quadratic Weighted Kappa} \usage{ MeanQuadraticWeightedKappa(kappas, weights = rep(1, length(kappas))) } \arguments{ \item{kappas}{A numeric vector of possible kappas.} \item{weights}{An optional numeric vector of ratings.} } \description{ \code{MeanQuadraticWeightedKappa} computes the mean quadratic weighted kappa, which can optionally be weighted } \examples{ 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) } \seealso{ \code{\link{ScoreQuadraticWeightedKappa}} } Metrics/man/logLoss.Rd0000644000176200001440000000133713201251161014340 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/binary_classification.R \name{logLoss} \alias{logLoss} \title{Mean Log Loss} \usage{ logLoss(actual, predicted) } \arguments{ \item{actual}{The ground truth binary numeric vector containing 1 for the positive class and 0 for the negative class.} \item{predicted}{A numeric vector of predicted values, where the values correspond to the probabilities that each observation in \code{actual} belongs to the positive class} } \description{ \code{logLoss} computes the average log loss between two numeric vectors. } \examples{ 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) } \seealso{ \code{\link{ll}} } Metrics/LICENSE0000644000176200001440000000011013320552556012663 0ustar liggesusersYEAR: 2018 COPYRIGHT HOLDER: Ben Hamner ORGANIZATION: mfrasco6@gmail.com