PHPackages                             kamisama/cakephp-predictionio - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. kamisama/cakephp-predictionio

ActiveCakephp-plugin

kamisama/cakephp-predictionio
=============================

102.6k[1 issues](https://github.com/kamisama/cakephp-predictionio/issues)PHP

Since Nov 12Pushed 12y ago2 watchersCompare

[ Source](https://github.com/kamisama/cakephp-predictionio)[ Packagist](https://packagist.org/packages/kamisama/cakephp-predictionio)[ RSS](/packages/kamisama-cakephp-predictionio/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

PredictionIO for CakePHP
========================

[](#predictionio-for-cakephp)

[![Build Status](https://camo.githubusercontent.com/bf8ea0cdf2f1ca2ad78d87c13cb6d06fe7bbb2c263aa0059ef9c8d688dd0e1e4/68747470733a2f2f7472617669732d63692e6f72672f6b616d6973616d612f63616b657068702d70726564696374696f6e696f2e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/kamisama/cakephp-predictionio) [![Coverage Status](https://camo.githubusercontent.com/532bc761bdde0c93f7357a02a81d5fb35301a0d957e07636237aae287b3cb4a3/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6b616d6973616d612f63616b657068702d70726564696374696f6e696f2f62616467652e706e67)](https://coveralls.io/r/kamisama/cakephp-predictionio) [![Latest Stable Version](https://camo.githubusercontent.com/c2ac51bfdaabffabc5e0bebf5c72b54e5bfc55d6779f77dd678c775b7a3ff46a/68747470733a2f2f706f7365722e707567782e6f72672f6b616d6973616d612f63616b657068702d70726564696374696f6e696f2f762f737461626c652e706e67)](https://packagist.org/packages/kamisama/cakephp-predictionio)

CakePHP Plugin for the PredictionIO machine learning server

Installation
------------

[](#installation)

### Install the plugin

[](#install-the-plugin)

```
cd your-application/app/Plugin

# Classic install
git clone git://github.com/kamisama/cakephp-predictionio.git PredictionIO

# OR install as a submodule
git submodule add git://github.com/kamisama/cakephp-predictionioe.git PredictionIO

```

### Install dependencies

[](#install-dependencies)

```
cd PredictioIO
composer install

```

### Load the plugin

[](#load-the-plugin)

In your `app/Config/bootstrap.php`, load the plugin

```
CakePlugin::load(array('PredictionIO' => array('bootstrap' => true)));
```

Usage
-----

[](#usage)

### Settings

[](#settings)

Put your predictionIO api key in `app/Plugin/PredictionIO.Config/bootstrap.php`

You can also define which model will be used as the User model, and the name of the default engine used for your recommendation.

### Using the Predictionable Behavior

[](#using-the-predictionable-behavior)

The behavior will synchronize your models with the predictionIO server on each save/update/delete operation. By default, only the model primary key is sent to predictionIO, along with the model name.

Attach the Predictionable behavior to your Model

```
$actsAs = array(
  'PredictionIO.Predictionable' => array(
    //'fields' => array(),
    //'types' => array(),
    //'engine' => '',
    //'count' => 10
  )
);
```

Optional settings:

- `fields`: An array of additional fields to save along the predictionIO record
- `types`: An array of categories name, assigned to this model on the PredictionIo server (default is the current model name)
- `engine`: The name of the default engine used to fetch recommendation from
- `count`: The default number of records to fetch from predictionIO

`engine` and `count` can be overwritten later.

Now, you have to save user-to-item behavior before computing any recommendations.

Examples: User:1 Post:52, User:4 Page:26, User:85 Movie:8, etc ...

Those actions are saved from the User Model with:

```
$User->recordAction($actionName, $targetItem, $optionalParameters);
```

- `$actionName`: Name of the action, eg: save, like, rate, view, etc ...
- `$targetItem`: Target item of the action
- `$optionalParameters`: an array of additional fields to save along the action, eg: `array('note', 52)`

Example:

```
$User->id = 2;
$Post->id = 25;
$User->recordAction('rate', $Post, array('note' => 10));
```

You can also use the array alternative for referencing the target item:

```
$User->id = 2;
$User->recordAction('rate', array('model' => 'Post', 'id' => 25), array('note' => 10));
```

Getting items recommendations for an User
-----------------------------------------

[](#getting-items-recommendations-for-an-user)

Retrieve items recommended to a specific user

`findRecommended()` can be used on a User model, or on an other model, as long as it's binded to the User model.

```
$User->id = 5;
$User->findRecommended('all', array());

// Or
$Article->User->id = 5;
$Article->findRecommended('all', array());
```

`findRecommended()` accepts the same arguments as the classic `find()` method, and is always called by the **recommended item**.

Example

```
// Getting movies and activities recommendations
$User->id = 5;
$User->findRecommended('all', $options);

// Is equivalent to
$Movie->find('all', $options);
$Activity->find('all', $options);

// And will returns the results form these 2 find() actions
// Of course, the right ID will be injected into the $options,
// to fetch only the recommended items from yoru datasource
```

The type of model return depends on the type of models handled by your engine.

`$options` can take an additional `prediction` key:

```
'prediction' => array(
  'id' => $userId,
  'engine' => 'engine1'
)
```

Getting similar items recommendations
-------------------------------------

[](#getting-similar-items-recommendations)

Retrieve items silimar to another item

Use the `findSimilar()` methods. It accepts the same arguments as the classic `find` method, but will only returns results from similar items.

It accepts an additional `prediction` argument in the query options

```
$Post->id = 2;
$Post->findSimilar('all', array(
  'conditions' => array(),
  'fields' => array(),
  'limit' => 15,
  'prediction' => array(
    'engine' => 'engine1',
    'count' => 8
  )
));
```

In the `prediction` key, if:

- no engine is specified, it'll default to the one set when loading the Behavior, then the one set in the config
- no count is specified, it'll default to the `limit` key, then the count set when loading the behavior.

`findSimilar()` will in fact just find the ID of similar items, then put then in the `conditions` key. If you have something in `conditions.Post.id`, it'll be overwritten.
All other settings will be used to fetch the data from the original datasource.

To specify the ID of the items to get similars results to, you can either set the primary key of the current Model

`$Post-id = 2;`

or you can specify it in the query

```
$Post->findSimilar('all', array('id' => 2));
```

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/2935823cb9658334ccbba85d6a2be151d54ac52e1a6981b79b27a263e48320b1?d=identicon)[wa0x6e](/maintainers/wa0x6e)

---

Top Contributors

[![wa0x6e](https://avatars.githubusercontent.com/u/495709?v=4)](https://github.com/wa0x6e "wa0x6e (50 commits)")

### Embed Badge

![Health badge](/badges/kamisama-cakephp-predictionio/health.svg)

```
[![Health](https://phpackages.com/badges/kamisama-cakephp-predictionio/health.svg)](https://phpackages.com/packages/kamisama-cakephp-predictionio)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
