Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
package br.com.kamila;
import org.apache.mahout.cf.taste.common.TasteException;
import org.apache.mahout.cf.taste.eval.RecommenderBuilder;
import org.apache.mahout.cf.taste.impl.neighborhood.ThresholdUserNeighborhood;
import org.apache.mahout.cf.taste.impl.recommender.GenericUserBasedRecommender;
import org.apache.mahout.cf.taste.impl.similarity.PearsonCorrelationSimilarity;
import org.apache.mahout.cf.taste.model.DataModel;
import org.apache.mahout.cf.taste.neighborhood.UserNeighborhood;
import org.apache.mahout.cf.taste.recommender.Recommender;
import org.apache.mahout.cf.taste.recommender.UserBasedRecommender;
import org.apache.mahout.cf.taste.similarity.UserSimilarity;
//aqui connstruimos nosso recomendador
public class RecomendadorBuilder implements RecommenderBuilder {
public Recommender buildRecommender(DataModel model) throws TasteException {
//ele irá se basear na similaridade entre os usuários para contruir recomendações.
UserSimilarity similarity = new PearsonCorrelationSimilarity(model);
//pega a maior similaridade (vizinhança) entre os usuários do nosso modelo
UserNeighborhood neighborhood = new ThresholdUserNeighborhood(0.1, similarity, model);
//fazemos nossa recomendação baseada no usuário, que é retornada no recommender
UserBasedRecommender recommender = new GenericUserBasedRecommender(model, neighborhood, similarity);
return recommender;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment