Skip to content

Instantly share code, notes, and snippets.

View predictioniogists's full-sized avatar

PredictionIO predictioniogists

View GitHub Profile
# You need to specify the name of the engine from which you want to retrieve the prediction results.
# Add the following code to display recommended meals to the user after the user has logged in:
begin
# Retrieve top 5 recommended meals from the item recommendation engine.
# Assuming client.identify("user id") is already called when the user logged in.
iids = client.get_itemrec_top_n("the engine name", 5) # list of recommended meal IDs
rescue ItemRecNotFoundError => e
iids = get_default_iids_list(5) # default behavior when there is no prediction result, e.g. recommends newest meals
log_error(e) # log the error for debugging or analysis later
end
require "predictionio"
# In the beginning of your application, you need to instantiate the PredictionIO client object.
# You need this client object to import data into PredictionIO and retrieve prediction results.
# Add this line to the place where you do initialization:
client = PredictionIO::Client.new("your App Key")
# Then add the following lines to your codes which handle the corresponding application logic:
# When a new user registers:
gem install predictionio
import predictionio
# In the beginning of your application, you need to instantiate the PredictionIO client object.
# You need this client object to import data into PredictionIO and retrieve prediction results.
# Add this line to the place where you do initialization:
cient = predictionio.Client("your App Key")
# Then add the following lines to your codes which handle the corresponding application logic:
# When a new user registers:
# 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
# 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
client.record_action_on_item("rate", "rated course ID", { "pio_rate": rating }) # the variable rating stores the rating value (from 1 to 5 )
client.record_action_on_item("conversion", "the enrolled course ID")
client.record_action_on_item("view", "the viewed course ID")
client.identify("the logged-in user ID")