Tuesday, January 20, 2009

Portfolio Assignment 1

One of the problems I did in the book does not seem to work for me. I know it was said in class that some of them might not work 100 percent. When I type:

l1=[1,2,3,4,5,6,7,8,9]
timesten=dict([(v,v*10) for v in l1])


Snippets from pages 7-14:

>>> from math import sqrt
>>> sqrt(pow(4.5-4,2)+pow(1-2,2))
1.1180339887498949

>>> 1/(sqrt(pow(4.5-4,2)+pow(1-2,2)))
0.89442719099991586

>>> recommendations.sim_distance(recommendations.critics, 'Lisa Rose', 'Gene Seymour')
0.29429805508554946

>>> print recommendations.sim_pearson(recommendations.critics, 'Lisa Rose' , 'Gene Seymour')
0.396059017191

>>> recommendations.topMatches(recommendations.critics, 'Toby',n=3)
[(0.99124070716192991, 'Lisa Rose'), (0.92447345164190486, 'Mike LaSalle'), (0.89340514744156474, 'Claudia Puig')]

sim_distance using Manhattan distance:
>>> recommendations.sim_distance(recommendations.critics, 'Lisa Rose','Gene Seymour')
1.5


No comments:

Post a Comment