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

knn.userToUser.aggregationApproaches.Mean 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.knn.userToUser.aggregationApproaches;

import cf4j.Kernel;
import cf4j.TestUser;
import cf4j.TestUsersPartible;
import cf4j.User;

/**
 * 

This class computes the prediction of the test users' test items. The results are * saved in double array on the hashmap of each test user with the key "predictions". This * array overlaps with the test items' array of the test users. For example, the prediction * retrieved with the method testUser.getPredictions()[i] is the prediction of the item * testUser.getTestItems()[i].

* *

This class uses standard average as method to combine the test user neighbors' ratings.

* * @author Fernando Ortega */ public class Mean implements TestUsersPartible { @Override public void beforeRun() { } @Override public void run (int testUserIndex) { TestUser testUser = Kernel.gi().getTestUsers()[testUserIndex]; int [] neighbors = testUser.getNeighbors(); int numRatings = testUser.getNumberOfTestRatings(); double [] predictions = new double [numRatings]; for (int testItemIndex = 0; testItemIndex < numRatings; testItemIndex++) { int itemCode = testUser.getTestItems()[testItemIndex]; int count = 0; for (int n = 0; n




© 2015 - 2024 Weber Informatics LLC | Privacy Policy