/* * Precision and recall evaluation configuration and operation * * */package byuser;import java.io.file;import org.apache.mahout.cf.taste.common.TasteException; 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.eval.genericrecommenderirstatsevaluator;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.pearsoncorrelationsimilarity;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.common.randomutils;public Class recommenderirstatsevaluatortest {PublIC Recommenderirstatsevaluatortest () {try{randomutils.usetestseed ();D Atamodel model = new Filedatamodel (New File ("E:\ \mahout Project \\examples\\intro.csv ")); Recommenderirstatsevaluator evaluator = new Genericrecommenderirstatsevaluator (); Recommenderbuilder Recommenderbuilder = new Recommenderbuilder () {@Overridepublic recommender buildrecommender ( Datamodel model) throws Tasteexception {//TODO auto-generated method stubusersimilarity similarity = new Pearsoncorrelati Onsimilarity (model); Userneighborhood neighborhood = new Nearestnuserneighborhood (2, similarity, model); return new Genericuserbasedrecommender (model, neighborhood, similarity);}};/ /Recommended two data irstatistics stats = evaluator.evaluate (Recommenderbuilder, NULL, model, NULL, 2, Genericrecommenderirstatsevaluator.choose_threshold, 1.0); SYSTEM.OUT.PRINTLN ("Recommended two results of the precision ratio:" + stats.getprecision ()); System.out.println ("Recommended recall of two results:" + stats.getrecall ());} catch (Exception e) {e.printstacktrace ();}} public static void Main (string[] args) {//TODO Auto-generated method Stubrecommenderirstatsevaluatortest test = new Recommenderirstatsevaluatortest ();}}
Results:
Mahout the configuration and operation of precision and recall evaluation