double relativeError = 0.0;
// calculate the error on test instance
for (double[] testInstance : testInstances) {
DoubleVector instance = new DenseDoubleVector(testInstance);
double expected = instance.get(instance.getDimension() - 1);
instance = instance.slice(instance.getDimension() - 1);
double actual = regression.getOutput(instance).get(0);
if (expected == 0) {
expected = 0.0000001;
}
relativeError += Math.abs((expected - actual) / expected);