Java Code Examples for org.apache.mahout.cf.taste.impl.model.file.FileDataModel

The following examples show how to use org.apache.mahout.cf.taste.impl.model.file.FileDataModel. These examples are extracted from open source projects. 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 Project: hiped2   Source File: MovieUserRecommender.java    License: Apache License 2.0 6 votes vote down vote up
private static void recommend(String ratingsFile, int ... userIds)
    throws TasteException, IOException {
  DataModel model = new FileDataModel(new File(ratingsFile));

  UserSimilarity similarity = new PearsonCorrelationSimilarity(model);

  UserNeighborhood neighborhood =
      new NearestNUserNeighborhood(
          100, similarity, model);

  Recommender recommender =  new GenericUserBasedRecommender(
      model, neighborhood, similarity);

  Recommender cachingRecommender = new CachingRecommender(recommender);

  for(int userId: userIds) {
    System.out.println("UserID " + userId);
    List<RecommendedItem> recommendations =
        cachingRecommender.recommend(userId, 2);
    for(RecommendedItem item: recommendations) {
      System.out.println("  item " + item.getItemID() + " score " + item.getValue());
    }
  }
}
 
Example 2
public static void main( String[] args ) throws IOException, TasteException
{
	//user based recommender model
	DataModel model = new FileDataModel(new File("data/dataset.csv"));    	
	UserSimilarity similarity = new PearsonCorrelationSimilarity(model);
	UserNeighborhood neighborhood = new ThresholdUserNeighborhood(0.1, similarity, model);
	UserBasedRecommender recommender = new GenericUserBasedRecommender(model, neighborhood, similarity);
	List<RecommendedItem> recommendations = recommender.recommend(2, 3);
	for (RecommendedItem recommendation : recommendations) {
	  System.out.println(recommendation);
	}
}
 
Example 3
public static void main(String[] args) throws TasteException, IOException {
	//MF recommender model
   	DataModel model = new FileDataModel(new File("data/recodataset.csv"));   
   	//ALSWRFactorizer factorizer = new ALSWRFactorizer(model, 50, 0.065, 15);
   	ParallelSGDFactorizer factorizer = new ParallelSGDFactorizer(model,10,0.1,1);
   	SVDRecommender recommender = new SVDRecommender(model, factorizer);    	
   	
   	List<RecommendedItem> recommendations = recommender.recommend(2, 3);
   	for (RecommendedItem recommendation : recommendations) {
   	  System.out.println(recommendation);
   	}

}
 
Example 4
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 5
Source Project: Machine-Learning-in-Java   Source File: BookRecommender.java    License: MIT License 5 votes vote down vote up
public static DataModel loadFromFile(String filePath) throws IOException{
	// File-based DataModel - FileDataModel
	DataModel dataModel = new FileDataModel(new File("preferences.csv"));
	return dataModel;

}
 
Example 6
Source Project: hiped2   Source File: MovieUserEvaluator.java    License: Apache License 2.0 5 votes vote down vote up
public static void evaluate(String ratingsFile)
    throws TasteException, IOException {
  DataModel model = new FileDataModel(new File(ratingsFile));
  RecommenderEvaluator evaluator =
      new AverageAbsoluteDifferenceRecommenderEvaluator();
  RecommenderBuilder recommenderBuilder = new MyRecommendBuilder();
  evaluator.evaluate(
      recommenderBuilder,
      null,
      model,
      0.95,
      0.05
  );
}
 
Example 7
public static void main(String[] args) throws IOException {
	DataModel model = new FileDataModel(new File("data/dataset.csv"));  
	Recommender recommender = (Recommender) new SlopeOneRecommender();

}
 
Example 8
Source Project: rival   Source File: MahoutRecommenderRunner.java    License: Apache License 2.0 3 votes vote down vote up
/**
 * Runs the recommender using models from file.
 *
 * @param opts see
 * {@link net.recommenders.rival.recommend.frameworks.AbstractRunner.RUN_OPTIONS}
 * @return see
 * {@link #runMahoutRecommender(net.recommenders.rival.recommend.frameworks.AbstractRunner.RUN_OPTIONS, org.apache.mahout.cf.taste.model.DataModel, org.apache.mahout.cf.taste.model.DataModel)}
 *
 * @throws RecommenderException when the recommender is instantiated
 * incorrectly.
 * @throws IOException when paths in property object are incorrect..
 * @throws TasteException when the recommender is instantiated incorrectly
 * or breaks otherwise.
 */
@Override
public TemporalDataModelIF<Long, Long> run(final RUN_OPTIONS opts) throws RecommenderException, TasteException, IOException {
    if (isAlreadyRecommended()) {
        return null;
    }
    DataModel trainingModel = new FileDataModel(new File(getProperties().getProperty(RecommendationRunner.TRAINING_SET)));
    DataModel testModel = new FileDataModel(new File(getProperties().getProperty(RecommendationRunner.TEST_SET)));
    return runMahoutRecommender(opts, trainingModel, testModel);
}