Mahout using Boolean data to evaluate precision and recall

Source: Internet
Author: User

/* 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.