From 98a4cecec5f36ed713b9717b75d5e496e0c0d619 Mon Sep 17 00:00:00 2001 From: ledell Date: Tue, 25 Apr 2017 19:34:54 -0700 Subject: [PATCH] New Metrics R package version 0.1.3 fixes CRAN issues --- R/.Rbuildignore | 7 + R/DESCRIPTION | 18 +- R/LICENSE | 3 + R/NAMESPACE | 14 +- R/NEWS | 16 ++ R/R/metrics.r | 363 ++++++++++++++++----------- R/README.md | 2 +- R/man/.Rapp.history | 0 R/man/MeanQuadraticWeightedKappa.Rd | 18 +- R/man/ScoreQuadraticWeightedKappa.Rd | 23 +- R/man/ae.Rd | 22 +- R/man/apk.Rd | 20 +- R/man/auc.Rd | 21 +- R/man/ce.Rd | 18 +- R/man/f1.Rd | 19 +- R/man/ll.Rd | 18 +- R/man/logLoss.Rd | 18 +- R/man/mae.Rd | 22 +- R/man/mapk.Rd | 20 +- R/man/mse.Rd | 22 +- R/man/msle.Rd | 18 +- R/man/rae.Rd | 21 +- R/man/rmse.Rd | 22 +- R/man/rmsle.Rd | 18 +- R/man/rrse.Rd | 21 +- R/man/rse.Rd | 21 +- R/man/se.Rd | 18 +- R/man/sle.Rd | 18 +- 28 files changed, 509 insertions(+), 312 deletions(-) create mode 100644 R/.Rbuildignore create mode 100644 R/LICENSE create mode 100644 R/man/.Rapp.history diff --git a/R/.Rbuildignore b/R/.Rbuildignore new file mode 100644 index 0000000..4de2d52 --- /dev/null +++ b/R/.Rbuildignore @@ -0,0 +1,7 @@ +install_r_packages.r +run_r_tests.sh +^.*\.Rproj$ +^\.Rproj\.user$ +^README.*$ +.gitlab-ci.yml +.travis.yml diff --git a/R/DESCRIPTION b/R/DESCRIPTION index eece20a..b926231 100644 --- a/R/DESCRIPTION +++ b/R/DESCRIPTION @@ -1,12 +1,14 @@ Package: Metrics -Title: Evaluation metrics for machine learning -Description: Metrics is a set of evaluation metrics - that is commonly used in supervised machine - learning. -URL: https://github.com/benhamner/Metrics/ -Version: 0.1.1 +Version: 0.1.3 +Title: Evaluation Metrics for Machine Learning +Description: A set of evaluation metrics that are commonly used in supervised machine learning. +Authors@R: c( + person("Ben", "Hamner", role = c("aut", "cre", "cph"), email = "ben@benhamner.com"), + person("Erin", "LeDell", role = c("ctb"), email = "oss@ledell.org")) +URL: https://github.com/benhamner/Metrics/tree/master/R +BugReports: https://github.com/benhamner/Metrics/issues Maintainer: Ben Hamner -Author: Ben Hamner -License: BSD +License: BSD_3_clause + file LICENSE Collate: 'metrics.r' +RoxygenNote: 6.0.1 diff --git a/R/LICENSE b/R/LICENSE new file mode 100644 index 0000000..b0a59ba --- /dev/null +++ b/R/LICENSE @@ -0,0 +1,3 @@ +YEAR: 2012-2017 +COPYRIGHT HOLDER: Ben Hamner +ORGANIZATION: copyright holder diff --git a/R/NAMESPACE b/R/NAMESPACE index bb1943d..d4e8362 100644 --- a/R/NAMESPACE +++ b/R/NAMESPACE @@ -1,20 +1,22 @@ +# Generated by roxygen2: do not edit by hand + +export(MeanQuadraticWeightedKappa) +export(ScoreQuadraticWeightedKappa) export(ae) export(apk) export(auc) export(ce) +export(f1) export(ll) export(logLoss) export(mae) export(mapk) -export(MeanQuadraticWeightedKappa) export(mse) export(msle) +export(rae) export(rmse) export(rmsle) -export(ScoreQuadraticWeightedKappa) +export(rrse) +export(rse) export(se) export(sle) -export(rse) -export(rrse) -export(rae) -export(f1) diff --git a/R/NEWS b/R/NEWS index eae210d..9ce6fd0 100644 --- a/R/NEWS +++ b/R/NEWS @@ -1,3 +1,19 @@ +Version 0.1.3 (2017-04-25) +------------------------------------------------------------------------------ + + * fixed documentation bugs + * fixed CRAN check errors + * re-generated documentation and NAMESPACE using Roxygen2 + * added examples for all the functions + * added a .Rbuildignore for ignoring the top level scripts + * added Erin LeDell as a contributor + +Version 0.1.2 (2017-04-21) +------------------------------------------------------------------------------ + + * package was migrated to “ORPHANED” status on CRAN + * version number bumped automatically by CRAN + Version 0.1.1 (2012-06-19) ------------------------------------------------------------------------------ diff --git a/R/R/metrics.r b/R/R/metrics.r index 3d8ad57..2e435eb 100644 --- a/R/R/metrics.r +++ b/R/R/metrics.r @@ -1,155 +1,211 @@ #' Compute the squared error #' -#' This function computes the elementwise squared error for a -#' number or a vector +#' This function computes the elementwise squared error between +#' two numeric vectors #' -#' @param actual ground truth number or vector -#' @param predicted predicted number or vector +#' @param actual ground truth vector +#' @param predicted predicted vector +#' @examples +#' actual <- c(1,1,1,0,0,0) +#' predicted <- c(0.9,0.8,0.4,0.5,0.3,0.2) +#' se(actual, predicted) #' @export se <- function (actual, predicted) (actual-predicted)^2 -#' Compute the mean squared error#' +#' Compute the mean squared error +#' #' This function computes the mean squared error between -#' two vectors +#' two numeric vectors #' #' @param actual ground truth vector #' @param predicted predicted vector +#' @examples +#' actual <- c(1,1,1,0,0,0) +#' predicted <- c(0.9,0.8,0.4,0.5,0.3,0.2) +#' mse(actual, predicted) #' @export mse <- function (actual, predicted) mean(se(actual, predicted)) -#' Compute the root mean squared error#' +#' Compute the root mean squared error +#' #' This function computes the root mean squared error -#' between two vectors +#' between two numeric vectors #' #' @param actual ground truth vector #' @param predicted predicted vector +#' @examples +#' actual <- c(1,1,1,0,0,0) +#' predicted <- c(0.9,0.8,0.4,0.5,0.3,0.2) +#' rmse(actual, predicted) #' @export rmse <- function (actual, predicted) sqrt(mse(actual, predicted)) -#' Compute the absolute error#' -#' This function computes the elementwise absolute error for a -#' number or a vector +#' Compute the absolute error +#' +#' This function computes the elementwise absolute error between +#' two numeric vectors #' -#' @param actual ground truth number or vector -#' @param predicted predicted number or vector +#' @param actual ground truth vector +#' @param predicted predicted vector +#' @examples +#' actual <- c(1,1,1,0,0,0) +#' predicted <- c(1,0,1,1,0,0) +#' ae(actual, predicted) #' @export ae <- function (actual, predicted) abs(actual-predicted) -#' Compute the mean absolute error#' -#' This function computes the mean absolte error between -#' two vectors +#' Compute the mean absolute error +#' +#' This function computes the mean absolute error between +#' two numeric vectors #' #' @param actual ground truth vector -#' @param predicted vector +#' @param predicted predicted vector +#' @examples +#' actual <- c(1,1,1,0,0,0) +#' predicted <- c(1,0,1,1,0,0) +#' mae(actual, predicted) #' @export mae <- function (actual, predicted) mean(ae(actual, predicted)) #' Compute the squared log error #' -#' This function computes the elementwise squared log error for a -#' number or a vector +#' This function computes the elementwise squared log error between +#' two numeric vectors #' -#' @param actual ground truth number or vector -#' @param predicted predicted number or vector +#' @param actual ground truth vector +#' @param predicted predicted vector +#' @examples +#' actual <- c(1,1,1,0,0,0) +#' predicted <- c(0.9,0.8,0.4,0.5,0.3,0.2) +#' sle(actual, predicted) #' @export sle <- function (actual, predicted) (log(1+actual)-log(1+predicted))^2 #' Compute the mean squared log error #' #' This function computes the mean squared log error between -#' two vectors +#' two numeric vectors #' #' @param actual ground truth vector #' @param predicted predicted vector +#' @examples +#' actual <- c(1,1,1,0,0,0) +#' predicted <- c(0.9,0.8,0.4,0.5,0.3,0.2) +#' msle(actual, predicted) #' @export msle <- function (actual, predicted) mean(sle(actual, predicted)) #' Compute the root mean squared log error #' #' This function computes the root mean squared log error between -#' two vectors +#' two numeric vectors #' #' @param actual ground truth vector #' @param predicted predicted vector +#' @examples +#' actual <- c(1,1,1,0,0,0) +#' predicted <- c(0.9,0.8,0.4,0.5,0.3,0.2) +#' rmsle(actual, predicted) #' @export rmsle <- function (actual, predicted) sqrt(msle(actual, predicted)) #' Compute the relative squared error #' #' This function computes the relative squared error between -#' two vectors +#' two numeric vectors #' #' @param actual ground truth vector #' @param predicted predicted vector +#' @examples +#' actual <- c(1,1,1,0,0,0) +#' predicted <- c(0.9,0.8,0.4,0.5,0.3,0.2) +#' rse(actual, predicted) #' @export -rse <- function (actual, predicted) -{ - sum(se(actual, predicted)) / sum(se(actual, mean(actual))) +rse <- function (actual, predicted) { + sum(se(actual, predicted)) / sum(se(actual, mean(actual))) } #' Compute the root relative squared error #' #' This function computes the root relative squared error between -#' two vectors +#' two numeric vectors #' #' @param actual ground truth vector #' @param predicted predicted vector +#' @examples +#' actual <- c(1,1,1,0,0,0) +#' predicted <- c(0.9,0.8,0.4,0.5,0.3,0.2) +#' rrse(actual, predicted) #' @export rrse <- function (actual, predicted) sqrt(rse(actual, predicted)) #' Compute the relative absolute error #' #' This function computes the relative absolute error between -#' two vectors +#' two numeric vectors #' #' @param actual ground truth vector #' @param predicted predicted vector +#' @examples +#' actual <- c(1,1,1,0,0,0) +#' predicted <- c(1,0,1,1,0,0) +#' rae(actual, predicted) #' @export -rae <- function (actual, predicted) -{ - sum(ae(predicted, actual)) / sum(ae(actual, mean(actual))) +rae <- function (actual, predicted) { + sum(ae(predicted, actual)) / sum(ae(actual, mean(actual))) } -#' Compute the area under the ROC (AUC) +#' Compute the area under the ROC curve (AUC) #' #' This function computes the area under the receiver-operator -#' characteristic (AUC) +#' characteristic curve (AUC) #' -#' @param actual binary vector -#' @param predicted real-valued vector that defines the ranking +#' @param actual binary ground truth vector +#' @param predicted predicted vector (defines the ranking) #' @export -auc <- function(actual, predicted) -{ - r <- rank(predicted) - n_pos <- sum(actual==1) - n_neg <- length(actual) - n_pos - auc <- (sum(r[actual==1]) - n_pos*(n_pos+1)/2) / (n_pos*n_neg) - auc +#' @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) { + r <- rank(predicted) + n_pos <- sum(actual==1) + n_neg <- length(actual) - n_pos + auc <- (sum(r[actual==1]) - n_pos*(n_pos+1)/2) / (n_pos*n_neg) + auc } #' Compute the log loss #' -#' This function computes the elementwise log loss for a -#' number or a vector +#' This function computes the elementwise log loss between +#' two numeric vectors #' -#' @param actual binary ground truth number or vector -#' @param predicted predicted number or vector +#' @param actual binary ground truth vector +#' @param predicted predicted vector +#' @examples +#' actual <- c(1,1,1,0,0,0) +#' predicted <- c(1,0,1,1,0,0) +#' ll(actual, predicted) #' @export -ll <- function(actual, predicted) -{ - score <- -(actual*log(predicted) + (1-actual)*log(1-predicted)) - score[actual==predicted] <- 0 - score[is.nan(score)] <- Inf - score +ll <- function(actual, predicted) { + score <- -(actual*log(predicted) + (1-actual)*log(1-predicted)) + score[actual==predicted] <- 0 + score[is.nan(score)] <- Inf + score } #' Compute the mean log loss #' #' This function computes the mean log loss between -#' two vectors +#' two numeric vectors #' #' @param actual binary ground truth vector #' @param predicted predicted vector +#' @examples +#' actual <- c(1,1,1,0,0,0) +#' predicted <- c(1,0,1,1,0,0) +#' logLoss(actual, predicted) #' @export logLoss <- function(actual, predicted) mean(ll(actual, predicted)) @@ -161,69 +217,71 @@ logLoss <- function(actual, predicted) mean(ll(actual, predicted)) #' @param k max length of predicted sequence #' @param actual ground truth set (vector) #' @param predicted predicted sequence (vector) +#' @examples +#' actual <- c(1,1,1,0,0,0) +#' predicted <- c(1,0,1,1,0,0) +#' apk(4, actual, predicted) #' @export -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 - } +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 } - score <- score / min(length(actual), k) - score + } + score <- score / min(length(actual), k) + score } #' Compute the mean average precision at k #' #' This function computes the mean average precision at k -#' of two lists of sequences. +#' of two sequences #' #' @param k max length of predicted sequence #' @param actual list of ground truth sets (vectors) #' @param predicted list of predicted sequences (vectors) +#' @examples +#' actual <- c(1,1,1,0,0,0) +#' predicted <- c(1,0,1,1,0,0) +#' mapk(4, actual, predicted) #' @export -mapk <- function (k, actual, predicted) -{ - if( length(actual)==0 || length(predicted)==0 ) - { - return(0.0) - } +mapk <- function (k, actual, predicted) { + if ( length(actual)==0 || length(predicted)==0 ) { + return(0.0) + } - scores <- rep(0, length(actual)) - for (i in 1:length(scores)) - { - scores[i] <- apk(k, actual[[i]], predicted[[i]]) - } - score <- mean(scores) - score + scores <- rep(0, length(actual)) + for (i in 1:length(scores)) { + scores[i] <- apk(k, actual[[i]], predicted[[i]]) + } + score <- mean(scores) + score } #' Compute the classification error #' #' This function computes the classification error -#' between two vectors +#' between two numeric vectors #' #' @param actual ground truth vector #' @param predicted predicted vector +#' @examples +#' actual <- c(1,1,1,0,0,0) +#' predicted <- c(1,0,1,1,0,0) +#' ce(actual, predicted) #' @export -ce <- function (actual, predicted) -{ - cntError <- 0.0 - for (i in 1:length(actual)) - { - if (actual[i] != predicted[i]) - { - cntError <- cntError + 1 - } +ce <- function (actual, predicted) { + cntError <- 0.0 + for (i in 1:length(actual)) { + if (actual[i] != predicted[i]) { + cntError <- cntError + 1 } - - score = cntError / length(actual) - score + } + score <- cntError / length(actual) + score } #' Compute the quadratic weighted kappa @@ -235,38 +293,43 @@ ce <- function (actual, predicted) #' @param rater.b is the second rater's ratings #' @param min.rating is the minimum possible rating #' @param max.rating is the maximum possible rating +#' @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) #' @export -ScoreQuadraticWeightedKappa <- function (rater.a , rater.b, +ScoreQuadraticWeightedKappa <- function(rater.a , + rater.b, min.rating, max.rating) { - if (missing(min.rating)) { - min.rating <- min(min(rater.a),min(rater.b)) - } - if (missing(max.rating)) { - max.rating <- max(max(rater.a),max(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 - kappa <- 1 - sum(weights*confusion.mat)/sum(weights*expected.mat) - kappa + if (missing(min.rating)) { + min.rating <- min(min(rater.a),min(rater.b)) + } + if (missing(max.rating)) { + max.rating <- max(max(rater.a),max(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 + kappa <- 1 - sum(weights*confusion.mat)/sum(weights*expected.mat) + kappa } #' Compute the mean quadratic weighted kappa @@ -276,48 +339,56 @@ ScoreQuadraticWeightedKappa <- function (rater.a , rater.b, #' #' @param kappas is a vector of possible kappas #' @param weights is an optional vector of ratings +#' @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) #' @export -MeanQuadraticWeightedKappa <- function (kappas, weights) { +MeanQuadraticWeightedKappa <- function(kappas, weights) { - if (missing(weights)) { - weights <- rep(1, length(kappas)) - } else { - weights <- weights / mean(weights) - } + if (missing(weights)) { + weights <- rep(1, length(kappas)) + } else { + 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) - 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) - kappas <- z2r(kappas) - kappas + 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) + kappas <- z2r(kappas) + kappas } #' Compute the f1 score +#' #' This function computes the f1 score between -#' two vectors. +#' two numeric vectors #' #' @param actual ground truth vector #' @param predicted predicted vector +#' @examples +#' actual <- c(1,1,1,0,0,0) +#' predicted <- c(1,0,1,1,0,0) +#' f1(actual, predicted) #' @export -f1 <- function (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)) - + precision <- ifelse ((tp==0 & fp==0), 0, tp/(tp+fp)) recall <- ifelse ((tp==0 & fn==0), 0, tp/(tp+fn)) - + score <- ifelse ((precision==0 & recall==0), 0, 2*precision*recall/(precision+recall)) score } diff --git a/R/README.md b/R/README.md index 5abeaa4..9b91e74 100644 --- a/R/README.md +++ b/R/README.md @@ -3,7 +3,7 @@ Installation ============ -To install or update, run the following command from the R prompt. You need the latest version of R to get the latest version of Metrics. +To install or update, run the following command from the R prompt. You need the latest version of R to get the latest version of **Metrics**. ``` > install.packages("Metrics") diff --git a/R/man/.Rapp.history b/R/man/.Rapp.history new file mode 100644 index 0000000..e69de29 diff --git a/R/man/MeanQuadraticWeightedKappa.Rd b/R/man/MeanQuadraticWeightedKappa.Rd index 9d6604f..53d90c0 100644 --- a/R/man/MeanQuadraticWeightedKappa.Rd +++ b/R/man/MeanQuadraticWeightedKappa.Rd @@ -1,16 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/metrics.r \name{MeanQuadraticWeightedKappa} \alias{MeanQuadraticWeightedKappa} \title{Compute the mean quadratic weighted kappa} \usage{ - MeanQuadraticWeightedKappa(kappas, weights) +MeanQuadraticWeightedKappa(kappas, weights) } \arguments{ - \item{kappas}{is a vector of possible kappas} +\item{kappas}{is a vector of possible kappas} - \item{weights}{is an optional vector of ratings} +\item{weights}{is an optional vector of ratings} } \description{ - This function computes the mean quadratic weighted kappa, - which can optionally be weighted +This function 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) } - diff --git a/R/man/ScoreQuadraticWeightedKappa.Rd b/R/man/ScoreQuadraticWeightedKappa.Rd index eb47a0d..8334914 100644 --- a/R/man/ScoreQuadraticWeightedKappa.Rd +++ b/R/man/ScoreQuadraticWeightedKappa.Rd @@ -1,21 +1,26 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/metrics.r \name{ScoreQuadraticWeightedKappa} \alias{ScoreQuadraticWeightedKappa} \title{Compute the quadratic weighted kappa} \usage{ - ScoreQuadraticWeightedKappa(rater.a, rater.b, min.rating, - max.rating) +ScoreQuadraticWeightedKappa(rater.a, rater.b, min.rating, max.rating) } \arguments{ - \item{rater.a}{is the first rater's ratings} +\item{rater.a}{is the first rater's ratings} - \item{rater.b}{is the second rater's ratings} +\item{rater.b}{is the second rater's ratings} - \item{min.rating}{is the minimum possible rating} +\item{min.rating}{is the minimum possible rating} - \item{max.rating}{is the maximum possible rating} +\item{max.rating}{is the maximum possible rating} } \description{ - This function computes the quadratic weighted kappa - between two vectors of integers +This function 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) } - diff --git a/R/man/ae.Rd b/R/man/ae.Rd index 36de0e5..43d406e 100644 --- a/R/man/ae.Rd +++ b/R/man/ae.Rd @@ -1,18 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/metrics.r \name{ae} \alias{ae} -\title{Compute the absolute error#' -This function computes the elementwise absolute error for a -number or a vector} +\title{Compute the absolute error} \usage{ - ae(actual, predicted) +ae(actual, predicted) } \arguments{ - \item{actual}{ground truth number or vector} +\item{actual}{ground truth vector} - \item{predicted}{predicted number or vector} +\item{predicted}{predicted vector} } \description{ - Compute the absolute error#' This function computes the - elementwise absolute error for a number or a vector +This function computes the elementwise absolute error between +two numeric vectors +} +\examples{ +actual <- c(1,1,1,0,0,0) +predicted <- c(1,0,1,1,0,0) +ae(actual, predicted) } - diff --git a/R/man/apk.Rd b/R/man/apk.Rd index d9f1da3..88c3465 100644 --- a/R/man/apk.Rd +++ b/R/man/apk.Rd @@ -1,18 +1,24 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/metrics.r \name{apk} \alias{apk} \title{Compute the average precision at k} \usage{ - apk(k, actual, predicted) +apk(k, actual, predicted) } \arguments{ - \item{k}{max length of predicted sequence} +\item{k}{max length of predicted sequence} - \item{actual}{ground truth set (vector)} +\item{actual}{ground truth set (vector)} - \item{predicted}{predicted sequence (vector)} +\item{predicted}{predicted sequence (vector)} } \description{ - This function computes the average precision at k between - two sequences +This function computes the average precision at k +between two sequences +} +\examples{ +actual <- c(1,1,1,0,0,0) +predicted <- c(1,0,1,1,0,0) +apk(4, actual, predicted) } - diff --git a/R/man/auc.Rd b/R/man/auc.Rd index 7ea2e91..6c65da3 100644 --- a/R/man/auc.Rd +++ b/R/man/auc.Rd @@ -1,17 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/metrics.r \name{auc} \alias{auc} -\title{Compute the area under the ROC (AUC)} +\title{Compute the area under the ROC curve (AUC)} \usage{ - auc(actual, predicted) +auc(actual, predicted) } \arguments{ - \item{actual}{binary vector} +\item{actual}{binary ground truth vector} - \item{predicted}{real-valued vector that defines the - ranking} +\item{predicted}{predicted vector (defines the ranking)} } \description{ - This function computes the area under the - receiver-operator characteristic (AUC) +This function computes the area under the receiver-operator +characteristic curve (AUC) +} +\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) } - diff --git a/R/man/ce.Rd b/R/man/ce.Rd index 5f25816..e9e601d 100644 --- a/R/man/ce.Rd +++ b/R/man/ce.Rd @@ -1,16 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/metrics.r \name{ce} \alias{ce} \title{Compute the classification error} \usage{ - ce(actual, predicted) +ce(actual, predicted) } \arguments{ - \item{actual}{ground truth vector} +\item{actual}{ground truth vector} - \item{predicted}{predicted vector} +\item{predicted}{predicted vector} } \description{ - This function computes the classification error between - two vectors +This function computes the classification error +between two numeric vectors +} +\examples{ +actual <- c(1,1,1,0,0,0) +predicted <- c(1,0,1,1,0,0) +ce(actual, predicted) } - diff --git a/R/man/f1.Rd b/R/man/f1.Rd index ff92f0a..23352b1 100644 --- a/R/man/f1.Rd +++ b/R/man/f1.Rd @@ -1,15 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/metrics.r \name{f1} \alias{f1} \title{Compute the f1 score} \usage{ - f1(actual, predicted) +f1(actual, predicted) } \arguments{ - \item{actual}{ground truth vector} - - \item{predicted}{predicted vector} +\item{actual}{ground truth vector} + +\item{predicted}{predicted vector} } \description{ - This function computes the f1 score given the actual and predicted vectors. - f1 score is calculated after calculating Precision and Recall from the two vectors. +This function computes the f1 score between +two numeric vectors +} +\examples{ +actual <- c(1,1,1,0,0,0) +predicted <- c(1,0,1,1,0,0) +f1(actual, predicted) } diff --git a/R/man/ll.Rd b/R/man/ll.Rd index 010f8ac..004e654 100644 --- a/R/man/ll.Rd +++ b/R/man/ll.Rd @@ -1,16 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/metrics.r \name{ll} \alias{ll} \title{Compute the log loss} \usage{ - ll(actual, predicted) +ll(actual, predicted) } \arguments{ - \item{actual}{binary ground truth number or vector} +\item{actual}{binary ground truth vector} - \item{predicted}{predicted number or vector} +\item{predicted}{predicted vector} } \description{ - This function computes the elementwise log loss for a - number or a vector +This function computes the elementwise log loss between +two numeric vectors +} +\examples{ +actual <- c(1,1,1,0,0,0) +predicted <- c(1,0,1,1,0,0) +ll(actual, predicted) } - diff --git a/R/man/logLoss.Rd b/R/man/logLoss.Rd index 647dc2b..2c491d0 100644 --- a/R/man/logLoss.Rd +++ b/R/man/logLoss.Rd @@ -1,16 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/metrics.r \name{logLoss} \alias{logLoss} \title{Compute the mean log loss} \usage{ - logLoss(actual, predicted) +logLoss(actual, predicted) } \arguments{ - \item{actual}{binary ground truth vector} +\item{actual}{binary ground truth vector} - \item{predicted}{predicted vector} +\item{predicted}{predicted vector} } \description{ - This function computes the mean log loss between two - vectors +This function computes the mean log loss between +two numeric vectors +} +\examples{ +actual <- c(1,1,1,0,0,0) +predicted <- c(1,0,1,1,0,0) +logLoss(actual, predicted) } - diff --git a/R/man/mae.Rd b/R/man/mae.Rd index b039e7d..91550b9 100644 --- a/R/man/mae.Rd +++ b/R/man/mae.Rd @@ -1,18 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/metrics.r \name{mae} \alias{mae} -\title{Compute the mean absolute error#' -This function computes the mean absolte error between -two vectors} +\title{Compute the mean absolute error} \usage{ - mae(actual, predicted) +mae(actual, predicted) } \arguments{ - \item{actual}{ground truth vector} +\item{actual}{ground truth vector} - \item{predicted}{vector} +\item{predicted}{predicted vector} } \description{ - Compute the mean absolute error#' This function computes - the mean absolte error between two vectors +This function computes the mean absolute error between +two numeric vectors +} +\examples{ +actual <- c(1,1,1,0,0,0) +predicted <- c(1,0,1,1,0,0) +mae(actual, predicted) } - diff --git a/R/man/mapk.Rd b/R/man/mapk.Rd index 72aa5e0..a0deaab 100644 --- a/R/man/mapk.Rd +++ b/R/man/mapk.Rd @@ -1,18 +1,24 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/metrics.r \name{mapk} \alias{mapk} \title{Compute the mean average precision at k} \usage{ - mapk(k, actual, predicted) +mapk(k, actual, predicted) } \arguments{ - \item{k}{max length of predicted sequence} +\item{k}{max length of predicted sequence} - \item{actual}{list of ground truth sets (vectors)} +\item{actual}{list of ground truth sets (vectors)} - \item{predicted}{list of predicted sequences (vectors)} +\item{predicted}{list of predicted sequences (vectors)} } \description{ - This function computes the mean average precision at k of - two lists of sequences. +This function computes the mean average precision at k +of two sequences +} +\examples{ +actual <- c(1,1,1,0,0,0) +predicted <- c(1,0,1,1,0,0) +mapk(4, actual, predicted) } - diff --git a/R/man/mse.Rd b/R/man/mse.Rd index dda963b..20c51ef 100644 --- a/R/man/mse.Rd +++ b/R/man/mse.Rd @@ -1,18 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/metrics.r \name{mse} \alias{mse} -\title{Compute the mean squared error#' -This function computes the mean squared error between -two vectors} +\title{Compute the mean squared error} \usage{ - mse(actual, predicted) +mse(actual, predicted) } \arguments{ - \item{actual}{ground truth vector} +\item{actual}{ground truth vector} - \item{predicted}{predicted vector} +\item{predicted}{predicted vector} } \description{ - Compute the mean squared error#' This function computes - the mean squared error between two vectors +This function computes the mean squared error 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) +mse(actual, predicted) } - diff --git a/R/man/msle.Rd b/R/man/msle.Rd index 125cbfe..d12ce92 100644 --- a/R/man/msle.Rd +++ b/R/man/msle.Rd @@ -1,16 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/metrics.r \name{msle} \alias{msle} \title{Compute the mean squared log error} \usage{ - msle(actual, predicted) +msle(actual, predicted) } \arguments{ - \item{actual}{ground truth vector} +\item{actual}{ground truth vector} - \item{predicted}{predicted vector} +\item{predicted}{predicted vector} } \description{ - This function computes the mean squared log error between - two vectors +This function computes the mean squared log error 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) +msle(actual, predicted) } - diff --git a/R/man/rae.Rd b/R/man/rae.Rd index 207a6d3..454af39 100644 --- a/R/man/rae.Rd +++ b/R/man/rae.Rd @@ -1,21 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/metrics.r \name{rae} \alias{rae} \title{Compute the relative absolute error} \usage{ - rae(actual, predicted) +rae(actual, predicted) } \arguments{ - \item{actual}{ground truth vector} +\item{actual}{ground truth vector} - \item{predicted}{predicted vector} +\item{predicted}{predicted vector} } \description{ - This function computes the relative absolute error between two vectors. - The relative absolute error is just the total absolute error, - normalized by the error of the simple predictor that predicts - the average values, as described in Witten et al. (2011). +This function computes the relative absolute error between +two numeric vectors } -\references{ - Witten, Ian H, Eibe Frank, and Mark Hall (2011). Data Mining: Practical - Machine Learning Tools and Techniques. 3rd ed. Morgan Kaufman, p. 180. +\examples{ +actual <- c(1,1,1,0,0,0) +predicted <- c(1,0,1,1,0,0) +rae(actual, predicted) } diff --git a/R/man/rmse.Rd b/R/man/rmse.Rd index 6605bc0..bfbf28e 100644 --- a/R/man/rmse.Rd +++ b/R/man/rmse.Rd @@ -1,18 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/metrics.r \name{rmse} \alias{rmse} -\title{Compute the root mean squared error#' -This function computes the root mean squared error -between two vectors} +\title{Compute the root mean squared error} \usage{ - rmse(actual, predicted) +rmse(actual, predicted) } \arguments{ - \item{actual}{ground truth vector} +\item{actual}{ground truth vector} - \item{predicted}{predicted vector} +\item{predicted}{predicted vector} } \description{ - Compute the root mean squared error#' This function - computes the root mean squared error between two vectors +This function computes the root mean squared error +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) +rmse(actual, predicted) } - diff --git a/R/man/rmsle.Rd b/R/man/rmsle.Rd index f5aa9bc..3578e58 100644 --- a/R/man/rmsle.Rd +++ b/R/man/rmsle.Rd @@ -1,16 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/metrics.r \name{rmsle} \alias{rmsle} \title{Compute the root mean squared log error} \usage{ - rmsle(actual, predicted) +rmsle(actual, predicted) } \arguments{ - \item{actual}{ground truth vector} +\item{actual}{ground truth vector} - \item{predicted}{predicted vector} +\item{predicted}{predicted vector} } \description{ - This function computes the root mean squared log error - between two vectors +This function computes the root mean squared log error 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) +rmsle(actual, predicted) } - diff --git a/R/man/rrse.Rd b/R/man/rrse.Rd index 9697d05..cf1c85e 100644 --- a/R/man/rrse.Rd +++ b/R/man/rrse.Rd @@ -1,21 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/metrics.r \name{rrse} \alias{rrse} \title{Compute the root relative squared error} \usage{ - rrse(actual, predicted) +rrse(actual, predicted) } \arguments{ - \item{actual}{ground truth vector} +\item{actual}{ground truth vector} - \item{predicted}{predicted vector} +\item{predicted}{predicted vector} } \description{ - This function computes the root relative squared error between two vectors. - The root relative squared error is relative to what it would have been - if a simple predictor had been used. This simple predictor is - just the average of the actual values, as described in Witten et al. (2011). +This function computes the root relative squared error between +two numeric vectors } -\references{ - Witten, Ian H, Eibe Frank, and Mark Hall (2011). Data Mining: Practical - Machine Learning Tools and Techniques. 3rd ed. Morgan Kaufman, p. 180. +\examples{ +actual <- c(1,1,1,0,0,0) +predicted <- c(0.9,0.8,0.4,0.5,0.3,0.2) +rrse(actual, predicted) } diff --git a/R/man/rse.Rd b/R/man/rse.Rd index 16bdfd1..75259e8 100644 --- a/R/man/rse.Rd +++ b/R/man/rse.Rd @@ -1,21 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/metrics.r \name{rse} \alias{rse} \title{Compute the relative squared error} \usage{ - rse(actual, predicted) +rse(actual, predicted) } \arguments{ - \item{actual}{ground truth vector} +\item{actual}{ground truth vector} - \item{predicted}{predicted vector} +\item{predicted}{predicted vector} } \description{ - This function computes the relative squared error between two vectors. - The relative squared error is relative to what it would have been - if a simple predictor had been used. This simple predictor is - just the average of the actual values, as described in Witten et al. (2011). +This function computes the relative squared error between +two numeric vectors } -\references{ - Witten, Ian H, Eibe Frank, and Mark Hall (2011). Data Mining: Practical - Machine Learning Tools and Techniques. 3rd ed. Morgan Kaufman, p. 180. +\examples{ +actual <- c(1,1,1,0,0,0) +predicted <- c(0.9,0.8,0.4,0.5,0.3,0.2) +rse(actual, predicted) } diff --git a/R/man/se.Rd b/R/man/se.Rd index a442714..4008900 100644 --- a/R/man/se.Rd +++ b/R/man/se.Rd @@ -1,16 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/metrics.r \name{se} \alias{se} \title{Compute the squared error} \usage{ - se(actual, predicted) +se(actual, predicted) } \arguments{ - \item{actual}{ground truth number or vector} +\item{actual}{ground truth vector} - \item{predicted}{predicted number or vector} +\item{predicted}{predicted vector} } \description{ - This function computes the elementwise squared error for - a number or a vector +This function computes the elementwise squared error 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) +se(actual, predicted) } - diff --git a/R/man/sle.Rd b/R/man/sle.Rd index 87b5198..33c99c7 100644 --- a/R/man/sle.Rd +++ b/R/man/sle.Rd @@ -1,16 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/metrics.r \name{sle} \alias{sle} \title{Compute the squared log error} \usage{ - sle(actual, predicted) +sle(actual, predicted) } \arguments{ - \item{actual}{ground truth number or vector} +\item{actual}{ground truth vector} - \item{predicted}{predicted number or vector} +\item{predicted}{predicted vector} } \description{ - This function computes the elementwise squared log error - for a number or a vector +This function computes the elementwise squared log error 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) +sle(actual, predicted) } -