The Magic Behind an App Store: Personalization – with PHP SDK Code Samples
15 Oct 2013

UseCase-AppStoreIn this era of platforms, app stores are essential and the competition in the market is fierce. As the hegemony of Apple App Store, Google Play, Facebook App Center and Amazon Appstore continues, competitors are hoping to take a slice of the app store pie.

Some examples include Appolicious, Appreciate, Getjar, Appoke, and Firefox Marketplace. There are also app stores that focus on specific verticals like games, these are becoming more and more popular, with Games Grabr, and GameFinder being some examples.

While the app store business can be profitable, the fact that there are so many apps out there poses a discovery problem. As numerous new apps come out every day with some being junk and some relevant only to a small group of users, app stores need to know how to recommend the most relevant apps to their users in order to remain popular.

For this reason, most app stores offer personalized recommendations to their users.


You may be wondering how such personalized discovery features can be built. The truth is, with the help of PredictionIO, the open source Machine Learning server, it can be built in no time! In this tutorial, we are going to show you how:
Discovery based on Recent Interests

On the front page, you can make serendipitous recommendations to help users discover new and interesting apps based on what they have recently browsed. This can be achieved using an Item Similarity Engine.

Step 1: Install PredictionIO Server

Follow the instructions to install PredictionIO.

When the installation is complete, go to the PredictionIO Admin Panel to add a new application for the service you are building. You will then obtain an App Key, which is needed later when you integrate the PredictionIO SDK.

Step 2: Install the SDK in Your Development Language

PredictionIO provides SDK in various languages. PHP is used in this example. Execute the following shell command. This will install the SDK package on your machine:

  1. Create a file called composer.json
  2. Install Composer
  3. Install PredictionIO PHP SDK and its dependencies with Composer

Step 3: Integrate the PredictionIO SDK into Your Application for Importing Data

Now you have finished the integration which handles the data import.

Step 4: Create an Item Similarity Engine

Go to the PredictionIO Admin Panel, add an Item Similarity Engine. Specify an engine name that will be used in your code to retrieve prediction results from this engine (e.g. “similarapps”). Since this engine is responsible for making serendipitous recommendations, you should set Serendipity to a higher level, say 8 or 9, under Prediction Preferences.

This engine can now generate personalized app recommendation to users based on the imported data. The default algorithm will be deployed automatically, but you can fine-tune it later. Alternatively, there are a number of different built-in algorithms to choose from.

When the engine status changes to “Running”, it means the prediction results are ready.

Step 5: Query Prediction Results.


// 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
    foreach ($previouslyViewedApps as $app) {
        $command = $client->getCommand(
                'pio_iid' => $app,
                'pio_engine' => 'similarapps',
                'pio_n' => 10
        $result = $client->execute($command);
        array_push($similarApps, $result["pio_iids"]);
    } catch (Exception $e) {
        echo 'Caught exception: ', $e->getMessage(), "\n";

// Randomly pick and show 10 similar apps
show(array_rand($similarApps, 10));


People who Download this also Download….

Showing ‘People who download this app also download…’ for each app is also straightforward. Just follow the example above to import data, and you will have created an Item Similarity Engine. Now you can query similar items:


Personalized Recommendation for Each App Category

The following demonstrates how to recommend 10 apps in each category to users based on a) their previous downloads; b) the star ratings they gave to apps previously.

Assuming you have integrated your app with PredictionIO, you now need to create an Item Recommendation Engine:

Step 1: Create an Item Recommendation Engine

Go to the PredictionIO Admin Panel, add an Item Recommendation Engine. When the engine status changes to “Running”, it means the prediction results are ready.

Step 2: Query Prediction Results.

// 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
    $command = $client->getCommand(
            'pio_uid' => $uid,
            'pio_engine' => 'appsrec',
            'pio_n' => 10,
            'pio_itypes' => $category
    $result = $client->execute($command);
    $recs = $result["pio_iids"];
} catch (Exception $e) {
    echo 'Caught exception: ', $e->getMessage(), "\n";

Without a doubt, personalization can greatly increase the effectiveness of app recommendations and is helpful in retaining customers. This tutorial has demonstrated how to quickly embed personalization features in different ways for app stores, and hopefully this is useful for some of you guys! For more details on how PredictionIO can be helpful for building smarter software using Machine Learning, visit our website at