ModelMetrics icon indicating copy to clipboard operation
ModelMetrics copied to clipboard

poisson log loss

Open spedygiorgio opened this issue 8 years ago • 2 comments

The following function could be a nice add for the package, since it implements the Poisson Log Loss in Rcpp (also thanks to SO ) and originally written in R in the MLmetrics package:

#include <Rcpp.h>
#include <math.h>
using namespace Rcpp;

// [[Rcpp::export]]
double poissonLogLoss(NumericVector predicted, NumericVector actual) {
  NumericVector temp, y_pred_new;
  double out; 
  const double eps=1e-15;

  y_pred_new=pmax(predicted,eps);
  temp = log(gamma(actual + 1)) + y_pred_new - log(y_pred_new)*actual;
  out=mean(temp); // using sugar implementation
  return out;
}

spedygiorgio avatar Apr 27 '17 13:04 spedygiorgio

@spedygiorgio Can you open a pull req for this. It would be a great addition. You can also get credit for the work. Let me know Tyler

JackStat avatar Jul 14 '17 19:07 JackStat

@JackStat I hope to pull it tomorrow

spedygiorgio avatar Jul 19 '17 22:07 spedygiorgio