org.apache.mahout.cf.taste.similarity.ItemSimilarity Java Examples

The following examples show how to use org.apache.mahout.cf.taste.similarity.ItemSimilarity. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ItembasedRecommender.java    From Building-Recommendation-Engines with MIT License 5 votes vote down vote up
public static void main(String[] args) throws TasteException, IOException {
	DataModel model = new FileDataModel(new File("data/dataset.csv"));
   	ItemSimilarity similarity = new LogLikelihoodSimilarity(model);
   	//UserNeighborhood neighborhood = new ThresholdUserNeighborhood(0.1, similarity, model);
   	GenericItemBasedRecommender recommender = new GenericItemBasedRecommender(model, similarity);
   	List<RecommendedItem> recommendations = recommender.mostSimilarItems(18, 3);
   	for (RecommendedItem recommendation : recommendations) {
   	  System.out.println(recommendation);
   	}

}
 
Example #2
Source File: BookRecommender.java    From Machine-Learning-in-Java with MIT License 5 votes vote down vote up
public static ItemBasedRecommender itemBased() throws Exception {

		// Load the data
		StringItemIdFileDataModel dataModel = loadFromFile("data/BX-Book-Ratings.csv", ";");
		// Collection<GenericItemSimilarity.ItemItemSimilarity> correlations =
		// null;
		// ItemItemSimilarity iis = new ItemItemSimilarity(0, 0, 0);
		// ItemSimilarity itemSimilarity = new
		// GenericItemSimilarity(correlations);
		ItemSimilarity itemSimilarity = new PearsonCorrelationSimilarity(dataModel);

		ItemBasedRecommender recommender = new GenericItemBasedRecommender(
				dataModel, itemSimilarity);

		IDRescorer rescorer = new MyRescorer();

		// List recommendations = recommender.recommend(2, 3, rescorer);
		String itemISBN = "042513976X";
		long itemID = dataModel.readItemIDFromString(itemISBN);
		int noItems = 10;

		System.out.println("Recommendations for item: " + books.get(itemISBN));

		System.out.println("\nMost similar items:");
		List<RecommendedItem> recommendations = recommender.mostSimilarItems(
				itemID, noItems);
		for (RecommendedItem item : recommendations) {
			itemISBN = dataModel.getItemIDAsString(item.getItemID());
			System.out.println("Item: " + books.get(itemISBN) + " | Item id: "
					+ itemISBN + " | Value: " + item.getValue());
		}
		
		return recommender;
	}