# 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