class EvaluationUtil implements Serializable {

    public static RegressionMetricsSummary getRegressionStatistics(Iterable<Row> rows) {
        RegressionMetricsSummary regressionSummary = new RegressionMetricsSummary();
        for (Row row : rows) {
            if (checkRowFieldNotNull(row)) {
                double yVal = ((Number)row.getField(0)).doubleValue();
                double predictVal = ((Number)row.getField(1)).doubleValue();
                double diff = Math.abs(yVal - predictVal);
                regressionSummary.ySumLocal += yVal;
                regressionSummary.ySum2Local += yVal * yVal;
                regressionSummary.predSumLocal += predictVal;
                regressionSummary.predSum2Local += predictVal * predictVal;
                regressionSummary.maeLocal += diff;
                regressionSummary.sseLocal += diff * diff;
                regressionSummary.mapeLocal += Math.abs(diff / yVal);
                regressionSummary.total++;
            }
        }
        return regressionSummary.total == 0 ? null : regressionSummary;
    }

}