Friday, January 23, 2009

Installing Python and Portfolio Assignment 1

So I just installed amd64 python on my laptop and starting playing around with the command line interface. The examples on the tutorial site seemed to work well, so I was encouraged by that. So far Python seems strange, but not too bad. Syntax is straitforward. The code snippets in the introduction to Collective Intelligence don't work, so that sucks. The code seems simple, so I feel like I should be able to determine what is wrong, but I cant.

if x==1:
print 'x = 1'
print 'Still inside if block'
print 'Outside if block'

Returns a syntax error on the last line. WTF? I'm just printing a statement. Hardly rocket science. Oh well, so far recommendations.py is giving me no trouble. I'm playing with the command line stuff in the book.

After poring over the Euclidean distance calculations in my Python code in search of the error Dr Zacharski alluded to, I finally decided just to do the calculation by hand and see what I come up with. Turns out the answer I got was in fact correct, and the code I copied from the book was also correct. So much time wasted!

Oh Python. Why do you hate me so? So I do not know if I would call it a limitation of the language, because it really seems to be a limitation of the font in the textbook, but my entire Pearson function would not work, despite me having typed it exactly as I saw it in the book. It turns out I indented one of my functions too far, and it was yielding unexpected results. Once I fixed that, it worked fine.

Since the first two functions work properly, the Ranking function was simple to implement, as was the Recommender.

Manhattan distance a simple matter of copying the Euclidian distance function and replacing the different, similar formula.

No comments:

Post a Comment