Commit 1f165c86 authored by DIVYANSH PAREEK's avatar DIVYANSH PAREEK

Update collab-filter.py for adding Euclidean Stuff

parent 03be5922
...@@ -37,3 +37,20 @@ data.append(userRatings) ...@@ -37,3 +37,20 @@ data.append(userRatings)
file.close() file.close()
userFile.close() userFile.close()
#data is complete at this point #data is complete at this point
# Euclidean Distance Basic Implementation Using for Loop
euclidean = []
rows = len(data)
users = data[rows-1]
cols = len(users)
for x in range(1,rows-1): # does not include (rows-1)
lis = data[x]
summ = 0
for y in range(1,cols):
if(float(lis[y]) != -1 and float(users[y]) != -1):
summ += (float(users[y]) - float(lis[y])) ** 2
summ = summ ** 0.5
euclidean.append((summ,lis[0]))
euclidean.sort()
print(euclidean)
\ No newline at end of file
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