Mahout recommendation 3-Evaluation of precision and recall rate

Source: Internet
Author: User
Tags file info

It is not absolutely necessary to generate recommendation results by estimating preference values. Providing a recommended list from superior to inferior is sufficient for many scenarios without having to include the estimated preference value.

Precision: Ratio of the relevant results in the top results

Full query rate: Percentage of all relevant results included in the top results

Test the previous example:

Package mahout; 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 irstatsevalutator {public static void main (string [] ARGs) throws exception {randomutils. usetestseed (); datamodel = new filedatamodel (new file ("Data/intro.csv"); recommenderirstatsevaluator evaluator = new generator (); // builder used to generate recommendation engine, same as the previous example, recommenderbuilder builder = new recommenderbuilder () {public recommender buildrecommender (datamodel model) throws tasteexception {// todo auto-generated method stub // user similarity, multiple methods: usersimilarity similarity = new pearsoncorrelationsimilarity (model); // userneighborhood neighborhood = new neighbor (2, similarity, model); // a recommender return new neighbor (model, model, neighborhood, similarity) ;}}; // estimate the precision and recall ratio of the two recommendation results irstatistics statistics = evaluator. evaluate (builder, null, datamodel, null, 2, genericrecommenderirstatsevaluator. choose_threshold, 1.0); system. out. println ("precision:" + statistics. getprecision (); system. out. println ("query full rate:" + statistics. getrecall ());}}

Output result:

14/08/04 09:46:21 info file. filedatamodel: Creating filedatamodel for file data \ intro.csv 14/08/04 09:46:21 info file. filedatamodel: Reading file info... 14/08/04 09:46:21 info file. filedatamodel: read lines: 2114/08/04 09:46:21 info model. genericdatamodel: processed 5 users14/08/04 09:46:21 info model. genericdatamodel: processed 5 users14/08/04 09:46:21 info model. genericdatamodel: processed 5 users14/08/04 09:46:21 info eval. genericrecommenderirstatsevaluator: evaluated with user 2 in 31ms14/08/04 09:46:21 info eval. genericrecommenderirstatsevaluator: Precision/recall/fall-out/ndcg/Reach: 1.0/1.0/0.0/1.0/1.014 09:46:21 info model. genericdatamodel: processed 5 users14/08/04 09:46:21 info eval. genericrecommenderirstatsevaluator: evaluated with user 4 in 0ms14/08/04 09:46:21 info eval. genericrecommenderirstatsevaluator: Precision/recall/fall-out/ndcg/Reach: 0.75/1.0/0.08333333333333333/1.0/1.0 precision: 0.75 recall: 1.0

File Description: see mahout in action.

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.