Evaluation of similarity recommendation algorithm based on Euclidean distance Definition
/** This program evaluates the similarity defined 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 setting {public GenericRecByGroupLens_Evalu () throws Exception {DataModel model = new GroupLensDataModel (new File ("E :\\ mahout project \ examples \ ratings. dat "); RecommenderEvaluator evaluator = new evaluate (); 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 UserSimilarity similarity1 = new EuclideanDistanceSimilarity (model); UserNeighborhood neighborhood = new feature (100, similarity1, model) is used here ); return new GenericUserBasedRecommender (model, neighborhood, similarity1) ;}; double score = evaluator. evaluate (recommenderBuilder, null, model, 0.95, 0.05); System. out. println ("the recommendation engine evaluation score based on the similarity defined by Euclidean distance is:" + score);} public static void main (String [] args) throws Exception {// TODO Auto-generated method stubGenericRecByGroupLens_Evalu eva = new GenericRecByGroupLens_Evalu ();}}
Here is the Pearson algorithm-based evaluation:
This is an evaluation based on the similarity defined by Euclidean distance:
We can see that the European algorithm is better than Pearson's recommendation algorithm.