首页 > 代码库 > mahout学习(一)
mahout学习(一)
mahout主页:http://mahout.apache.org/
mahout maven:
<dependency> <groupId>org.apache.mahout</groupId> <artifactId>mahout-core</artifactId> <version>0.9</version></dependency>
参考:http://mahout.apache.org/users/recommender/userbased-5-minutes.html
例子:
public class TMahout { public static void main(String[] args) throws IOException, TasteException { DataModel model = new FileDataModel(new File("path/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); } RecommenderEvaluator evaluator = new AverageAbsoluteDifferenceRecommenderEvaluator(); RecommenderBuilder builder = new RecommenderBuilder() { @Override public Recommender buildRecommender(DataModel dataModel) throws TasteException { UserSimilarity similarity = new PearsonCorrelationSimilarity(dataModel); UserNeighborhood neighborhood = new ThresholdUserNeighborhood(0.1, similarity, dataModel); return new GenericUserBasedRecommender(dataModel, neighborhood, similarity); } }; double result = evaluator.evaluate(builder, null, model, 0.9, 1.0); System.out.println(result); }}
mahout学习(一)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。