Collaborative filtering recommendation system. Recommendation algorithm using collaborative filtering. Topics: Ranking algorithm, euclidean distance algorithm, slope one algorithm, filtragem colaborativa.
Collaborative filtering recommendation system
composer require tigo/recommendation
If you found this project useful, consider making a donation to support the developer.
Starting with composer
composer require tigo/recommendation
//Somewhere in your project, you may need to use autoload
include __DIR__ ."/vendor/autoload.php";
Recommend a product using collaborative filtering
/**
$table gets the array from the database.
$user is the foreign key that represents the user who will receive the recommendation.
**/
use Tigo\Recommendation\Recommend; // import class
$client = new Recommend();
$client->ranking($table,$user); //optional third parameter refers to the score not accepted
$client->euclidean($table,$user); //optional third parameter refers to the minimum accepted score
$client->slopeOne($table, $user); //optional third parameter refers to the minimum accepted score
Sometimes, it may be necessary to rename the value of the constants (According to your database table).
./src/configuration/StandardKey.php
) const SCORE = 'score'; //score
const PRODUCT_ID = 'product_id'; //Foreign key
const USER_ID = 'user_id'; //Foreign key
A simple didactic demonstration of the algorithm
/**
Example using "rating: liked and disliked"
like: score = 1; dislike: score = 0
**/
$table = [
['product_id'=> 'A',
'score'=> 1,
'user_id'=> 'Pedro'
],
['product_id'=> 'B',
'score'=> 1,
'user_id'=> 'Pedro'
],
['product_id'=> 'A',
'score'=> 1,
'user_id'=> 'João'
],
['product_id'=> 'B',
'score'=> 1,
'user_id'=> 'João'
],
['product_id'=> 'C',
'score'=> 1,
'user_id'=> 'João'
]
];
use Tigo\Recommendation\Recommend; // import class
$client = new Recommend();
print_r($client->ranking($table,"Pedro")); // result = ['C' => 2]
print_r($client->ranking($table,"Pedro",1)); // result = [];
print_r($client->euclidean($table,"Pedro")); // result = ['C' => 1]
print_r($client->euclidean($table,"Pedro", 2)); // result = [] ;
print_r($client->slopeOne($table,'Pedro')); // result = ['C' => 1]
print_r($client->slopeOne($table,'Pedro', 2)); // result = []
If you are interested in supporting this project, you can help in many ways. Leave a star :star: or make a donation of any value.
MIT license. See the archive License