Data digging and the chord of acquaintance

Source: Internet
Author: User

# coding:utf-8__author__ = ' HDFs ' from math import sqrtusers = {"Angelica": {"Blues Traveler": 3.5, "Broken Bells": 2.0 , "Norah Jones": 4.5, "Phoenix": 5.0, "slightly stoopid": 1.5, "the Strokes": 2.5, "vampir E Weekend ": 2.0}," Hailey ": {" Broken Bells ": 4.0," Deadmau5 ": 1.0," Norah Jones ": 4.0," The Strokes ": 4.0," Vampire Wee Kend ": 1.0}," Jordyn ": {" Broken Bells ": 4.5," Deadmau5 ": 4.0," Norah Jones ": 5.0," Phoenix ": 5.0," slightly stoopid ": 4 .5, "The Strokes": 4.0, "Vampire Weekend": 4.0}, "Sam": {"Blues Traveler": 5.0, "Broken Bells": 2.0, "Nor  Ah Jones ": 3.0," Phoenix ": 5.0," slightly stoopid ": 4.0," The Strokes ": 5.0}," Veronica ": {" Blues Traveler ": 3.0, "Norah Jones": 5.0, "Phoenix": 4.0, "slightly stoopid": 2.5, "The Strokes": 3.0}}def coscoefficient (Rating1, Rating2 ): "Cosine acquaintance degree:p Aram Rating1::p Aram Rating2:: Return: ' Xleng, Yleng = 0, 0 for Ratval01key, R Atval01 in Rating1.items(): Xleng = Xleng + ratval01 * ratval01 for Ratval02key, ratval02 in Rating2.items (): Yleng = Yleng + rat VAL02 * Ratval02 Neiji = 0 for Key1 in Rating1.keys (): If Key1 in Rating2.keys (): Neiji = Neiji +    RATING1[KEY1] * Rating2[key1] result = Neiji/(sqrt (Xleng) * sqrt (Yleng)) return resultif __name__ = = "__main__": Print (Coscoefficient (users[' Angelica '), users[' Veronica '])

  

Data digging and the chord of acquaintance

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.