Skip to content

Instantly share code, notes, and snippets.

View predictioniogists's full-sized avatar

PredictionIO predictioniogists

View GitHub Profile
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:
gem install predictionio
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:
# 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
# You need to specify the name of the engine from which you want to retrieve the prediction results.
# When a user views a meal, you can suggest similar meals to the user by adding the following:
begin
# retreive top 5 similar courses from the item similarity engine
iids = client.get_itemsim_top_n("the engine name", "the viewed meal ID", 5) # list of recommended meal IDs
rescue ItemSimNotFoundError => e
iids = get_default_iids_list(5) # default behavior when there is no prediction results, e.g. recommends newest meals
log_error(e) # log the error for debugging or analysis later
end
<project ...>
...
<dependencies>
<dependency>
<groupId>io.prediction</groupId>
<artifactId>client</artifactId>
<version>0.6.0</version>
</dependency>
</dependencies>
...
<ivy-module ...>
...
<dependencies>
<dependency org="io.prediction" name="client" rev="0.6.0" />
...
</dependencies>
...
</ivy-module>
import io.prediction.Client;
import io.prediction.UserActionItemRequestBuilder;
import io.prediction.CreateItemRequestBuilder;
// 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 client = new Client("your app key");
// Then add the following lines to your codes which handle the corresponding application logic:
import io.prediction.ItemRecGetTopNRequestBuilder;
// 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 drivers to the logged-in user:
String[] driverIds;
try {
// Retrieve top 5 recommended drivers from the item recommendation engine.
// Assuming client.identify("user id") is already called when the user logged in.
// When a new destination is added:
try {
// sightseeing spot type may be "museums", "landmarks", etc
String[] itypes = {"destinations", "sightseeing", "sightseeing spot type 1", "sightseeing spot type 2"};
client.createItem("destination ID or name", itypes);
} catch (Exception e) {
handleException(e);
}
// When the logged-in user goes to a destination: