From 3a98fb12078d2aa5caa51289aaaa0e6704f126ad Mon Sep 17 00:00:00 2001 From: theiling Date: Sun, 7 Jun 2015 10:34:17 +0200 Subject: [PATCH] Update metrics. R Corrected rare case, where metrics fails and gives "NaN".. Happens in case of perfect match and both expected.mat and confusion.mat only have one nonzero entry. (Example where the metric fails: rater.a = c(2, 2, 2, 2, 2, 2) rater.b = c(2, 2, 2, 2, 2, 2)) Help by Stephen McInerney in Kaggle forum --- R/R/metrics.r | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/R/metrics.r b/R/R/metrics.r index b770a26..28843bb 100644 --- a/R/R/metrics.r +++ b/R/R/metrics.r @@ -260,7 +260,8 @@ ScoreQuadraticWeightedKappa <- function (rater.a , rater.b, weights <- outer(labels, labels, FUN <- function(x,y) (x-y)^2 ) #calculate kappa - kappa <- 1 - sum(weights*confusion.mat)/sum(weights*expected.mat) + # kappa <- 1 - sum(weights*confusion.mat)/sum(weights*expected.mat) + kappa = ifelse(sum(weights*expected.mat) == 0, 1, 1 - sum(weights*confusion.mat)/sum(weights*expected.mat)) kappa }