Skip to content

Instantly share code, notes, and snippets.

View predictioniogists's full-sized avatar

PredictionIO predictioniogists

View GitHub Profile
$ pip install predictionio
Or
$ easy_install predictionio
client.create_item("the new course ID", ("course category 1",))
import predictionio
# add this line to where initialization is done
client = predictionio.Client("your App Key")
client.create_user("the new user ID")
client.identify("the logged-in user ID")
client.record_action_on_item("view", "the viewed course ID")
client.record_action_on_item("conversion", "the enrolled course ID")
client.record_action_on_item("rate", "rated course ID", { "pio_rate": rating }) # the variable rating stores the rating value (from 1 to 5 )
# You need to specify the name of the engine from which you want to retrieve the prediction results.
# When any user views a course, you can suggest similar courses to the user by adding the following:
try:
# retreive top 5 similar courses from the item similarity engine
result = client.get_itemsim_topn("the engine name", "the viewed course ID", 5)
iids = result['pio_iids'] # list of recommended course IDs
except Exception as e:
iids = get_default_iids_list(5) # default behavior when no prediction results. eg. recommends latest courses
log_error(e) # log the error for debugging or analysis later
# You need to specify the name of the engine from which you want to retrieve the prediction results.
# Add the following code to display the recommended courses to the user after the user has logged in:
try:
# Retrieve top 5 recommnded courses from the item recommendation engine.
# Assuming client.identify("user id") is already called when the user logged in.
result = client.get_itemrec_topn("the engine name", 5)
iids = result['pio_iids'] # list of recommended course IDs
except Exception as e:
iids = get_default_iids_list(5) # default behavior when no prediction results. eg. recommends latest courses