All Downloads are FREE. Search and download functionalities are using the official Maven repository.

qualityMeasures.MAE Maven / Gradle / Ivy

Go to download

A Java's Collaborative Filtering library to carry out experiments in research of Collaborative Filtering based Recommender Systems. The library has been designed from researchers to researchers.

The newest version!
package cf4j.qualityMeasures;

import cf4j.TestUser;

/**
 * 

This class calculates the MAE (Mean Absolute Error) of the recommender system. The MAE is the * absolute difference between the user rating and the predicted rating.

* *

This class puts the "MAE" key at the Kernel map containing a double with the MAE value.

* * @author Fernando Ortega */ public class MAE extends QualityMeasure { private final static String NAME = "MAE"; /** * Constructor of MAE */ public MAE () { super(NAME); } @Override public double getMeasure (TestUser testUser) { double [] predictions = testUser.getPredictions(); double [] ratings = testUser.getTestRatings(); double mae = 0d; int count = 0; for (int i = 0; i < ratings.length; i++) { if (!Double.isNaN(predictions[i])) { mae += Math.abs(predictions[i] - ratings[i]); count++; } } return (count == 0) ? Double.NaN : mae / count; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy