Similarity Calculation Based on grain Coefficient

Source: Internet
Author: User

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:

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.