/* * This program evaluates the similarity based on Euclidean distance * */package Byuser;import java.io.file;import Org.apache.mahout.cf.taste.common.tasteexception;import Org.apache.mahout.cf.taste.eval.RecommenderBuilder; Import Org.apache.mahout.cf.taste.eval.recommenderevaluator;import Org.apache.mahout.cf.taste.impl.eval.averageabsolutedifferencerecommenderevaluator;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.euclideandistancesimilarity;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.cf.taste.similarity.precompute.example.grouplensdatamodel;public class GenericRecByGroupLens_ Evalu {PUblic Genericrecbygrouplens_evalu () throws Exception{datamodel model = new Grouplensdatamodel (New File ("E:\\mahout project \ \ Examples\\ratings.dat ")); Recommenderevaluator evaluator = new Averageabsolutedifferencerecommenderevaluator (); Recommenderbuilder Recommenderbuilder = new Recommenderbuilder () {@Overridepublic recommender buildrecommender ( Datamodel model) throws Tasteexception {//pearsoncoreconrrelationsimilarity is the Pearson correlation coefficient algorithm using usersimilarity similarity = New pearsoncorrelationsimilarity (model);//The algorithm used here is based on the Euclidean distance definition similarity usersimilarity similarity1 = new Euclideandistancesimilarity (model); Userneighborhood neighborhood = new Nearestnuserneighborhood (+, similarity1, model); return new Genericuserbasedrecommender (model, neighborhood, similarity1);}; Double score = evaluator.evaluate (Recommenderbuilder, NULL, model, 0.95, 0.05); SYSTEM.OUT.PRINTLN ("The evaluation score for the recommendation engine based on the Euclidean distance definition similarity is:" + score);} public static void Main (string[] args) throws Exception {//TODO auto-generated method Stubgenericrecbygrouplens_evalU eva = new Genericrecbygrouplens_evalu ();}}
Here is an evaluation based on the Pearson algorithm:
This is based on the Euclidean distance definition similarity assessment:
It can be seen that the European algorithm is more superior to Pearson's recommendation algorithm
Evaluation of similarity recommendation algorithm based on Euclidean distance definition