Similarity Calculation Based on grain Coefficient
// This program ignores the preference value and calculates the similarity based on the grain coefficient. // This algorithm is based on the grain coefficient. // This value is also called the Jaccard coefficient, the number of preferences expressed by two users is divided by at least // The number of preferences expressed by one user (that is, the intersection of the two is divided by the union of the two) 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. 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. cachingUserSimilarity; import org. apache. mahout. cf. taste. impl. similarity. pearsonCorrelationSimilarity; import org. apache. mahout. cf. taste. impl. similarity. using mancorrelationsimilarity; 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; import org. apache. mahout. math. hadoop. similarity. cooccurrence. measures. tanimotoCoefficientSimilarity; public class failed {public writable () throws IOException, TasteException {DataModel model = new GroupLensDataModel (new File ("E: \ mahout project \ examples \ ratings. dat "); incluevaluator = new evaluate (); RecommenderBuilder recommenderBuilder = new RecommenderBuilder () {@ Overridepublic Recommender buildRecommender (DataModel model) throws TasteException {extends similarity = new org. apache. mahout. cf. taste. impl. similarity. round (model); UserNeighborhood neighborhood = new round (100, similarity, model); return new GenericUserBasedRecommender (model, neighborhood, similarity) ;}}; double score = evaluator. evaluate (recommenderBuilder, null, model, 0.95, 0.05); System. out. println ("the evaluation score of the recommendation engine that uses the grain coefficient to calculate similarity is:" + score);} public static void main (String [] args) throws TasteException, IOException {// TODO Auto-generated method stubTanimotoCoefficientSimilarityTest tt = new TanimotoCoefficientSimilarityTest ();}}
Result: