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

model.predictions.FactorizationPrediction 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.model.predictions;

import cf4j.Kernel;
import cf4j.TestUser;
import cf4j.TestUsersPartible;
import cf4j.model.matrixFactorization.FactorizationModel;

/**
 * Compute users predictions using a factorization model
 *
 * @see FactorizationModel
 *
 * @author Fernando Ortega
 */
public class FactorizationPrediction implements TestUsersPartible {

	protected FactorizationModel model;

	public FactorizationPrediction (FactorizationModel model) {
		this.model = model;
	}

	@Override
	public void beforeRun() { }

	@Override
	public void run (int testUserIndex) {
		TestUser user = Kernel.gi().getTestUsers()[testUserIndex];

		double [] predictions = new double [user.getNumberOfTestRatings()];

		for (int i = 0; i < user.getNumberOfTestRatings(); i++) {
			int itemCode = user.getTestItems()[i];
			int itemIndex = Kernel.gi().getItemIndex(itemCode);

			int userIndex = user.getUserIndex();

			predictions[i] = model.getPrediction(userIndex, itemIndex);
		}

		user.setPredictions(predictions);
	}

	@Override
	public void afterRun() { }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy