Examples

By using the Movie Lens dataset, you can find additional movie recommendations. For example, if you enjoy the movie “The Terminator”, and you want to get a list of other similar movies, you would do this.

You can download this dataset and try out this example by downloading the Movie Lens' Dataset here.

1. Upload Data Set

This will return to you a datasource_id_seq number. This is the ID of the file you have just uploaded. This ID will be used on the subsequent API calls.

curl -i -X POST 'https://algorithms.p.mashape.com/dataset' \
  -H 'X-Mashape-Authorization: <YOUR AUTHORIZATION TOKEN FROM MASHAPE>'  \
  -F theFile=@Movie_Lens_10k_data.csv

The returned result is:

[
  {
    "api": {
      "Authentication": "Success"
    },
    "data": 3298
  }
]


2.  Convert Data File to Proper Format

This algorithm takes input in a specific numeric format and cannot take anything that is in a string format.  Running this prepare call will convert your csv file into the format this algorithms needs.  It is expecting that the first row a header row.  You have to inform the call which column is the "user" column, "item" column, and the "preference" column.  This might take some a while depending on your dataset size. 

From the Mashape web GUI, there is a button next to this call to generate this cURL command.    

curl -i -X POST 'https://algorithms.p.mashape.com/jobs/run/29' \
  -H 'X-Mashape-Authorization: <YOUR AUTHORIZATION TOKEN FROM MASHAPE>' \
  -d 'outputType=json' \
  -d 'method=sync' \
  -d 'datasources=[3298]' \
  -d 'field_user_id=user' \
  -d 'field_item_id=item' \
  -d 'field_preference=pref'

The returned result is:

{"outcome":"Success","TotalRows":14696}
  


3.  Run Recommendation

Now you can run the algorithm and generate a recommendation.  

The example below shows how to get a recommendation for a movie similar to the classic Terminator movie. 

curl -i -X POST 'https://algorithms.p.mashape.com/jobs/run/14' \
  -H 'X-Mashape-Authorization: <YOUR AUTHORIZATION TOKEN FROM MASHAPE>' \
  -d 'outputType=json' \
  -d 'method=sync' \
  -d 'datasources=[3298]' \
  -d 'type=item' \
  -d 'item=Terminator The 1984'

The returned result is:

[
    {"output":{
        "api":{
            "Authentication":"Success"
            },
        "data":{
            "recommendation":[
        {"id":"Sudden Death 1995","value":"0.95996654"},
        {"id":"Sword in the Stone The 1963","value":"0.9511138"},
        {"id":"Empire Strikes Back The 1980","value":"0.95010316"},
        {"id":"Die Hard 2 1990","value":"0.945785"},
        {"id":"Clear and Present Danger 1994","value":"0.9444163"},
        {"id":"Return of the Jedi 1983","value":"0.9439957"},
        {"id":"Blade Runner 1982","value":"0.9425006"},
        {"id":"Island of Dr. Moreau The 1996","value":"0.9395942"},
        {"id":"Fugitive The 1993","value":"0.9383732"},
        {"id":"Waterworld 1995","value":"0.93799603"},
        {"id":"Interview with the Vampire 1994","value":"0.93409985"},
        {"id":"Raiders of the Lost Ark 1981","value":"0.93382645"},
        {"id":"Timecop 1994","value":"0.9330071"}]
    }}}]