AsymmetricLoss extends ARegressionMeasure { @Override public double loss(final List<? extends Double> expected, final List<? extends IRegressionPrediction> predicted) { this.checkConsistency(expected, predicted); List<Double> accuracyList = new ArrayList<>(); for (int i = 0; i < expected.size(); i++) { Double percentageError = 100 * ((expected.get(i) - predicted.get(i).getPrediction()) / expected.get(i)); Double accuracy; if (percentageError <= 0) { accuracy = Math.exp(-Math.log(0.5) * (percentageError / this.dividerOverestimation)); } else { accuracy = Math.exp(Math.log(0.5) * (percentageError / this.dividerUnderestimation)); } accuracyList.add(accuracy); } return 1 - StatisticsUtil.mean(accuracyList); } AsymmetricLoss();  AsymmetricLoss(final double dividerUnderestimation, final double dividerOverestimation); @Override double loss(final List<? extends Double> expected, final List<? extends IRegressionPrediction> predicted);  }
@Test public void lossWithNoError() { List<Double> expected = Arrays.asList(0.1, 0.2, 0.3, 0.4, 0.5); List<IRegressionPrediction> predicted = this.toPredictions(expected); ERulPerformanceMeasure asymmetricLoss = ERulPerformanceMeasure.ASYMMETRIC_LOSS; assertEquals("Loss must be 0.0", 0.0, asymmetricLoss.loss(expected, predicted), 1E-8); }
@Test public void lossWithError() { List<Double> expected = Arrays.asList(10.0, 5.0); List<IRegressionPrediction> predicted = this.toPredictions(Arrays.asList(11.0, 4.0)); ERulPerformanceMeasure asymmetricLoss = ERulPerformanceMeasure.ASYMMETRIC_LOSS; assertEquals("Loss not as expected.", 0.625, asymmetricLoss.loss(expected, predicted), 1E-8); }