Skip to content

Commit

Permalink
add regression metrics MAE and RMSLE
Browse files Browse the repository at this point in the history
  • Loading branch information
nanxstats committed Oct 19, 2015
1 parent 8dce815 commit 59e64d4
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 9 deletions.
2 changes: 2 additions & 0 deletions R-package/NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ export(mx.io.extract)
export(mx.kv.create)
export(mx.metric.accuracy)
export(mx.metric.custom)
export(mx.metric.mae)
export(mx.metric.rmse)
export(mx.metric.rmsle)
export(mx.model.FeedForward.create)
export(mx.model.load)
export(mx.model.save)
Expand Down
26 changes: 21 additions & 5 deletions R-package/R/metric.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' Helper function to create a customized metric
#'
#'
#' @export
mx.metric.custom <-function(name, feval) {
mx.metric.custom <- function(name, feval) {
init <- function() {
c(0, 0)
}
Expand All @@ -18,18 +18,34 @@ mx.metric.custom <-function(name, feval) {
return(ret)
}

#' Accuracy metric
#' Accuracy metric for classification
#'
#' @export
mx.metric.accuracy <- mx.metric.custom("accuracy", function(label, pred) {
ypred = max.col(pred, tie="first")
return(sum((label + 1) == ypred) / length(label))
})

#' RMSE metric
#'
#' RMSE (Root Mean Squared Error) metric for regression
#'
#' @export
mx.metric.rmse <- mx.metric.custom("rmse", function(label, pred) {
res <- sqrt(mean((label-pred)^2))
return(res)
})

#' MAE (Mean Absolute Error) metric for regression
#'
#' @export
mx.metric.mae <- mx.metric.custom("mae", function(label, pred) {
res <- mean(abs(label-pred))
return(res)
})

#' RMSLE (Root Mean Squared Logarithmic Error) metric for regression
#'
#' @export
mx.metric.rmsle <- mx.metric.custom("rmsle", function(label, pred) {
res <- sqrt(mean((log(pred + 1) - log(label + 1))^2))
return(res)
})
4 changes: 2 additions & 2 deletions R-package/man/mx.metric.accuracy.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
\docType{data}
\name{mx.metric.accuracy}
\alias{mx.metric.accuracy}
\title{Accuracy metric}
\title{Accuracy metric for classification}
\format{\preformatted{List of 3
$ init :function ()
$ update:function (label, pred, state)
Expand All @@ -14,7 +14,7 @@
mx.metric.accuracy
}
\description{
Accuracy metric
Accuracy metric for classification
}
\keyword{datasets}

20 changes: 20 additions & 0 deletions R-package/man/mx.metric.mae.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
% Generated by roxygen2 (4.1.1): do not edit by hand
% Please edit documentation in R/metric.R
\docType{data}
\name{mx.metric.mae}
\alias{mx.metric.mae}
\title{MAE (Mean Absolute Error) metric for regression}
\format{\preformatted{List of 3
$ init :function ()
$ update:function (label, pred, state)
$ get :function (state)
- attr(*, "class")= chr "mx.metric"
}}
\usage{
mx.metric.mae
}
\description{
MAE (Mean Absolute Error) metric for regression
}
\keyword{datasets}

4 changes: 2 additions & 2 deletions R-package/man/mx.metric.rmse.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
\docType{data}
\name{mx.metric.rmse}
\alias{mx.metric.rmse}
\title{RMSE metric}
\title{RMSE (Root Mean Squared Error) metric for regression}
\format{\preformatted{List of 3
$ init :function ()
$ update:function (label, pred, state)
Expand All @@ -14,7 +14,7 @@
mx.metric.rmse
}
\description{
RMSE metric
RMSE (Root Mean Squared Error) metric for regression
}
\keyword{datasets}

20 changes: 20 additions & 0 deletions R-package/man/mx.metric.rmsle.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
% Generated by roxygen2 (4.1.1): do not edit by hand
% Please edit documentation in R/metric.R
\docType{data}
\name{mx.metric.rmsle}
\alias{mx.metric.rmsle}
\title{RMSLE (Root Mean Squared Logarithmic Error) metric for regression}
\format{\preformatted{List of 3
$ init :function ()
$ update:function (label, pred, state)
$ get :function (state)
- attr(*, "class")= chr "mx.metric"
}}
\usage{
mx.metric.rmsle
}
\description{
RMSLE (Root Mean Squared Logarithmic Error) metric for regression
}
\keyword{datasets}

0 comments on commit 59e64d4

Please sign in to comment.