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

qualityMeasures.Recall 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;
import cf4j.utils.Methods;

/**
 * 

This class calculates the Recall of the recommender system. It is calculate as * follows:

* *

recall = <relevant recommended items> / <number of relevant items>

* *

This class puts the "Recall" key at the Kernel map containing a double with the * recall value.

* * @author Fernando Ortega */ public class Recall extends QualityMeasure { private final static String NAME = "Recall"; /** * Number of recommended items */ private int numberOfRecommendations; /** * Relevant rating threshold */ private double relevantThreshold; /** * Constructor of Recall * @param numberOfRecommendations Number of recommendations * @param relevantThreshold Minimum rating to consider a rating as relevant */ public Recall (int numberOfRecommendations, double relevantThreshold) { super(NAME); this.numberOfRecommendations = numberOfRecommendations; this.relevantThreshold = relevantThreshold; } @Override public double getMeasure (TestUser testUser) { // Items rated as relevant (in test) by the active user int relevant = 0; for (double rating : testUser.getTestRatings()) { if (rating >= this.relevantThreshold) { relevant++; } } // Items that has been recommended and was relevant to the active user double [] predictions = testUser.getPredictions(); int [] recommendations = Methods.findTopN(predictions, this.numberOfRecommendations); int recommendedAndRelevant = 0; for (int testItemIndex : recommendations) { if (testItemIndex == -1) break; if (testUser.getTestRatings()[testItemIndex] >= this.relevantThreshold) { recommendedAndRelevant++; } } double recall = (double) recommendedAndRelevant / (double) relevant; return recall; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy