You need to sign in or sign up before continuing.
Commit 79c080af authored by RISHABH GARG's avatar RISHABH GARG

Euclidean Distance

parent 59e137ab
import csv import csv
from math import sqrt
csvfile=open('movie-ratings.csv') csvfile=open('movie-ratings.csv')
read=csv.reader(csvfile) read=csv.reader(csvfile)
reading=[] reading=[]
for line in read: for line in read:
reading.append(line) reading.append(line)
#########################
f2 = open ("user_preference.csv") f2 = open ("user_preference.csv")
data = csv.reader(f2) user_data = csv.reader(f2)
preference = [] preference = []
a=input("Your name :") preference.append(input("Your name :"))
preference.append(a) for line in user_data:
for line in data:
preference.append(line) preference.append(line)
prefdict = dict( zip(preference[1],preference[2])) prefdict = dict( zip(preference[1],preference[2]))
print(prefdict) ####################
\ No newline at end of file # print(reading[1][6])
header = reading[0]
del reading[0]
reviewers = [ s[0] for s in reading]
reviewdic = []
for line in reading:
dic = dict( (header[i],line[i]) for i in range(1,len(line)))
reviewdic.append(dic)
dist=[]
# print(reviewdic)
for i in reviewdic:
sum=0
for j in prefdict.keys():
if(i[j] != -1 and prefdict[j] != -1):
sum+=sqrt((float(i[j])-float(prefdict[j]))**2)
dist.append(sum)
# print(len(prefdict))
# for i in reviewdic:
order_dist = sorted(zip(reviewers,dist), key=lambda x: x[1],reverse=True)
The Godfather,Pulp Fiction,The Clockwork Orange,Cinema Paradiso,Wild Strawberries,Amadeus The Godfather,Pulp Fiction,Gone With the Wind,12 Angry Men,Lawrence of Arabia,Raging Bull,The Clockwork Orange,Cinema Paradiso,Wild Strawberries,Amadeus
9,7,6,10,8,10 9,7,6,10,8,10,-1,-1,-1,-1
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment