Mahout the configuration and operation of precision and recall evaluation

Source: Internet
Author: User

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

Related Article

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.