码迷,mamicode.com
首页 > 其他好文 > 详细

Mahout基于对数似然比更好的计算相似度

时间:2015-05-27 21:08:44      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:

//基于对数似然比更好的计算相似度(量用户)
//所谓对数似然比为选取两个用户进行比较的时后进行筛选
//相似性为可以解释为发生重叠为发生重叠的非偶然概率

package byuser;

import java.io.File;
import java.io.IOException;

import org.apache.mahout.cf.taste.common.TasteException;
import org.apache.mahout.cf.taste.eval.RecommenderBuilder;
import org.apache.mahout.cf.taste.eval.RecommenderEvaluator;
import org.apache.mahout.cf.taste.impl.eval.AverageAbsoluteDifferenceRecommenderEvaluator;
import org.apache.mahout.cf.taste.impl.neighborhood.NearestNUserNeighborhood;
import org.apache.mahout.cf.taste.impl.recommender.GenericUserBasedRecommender;
import org.apache.mahout.cf.taste.impl.similarity.CachingUserSimilarity;
import org.apache.mahout.cf.taste.impl.similarity.LogLikelihoodSimilarity;
import org.apache.mahout.cf.taste.model.DataModel;
import org.apache.mahout.cf.taste.neighborhood.UserNeighborhood;
import org.apache.mahout.cf.taste.recommender.Recommender;
import org.apache.mahout.cf.taste.similarity.UserSimilarity;
import org.apache.mahout.cf.taste.similarity.precompute.example.GroupLensDataModel;

public class LogLikelihoodSimailarirtyTest {
	DataModel model;
	public LogLikelihoodSimailarirtyTest() throws IOException, TasteException{
		DataModel model = new GroupLensDataModel(new File("E:\\mahout项目\\examples\\ratings.dat"));
		RecommenderEvaluator evaluator = new AverageAbsoluteDifferenceRecommenderEvaluator();
		RecommenderBuilder recommenderBuilder = new RecommenderBuilder() {
			@Override
			public Recommender buildRecommender(DataModel model) throws TasteException {
				UserSimilarity similarity = new CachingUserSimilarity(new LogLikelihoodSimilarity(model), model);
				UserNeighborhood neighborhood = new NearestNUserNeighborhood(100, similarity, model);
				return new GenericUserBasedRecommender(model, neighborhood, similarity);
			}
		};
		double score = evaluator.evaluate(recommenderBuilder, null, model, 0.95, 0.05);
		System.out.println("采用对数似然比的推荐引擎的评测得分是: " + score);
	}
	public static void main(String[] args) throws IOException, TasteException {
		// TODO Auto-generated method stub
		LogLikelihoodSimailarirtyTest ls = new LogLikelihoodSimailarirtyTest();
	}

}


如图:


技术分享

Mahout基于对数似然比更好的计算相似度

标签:

原文地址:http://blog.csdn.net/u012965373/article/details/46051641

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!