dev-master
9999999-dev
MIT
The Requires
- php >=5.3.0
- composer/installers *
- predictionio/predictionio *
by Wan Chen
cakephp predictionio
CakePHP Plugin for the PredictionIO machine learning server, (*2)
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
cd PredictioIO composer install
In your app/Config/bootstrap.php
, load the plugin, (*3)
CakePlugin::load(array('PredictionIO' => array('bootstrap' => true)));
Put your predictionIO api key in app/Plugin/PredictionIO.Config/bootstrap.php
, (*4)
You can also define which model will be used as the User model, and the name of the default engine used for your recommendation., (*5)
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., (*6)
Attach the Predictionable behavior to your Model, (*7)
$actsAs = array( 'PredictionIO.Predictionable' => array( //'fields' => array(), //'types' => array(), //'engine' => '', //'count' => 10 ) );
Optional settings:, (*8)
fields
: An array of additional fields to save along the predictionIO recordtypes
: 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 fromcount
: The default number of records to fetch from predictionIOengine
and count
can be overwritten later., (*9)
Now, you have to save user-to-item behavior before computing any recommendations., (*10)
Examples: User:1
Those actions are saved from the User Model with:, (*12)
$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:, (*13)
$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:, (*14)
$User->id = 2; $User->recordAction('rate', array('model' => 'Post', 'id' => 25), array('note' => 10));
Retrieve items recommended to a specific user, (*15)
findRecommended()
can be used on a User model, or on an other model, as long as it's binded to the User model., (*16)
$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., (*17)
Example, (*18)
// 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., (*19)
$options
can take an additional prediction
key:, (*20)
'prediction' => array( 'id' => $userId, 'engine' => 'engine1' )
Retrieve items silimar to another item, (*21)
Use the findSimilar()
methods. It accepts the same arguments as the classic find
method, but will only returns
results from similar items., (*22)
It accepts an additional prediction
argument in the query options, (*23)
$Post->id = 2; $Post->findSimilar('all', array( 'conditions' => array(), 'fields' => array(), 'limit' => 15, 'prediction' => array( 'engine' => 'engine1', 'count' => 8 ) ));
In the prediction
key, if:, (*24)
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., (*25)
To specify the ID of the items to get similars results to, you can either set the primary key of the current Model, (*26)
$Post-id = 2;
, (*27)
or you can specify it in the query, (*28)
$Post->findSimilar('all', array('id' => 2));
MIT
cakephp predictionio