标签:
//基于对数似然比更好的计算相似度(量用户) //所谓对数似然比为选取两个用户进行比较的时后进行筛选 //相似性为可以解释为发生重叠为发生重叠的非偶然概率 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(); } }
如图:
标签:
原文地址:http://blog.csdn.net/u012965373/article/details/46051641