/* Evaluate precision and recall with no-preference-worthy Boolean * data * */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 Project \\examples\\ua.base")); Recommenderirstatsevaluator evaluator = new Genericrecommenderirstatsevaluator (); Recommenderbuilder recommenderbuilder= New Recommenderbuilder () {@Overridepublic recommender buildrecommender ( Datamodel model) throws Tasteexception {//TODO auto-generated method stubusersimilarity similarity = new Loglikelihoodsim Ilarity (model); Userneighborhood neighborhood = new Nearestnuserneighborhood (ten, similarity, model); return new Genericuserbasedrecommender (model, neighborhood, similarity);};D Atamodelbuilder ModelBuilder = new Datamodelbuilder () {@Overridepublic Datamodel Builddatamodel (fastbyidmap< PreferenceaRray> trainingdata) {//TODO auto-generated method Stubreturn New Genericbooleanprefdatamodel ( Genericbooleanprefdatamodel.todatamap (Trainingdata));}};i Rstatistics stats = evaluator.evaluate (Recommenderbuilder, modelBuilder, model, NULL, 10, Genericrecommenderirstatsevaluator.choose_threshold, 1.0); SYSTEM.OUT.PRINTLN ("The precision of Boolean data evaluation is:" + stats.getprecision ()); System.out.println ("The Recall of Boolean data evaluation is:" + stats.getrecall ());} public static void Main (string[] args) throws Tasteexception, IOException {//TODO auto-generated method Stubgenericboolea Npretest test = new Genericbooleanpretest ();}}
Results
Mahout using Boolean data to evaluate precision and recall