Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- oceniPoKorisnici={
- 'Lisa Rose': {'Catch Me If You Can': 3.0 , 'Snakes on a Plane': 3.5, 'Superman Returns': 3.5, 'You, Me and Dupree': 2.5, 'The Night Listener': 3.0, 'Snitch': 3.0},
- 'Gene Seymour': {'Lady in the Water': 3.0, 'Snakes on a Plane': 3.5, 'Just My Luck': 1.5, 'The Night Listener': 3.0,'You, Me and Dupree': 3.5},
- 'Michael Phillips': {'Catch Me If You Can': 2.5, 'Lady in the Water': 2.5,'Superman Returns': 3.5, 'The Night Listener': 4.0, 'Snitch': 2.0},
- 'Claudia Puig': {'Snakes on a Plane': 3.5, 'Just My Luck': 3.0,'The Night Listener': 4.5, 'Superman Returns': 4.0,'You, Me and Dupree': 2.5},
- 'Mick LaSalle': {'Lady in the Water': 3.0, 'Snakes on a Plane': 4.0,'Just My Luck': 2.0, 'Superman Returns': 3.0, 'You, Me and Dupree': 2.0},
- 'Jack Matthews': {'Catch Me If You Can': 4.5, 'Lady in the Water': 3.0, 'Snakes on a Plane': 4.0,'The Night Listener': 3.0, 'Superman Returns': 5.0, 'You, Me and Dupree': 3.5, 'Snitch': 4.5},
- 'Toby': {'Snakes on a Plane':4.5, 'Snitch': 5.0},
- 'Michelle Nichols': {'Just My Luck' : 1.0, 'The Night Listener': 4.5, 'You, Me and Dupree': 3.5, 'Catch Me If You Can': 2.5, 'Snakes on a Plane': 3.0},
- 'Gary Coleman': {'Lady in the Water': 1.0, 'Catch Me If You Can': 1.5, 'Superman Returns': 1.5, 'You, Me and Dupree': 2.0},
- 'Larry': {'Lady in the Water': 3.0, 'Just My Luck': 3.5, 'Snitch': 1.5, 'The Night Listener': 3.5}
- }
- def sim_distance(oceni,person1,person2):
- zaednicki = {}
- zaedn = 0
- for film in oceni[person1].keys():
- if film in oceni[person2]:
- zaednicki[film] = 1
- zaedn+=1
- if len(zaednicki) == 0:
- return 0
- zbirKvadrati = 0;
- for film in zaednicki.keys():
- zbirKvadrati += (oceni[person1][film] - oceni[person2][film])**2
- slicnost = round(1/(1 + math.sqrt(zbirKvadrati)),3)
- return slicnost
- def sim_pearson(oceni,person1,person2):
- zaednicki = {}
- zaedn = 0
- for film in oceni[person1].keys():
- if film in oceni[person2]:
- zaednicki[film] = 1
- zaedn+=1
- if len(zaednicki) == 0:
- return 0
- sumaOceni1 = 0
- sumaOceni2 = 0
- sumaOceniKv1 = 0
- sumaOceniKv2 = 0
- sumaZaednPr = 0
- for film in zaednicki.keys():
- ocena1 = oceni[person1][film]
- ocena2 = oceni[person2][film]
- sumaOceni1 += ocena1
- sumaOceni2 += ocena2
- sumaOceniKv1 += ocena1**2
- sumaOceniKv2 += ocena2**2
- sumaZaednPr += ocena1 * ocena2
- broitel = zaedn * sumaZaednPr - sumaOceni1 * sumaOceni2
- imenitel = math.sqrt(zaedn * sumaOceniKv1 - (sumaOceni1**2)) * math.sqrt(zaedn * sumaOceniKv2 - sumaOceni2**2)
- if imenitel==0:
- if broitel>0:
- return 1
- elif broitel<0:
- return -1
- else:
- return -2
- formula = broitel / imenitel
- f = round(formula,3)
- return f,zaedn
- korisnik1 = input()
- korisnik2 = input()
- # korisnik1='Mick LaSalle'
- # korisnik2='Lisa Rose'
- print '({},'.format(sim_distance(oceniPoKorisnici,korisnik1, korisnik2)),
- print '{}, {})'.format(*sim_pearson(oceniPoKorisnici, korisnik1, korisnik2)),
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement