我想使用Java构建推荐系统。每当我请求推荐时,它应该为用户提供n个未读项目。我尝试创建基于Mahout用户的推荐。但是,当程序执行完毕后,它只会删除已加载的所有内存。我想在RAM中保留内存。如何将Java程序数据保存到内存中?
我使用下面列出的相同代码:
public static void main(String[] args) throws TasteException, IOException {
DataModel model = new FileDataModel(new File("test.csv"));
UserSimilarity similarity = new PearsonCorrelationSimilarity(model,Weighting.WEIGHTED);
UserNeighborhood neighborhood = new ThresholdUserNeighborhood(0.1, similarity, model);
Recommender recommender = new GenericUserBasedRecommender(model, neighborhood, similarity);
List<RecommendedItem> recs = recommender.recommend(2, 20);
for (RecommendedItem recommendedItem : recs) {
System.out.println(recommendedItem+".");
}
答案 0 :(得分:0)
您应该将推荐对象声明为静态常量。这可能会给出一个想法; https://github.com/mkarakaya/timeAwareItemBasedRecommender/blob/master/app/controllers/Application.java