Skip to content

Instantly share code, notes, and snippets.

Created October 5, 2010 14:38
Show Gist options
  • Save anonymous/611661 to your computer and use it in GitHub Desktop.
Save anonymous/611661 to your computer and use it in GitHub Desktop.
public class ItemBasedRecommender {
public static void main(String[] args) throws Exception {
DataModel model = new FileDataModel(new File("model.csv"));
RecommenderBuilder recommenderBuilder = new RecommenderBuilder() {
public Recommender buildRecommender(DataModel model) throws TasteException {
ItemSimilarity similarity = new EuclideanDistanceSimilarity(model);
return new GenericItemBasedRecommender(model, similarity);
}
};
Recommender recommender = recommenderBuilder.buildRecommender(model);
List<RecommendedItem> recomendations = recommender.recommend(1, 5);
for (RecommendedItem recommendedItem : recomendations) {
System.out.println(recommendedItem);
}
RecommenderIRStatsEvaluator statsEvaluator = new GenericRecommenderIRStatsEvaluator();
IRStatistics stats = statsEvaluator.evaluate(recommenderBuilder, null, model, null, 2, GenericRecommenderIRStatsEvaluator.CHOOSE_THRESHOLD, 1.0);
System.out.println(stats.getPrecision());
System.out.println(stats.getRecall());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment