标签:
/*利用无偏好值得布尔型 * 数据评估查准率和查全率 * */ 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.DataModelBuilder; import org.apache.mahout.cf.taste.eval.IRStatistics; import org.apache.mahout.cf.taste.eval.RecommenderBuilder; import org.apache.mahout.cf.taste.eval.RecommenderIRStatsEvaluator; import org.apache.mahout.cf.taste.impl.common.FastByIDMap; import org.apache.mahout.cf.taste.impl.eval.GenericRecommenderIRStatsEvaluator; import org.apache.mahout.cf.taste.impl.model.GenericBooleanPrefDataModel; import org.apache.mahout.cf.taste.impl.model.file.FileDataModel; 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.LogLikelihoodSimilarity; import org.apache.mahout.cf.taste.model.DataModel; import org.apache.mahout.cf.taste.model.PreferenceArray; import org.apache.mahout.cf.taste.neighborhood.UserNeighborhood; import org.apache.mahout.cf.taste.recommender.Recommender; import org.apache.mahout.cf.taste.similarity.UserSimilarity; public class GenericBooleanPreTest { public GenericBooleanPreTest() throws TasteException, IOException{ DataModel model = new GenericBooleanPrefDataModel(new FileDataModel(new File("E:\\mahout项目\\examples\\ua.base"))); RecommenderIRStatsEvaluator evaluator = new GenericRecommenderIRStatsEvaluator(); RecommenderBuilder recommenderBuilder= new RecommenderBuilder() { @Override public Recommender buildRecommender(DataModel model) throws TasteException { // TODO Auto-generated method stub UserSimilarity similarity = new LogLikelihoodSimilarity(model); UserNeighborhood neighborhood = new NearestNUserNeighborhood(10, similarity, model); return new GenericUserBasedRecommender(model, neighborhood, similarity); } }; DataModelBuilder modelBuilder = new DataModelBuilder() { @Override public DataModel buildDataModel(FastByIDMap<PreferenceArray> trainingData) { // TODO Auto-generated method stub return new GenericBooleanPrefDataModel(GenericBooleanPrefDataModel.toDataMap(trainingData)); } }; IRStatistics stats = evaluator.evaluate(recommenderBuilder, modelBuilder, model, null, 10, GenericRecommenderIRStatsEvaluator.CHOOSE_THRESHOLD, 1.0); System.out.println("布尔型数据评估的查准率是:" + stats.getPrecision()); System.out.println("布尔型数据评估的查全率是:" + stats.getRecall()); } public static void main(String[] args) throws TasteException, IOException { // TODO Auto-generated method stub GenericBooleanPreTest test = new GenericBooleanPreTest(); } }
结果如图:
标签:
原文地址:http://blog.csdn.net/u012965373/article/details/45536871