PHP code example of ankane / disco

1. Go to this page and download the library: Download ankane/disco library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ankane / disco example snippets


use Disco\Recommender;

$recommender = new Recommender();

$recommender->fit([
    ['user_id' => 1, 'item_id' => 1, 'rating' => 5],
    ['user_id' => 2, 'item_id' => 1, 'rating' => 3]
]);

$recommender->fit([
    ['user_id' => 1, 'item_id' => 1],
    ['user_id' => 2, 'item_id' => 1]
]);

$recommender->userRecs($userId);

$recommender->itemRecs($itemId);

$recommender->userRecs($userId, count: 3);

$recommender->predict([['user_id' => 1, 'item_id' => 2], ['user_id' => 2, 'item_id' => 4]]);

$recommender->similarUsers($userId);

use Disco\Data;

$data = Data::loadMovieLens();

$recommender = new Recommender(factors: 20);
$recommender->fit($data);
$recommender->itemRecs('Star Wars (1977)');

new Recommender(factors: 8, epochs: 20);

$recommender->fit($data, validationSet: $validationSet);

$recommender->userRecs($newUserId); // returns empty array

$recommender->userIds();
$recommender->itemIds();

$recommender->globalMean();

$recommender->userFactors($userId);
$recommender->itemFactors($itemId);
sh
git clone https://github.com/ankane/disco-php.git
cd disco-php
composer install
composer test