Thursday, February 12, 2009

Portfolio Assignment 3

So, Last.FM. This assignment proved to be a bit trickier than I had first anticipated. Initially, I was somewhat put off by the complete lack of documentation on the Pylastfm API. It was very sparse, and basically just had rudimentary instructions on how to "install" the module. This by itself gave me trouble, as I was not sure if the file should be put in the "lib" folder or in the general Python folder. The instructions were also designed for a Unix environment, so it took some figuring out for me to get it working. Finally, however, I was in fact able to get it installed in my Python directory, and succesfully connected with Last.FM to do some basic functions.

This is the code we used for this test:
import pylast

print "Welcome to the Team 3 Pylast Recommender!"
print "To find an artist similar to your artist, press (1)"
print "To find a list of top tracks by an artist, press (2)"
print "To find a list of songs similar to a particular song, press (3)"
print "To quit, press (4)"

input = raw_input(">")
print input

if (input=="1"):
print "Please enter the name of an Artist"
similarArtistName = raw_input(">")
similarArtist = pylast.Artist("similarArtistName", "bd46f9bce716e11a6d311d77c06d2159", "a313f7a6a587763c71eeb3cac498ca40", '')
print similarArtist.get_similar()
elif (input=="2"):
print "Please enter the name of an Artist"
trackArtistName = raw_input(">")
trackArtist = pylast.Artist("trackArtistName", "bd46f9bce716e11a6d311d77c06d2159", "a313f7a6a587763c71eeb3cac498ca40", '')
print pylast.Artist.get_top_tracks(trackArtist)


The track recommender did not work, and we were never able to figure out why. (Later on, we discovered that it secretly required an artist as well as track, despite the general API explicitly stating the opposite). At this point, we were able to connect with Will, and as we reviewed our total progress before, we realized that as a group, we had a substantial amount of combined knowledge of PHP, and none of us had any idea of how to implement a GUI in python. We did not want to be limited to a command line-style interface, so we decided that the best couse of action would be to change to a PHP driven website for the Recommender.

Here is a link to the final product we made via PHP:

http://rosemary.umw.edu/~wboyd/datamining/portfolio3/

It was again tricky to implement because the PHP api is different and more involved than the python one, and also because again several of the functions take more paramaters as input than the API would suggest. Still, we feel like it was a great success in implementing a recommender program on a dynamic website, with really cool feature we found in the API for listing the top artists and tracks of the userbase from various countries!

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.