当前位置: 首页 > 推荐系统 > 正文

Mahout中相似度计算类介绍(八)

1 星2 星3 星4 星5 星 (2 次投票, 评分: 5.00, 总分: 5)
Loading ... Loading ...
baidu_share

类名:GenericItemSimilarity
名称:通用的item Similarity
java例子:

GenericItemSimilarity.ItemItemSimilarity similarity = new GenericItemSimilarity.ItemItemSimilarity(2645769,2389682,31.78/100);
 
		List<GenericItemSimilarity.ItemItemSimilarity> similarities = new ArrayList<GenericItemSimilarity.ItemItemSimilarity>();
		similarities.add(similarity);
		//28.002708
		similarity = new GenericItemSimilarity.ItemItemSimilarity(2645769,2679041, 28.00/100);
		similarities.add(similarity);
		//26.309313
		similarity = new GenericItemSimilarity.ItemItemSimilarity(2645769,2656591, 26.30/100);
		//23.620678
		similarities.add(similarity);
		similarity = new GenericItemSimilarity.ItemItemSimilarity(2645769,2686496, 23.65/100);
		//22.648125
		similarities.add(similarity);
		similarity = new GenericItemSimilarity.ItemItemSimilarity(2645769,1129187, 22.64/100);
		similarities.add(similarity);
		//22.648125
		similarity = new GenericItemSimilarity.ItemItemSimilarity(2645767,2599815, 22.63/100);
		similarities.add(similarity);
		//22.648125
		similarity = new GenericItemSimilarity.ItemItemSimilarity(2645767,2540110, 22.62/100);
		similarities.add(similarity);
 
		similarity = new GenericItemSimilarity.ItemItemSimilarity(2645767,2700438, 22.61/100);
		similarities.add(similarity);
		similarity = new GenericItemSimilarity.ItemItemSimilarity(2645767,2767605, 22.60/100);
		similarities.add(similarity);
		similarity = new GenericItemSimilarity.ItemItemSimilarity(2645767,2529194, 22.54/100);
		similarities.add(similarity);
 
 
		ItemSimilarity itemSimilarity = new GenericItemSimilarity(similarities); 
 
		DataModel model = new FileDataModel(new File("e:\\recommend\\news.txt"));//文件名一定要是绝对路径  
		GenericItemBasedRecommender recommender = new GenericItemBasedRecommender(model,itemSimilarity);
        List<RecommendedItem> recommendations=recommender.recommend(10, 2);
 
        for (RecommendedItem recommendation : recommendations) {
        	System.out.println(recommendation.getItemID());
			System.out.println(recommendation.getValue());
		}

类名:FileItemSimilarity
名称:文件item similarity
该文件形容

itemID1,itemID2,similarity value
1,2,0.88
2,3,0.77

Java例子:

final DataModel dm = new FileDataModel(new File("e:\\recommend\\item.txt"));
final ItemSimilarity similarity = new FileItemSimilarity(new File("e:\\recommend\\item.txt"));
GenericItemBasedRecommender recommender = new GenericItemBasedRecommender(dm,similarity);
	        List<RecommendedItem> recommendations=recommender.mostSimilarItems(329387l, 3);
//329387 为itemID
	        for (RecommendedItem recommendation : recommendations) {
				System.out.println(recommendation.getItemID());
				System.out.println(recommendation.getValue());
		}

类名:TrackItemSimilarity
Java构造函数

  TrackItemSimilarity(File dataFileDirectory) throws IOException {
    trackData = new FastByIDMap<TrackData>();
    for (String line : new FileLineIterable(KDDCupDataModel.getTrackFile(dataFileDirectory))) {
      TrackData trackDatum = new TrackData(line);
      trackData.put(trackDatum.getTrackID(), trackDatum);
    }
  }

类名:HybridSimilarity
基于混合的相似度计算:LogLikelihoodSimilarity*TrackItemSimilarity。
Java构造函数

 HybridSimilarity(DataModel dataModel, File dataFileDirectory) throws IOException {
    super(dataModel);
    cfSimilarity = new LogLikelihoodSimilarity(dataModel);
    contentSimilarity = new TrackItemSimilarity(dataFileDirectory);
  }

类名:CachingItemSimilarity
缓存item similarity 结果

备注:HybridSimilarity和TrackItemSimilarity不能显示使用。

本文固定链接: http://www.chepoo.com/mahout-class-similarity-calculation-described-8.html | IT技术精华网

Mahout中相似度计算类介绍(八):等您坐沙发呢!

发表评论