Skip to content

Instantly share code, notes, and snippets.

View predictioniogists's full-sized avatar

PredictionIO predictioniogists

View GitHub Profile
import io.prediction.ItemSimGetTopNRequestBuilder;
// You need to specify the name of the engine from which you want to retrieve the prediction results.
// Add the following code to display similar sightseeing spots to the user after arriving a destination:
String[] destinationIds;
try {
//retreive top 5 similar sightseeing spots from the item similarity engine
String[] itypes = {"sightseeing"}
<?php
// Assuming we already have an ItemSim engine named 'similarapps'
// Get a list of previous viewed app IDs for the current session
$previouslyViewedApps = getViewedAppsInThisSession();
$similarApps = array();
try {
// Retrieve similar apps for each previously viewed app
<?php
// Assuming we already have an ItemRec engine named 'appsrec'
// Get user ID and the current view's category
$uid = getUid();
$category = getCategory();
try {
// Retrieve apps recommendation for the current user and category
<?php
// Assuming we already have an ItemRec engine named 'similarapps'
// Get app ID
$app = getApp();
try {
// Retrieve similar apps for the current app
$command = $client->getCommand(
'itemsim_get_top_n',
<?php
// Use Composer's autoloader to load PredictionIO PHP SDK.
require_once("vendor/autoload.php");
use PredictionIO\PredictionIOClient;
// 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 = PredictionIOClient::factory(array("appkey" => "your app key"));
{
"require": {
"predictionio/predictionio": "~0.6.0"
}
}
curl -sS https://getcomposer.org/installer | php -d detect_unicode=Off
php composer.phar install
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.
# Suggest similar funded projects
try:
# retreive top 5 similar funded projects
result = client.get_itemsim_topn("itemsim-fund", "the project ID", 5)
iids = result['pio_iids'] # list of recommended project IDs
except Exception as e:
iids = get_default_iids_list(5) # default behavior when no prediction results. eg. recommends the latest funded projects
log_error(e) # Handle error here. You may log the error for debugging.