Collective Smart Programming-Recommendation System (2), collective Smart Programming recommendation

Source: Internet
Author: User

Collective Smart Programming-Recommendation System (2), collective Smart Programming recommendation

Step 3: score reviewers

Now that we have a function for comparing two people, we can write a program below to rate each person based on the specified person and find the closest matching result. In this example, we are interested in finding Movie reviewers who are similar to ourselves, so that we know who should adopt their suggestions when selecting a video.

def topMatches(prefs,person,n=5,similarity=sim_pearson):    scores=[(similarity(prefs,person,other),other) for other in prefs if other!=person]    scores.sort()    scores.reverse()    return scores[0:n]

This function uses the list derivation to compare itself with every other user in the dictionary. Returns the first N items of the sorting result.

>>>reload(recommendations)>>> recommendations.topMatches(recommendations.critics,'Toby',n=3)[(0.9912407071619299, 'Lisa Rose'), (0.9244734516419049, 'Mick LaSalle'), (0.8934051474415647, 'Claudia Puig')]

Step 4: Recommended items

We use a weighted evaluation value to score the film. The score of the reviewer forms a ranking. To this end, we must obtain the evaluation results of all other reviewers to obtain the similarity and multiply them by the value given to each video.

def getRecommendations(prefs,person,similarity=sim_pearson):    totals={}    simSums={}    for other in prefs:        if other==person:continue  #do not compare with self        sim=similarity(prefs,person,other)        #ignore the value <=0        if sim<=0 :continue        for item in prefs[other]:            if item not in prefs[person] or prefs[person][item]==0:                  totals.setdefault(item,0)                totals[item]+=prefs[other][item]*sim                simSums.setdefault(item,0)                simSums[item]+=sim        ranking=[(total/simSums[item],item)for item,total in totals.items() ]    ranking.sort()    ranking.reverse()    return ranking

In this way, we can find ourselves that we should watch movies next.

 

Reference: collective Smart Programming

Related Article

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.