Python was installed successfully. I went through the tutorial posted on the assignment page and managed to get all the starter programs right.
Euclidean Distance
Then I got to the recommendations file which happened to work. However, once I tried to add the snippet to the recommendations file, I couldn't get it to work. I kept getting an indentation error. Finally i got the answer by using the correct indentations per line.
Pearson Correlation
The code gave me a very difficult time during this section. Once i noticed that the snippet 'from math import sqrt' was missing, I was able to get an answer equal to the textbook.
Manhattan Distance
After many attempts at ensuring that each code had the proper indentation, i finally sought the blog of a more experienced classmate. Thank you James Gallagher.
The code I used was
#returns a distance-based similarity score for person1 and person2def man_distance(prefs,person1,person2): # Get the list of shared_items si={} for item in prefs[person1]: if item in prefs[person2]: si[item]=1
# if they have no ratings in common, return 0 if len(si)==0:return 0
# Add up the squares of all the differences ManDistance = [ abs(prefs[person1][item] - prefs[person2][item]) for item in si ]
return (1/(1+sum(ManDistance)))
This produced an answer of 0.18181818181818182.
I have come to understand that Python is a great tool for people that aren't programmers to utilize. However I don't think I will be a programmer myself.
Sunday, January 25, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment