PHP code example of alejandro-yakovlev / cf-php

1. Go to this page and download the library: Download alejandro-yakovlev/cf-php 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/ */

    

alejandro-yakovlev / cf-php example snippets




use CFPHP\CollaborativeFiltering;
use CFPHP\RecommendationStrategy\UserBasedRecommendationStrategy;
use CFPHP\SimilarityStrategy\CosineSimilarityStrategy;
use CFPHP\User;

user3 = new User('user3', [
    'item1' => 3,
    'item2' => 3,
]);

$users = [
    $user1,
    $user2,
    $user3,
];

$similarityStrategy = new CosineSimilarityStrategy();
$recommendationStrategy = new UserBasedRecommendationStrategy($users, $similarityStrategy);

$collaborativeFiltering = new CollaborativeFiltering($recommendationStrategy);
$recommendations = $collaborativeFiltering->getRecommendations('user3');

print_r($recommendations);
bash
composer