Comments (7)
Doing a fast search, that is how i fixed it, I'm not sure if it's the right way or I didn't hardcoded it:
public static function calculateRecommendations($data, $dataCount)
{
$dataCartesianRanks = [];
$recommendations = [];
$dataGroup = [];
foreach ($data as $value) {
if (!isset($dataGroup[$value->group_field])) {
$dataGroup[$value->group_field] = [];
}
$dataGroup[$value->group_field][$value->data_field] = $value->data_field;
}
foreach ($dataGroup as $group) {
foreach ($group as $data1) {
foreach ($group as $data2) {
if ($data1 == $data2) {
continue;
}
if (!isset($dataCartesianRanks[$data1])) {
$dataCartesianRanks[$data1] = [];
}
if (!isset($dataCartesianRanks[$data1][$data2])) {
$dataCartesianRanks[$data1][$data2] = 0;
}
$dataCartesianRanks[$data1][$data2] += 1;
}
}
}
// Generate recommendation list by sorting
foreach ($dataCartesianRanks as $data1 => $data) {
arsort($data);
$key = key($dataGroup);
$data = array_slice($data, 0, $dataCount, true);
$recommendations[$key] = $data;
}
return $recommendations;
}
from laravel-model-recommendation.
@Xoshbin many thanks for the issue and solution. Let me check and update you asap :-)
from laravel-model-recommendation.
@Xoshbin Is it possible to create a PR for this fix? Theoretically, It is correct. I will merge it soon.
from laravel-model-recommendation.
I will do a PR soon, I was waiting for your response for two things:
First: making sure the solutions is working! (Done)
Second: There is an issue!!
on the same use case and using my example, I think "it's supposed to iterate through the posts table to generate the recommendations" (correct me if I'm wrong), but it's generating the recommendations iterating through the interactions table .
from laravel-model-recommendation.
@Xoshbin I have merged PR but It fails agains the existing tests. When I checked, I think $key = key($dataGroup);
is wrong. The $key
is always the first index.
from laravel-model-recommendation.
@Xoshbin Regarding the second problem, It should traverse the interactions table to have the both source and target IDs.
from laravel-model-recommendation.
@Xoshbin I have merged PR but It fails agains the existing tests. When I checked, I think
$key = key($dataGroup);
is wrong. The$key
is always the first index.
It's true, it's returning the first index. when I debug the issue, only the first index contained the source_id value, that is why I fixed it that way, it did fix my problem, but I was not sure if it was correct or no and that is why I waited for your response.
from laravel-model-recommendation.
Related Issues (15)
- Use Cases With Some Popular Packages
- Improve Recommendation Config
- Support For Different Types Of Models In Same Occurance
- Add Documentations For Some Packages With Multi-type Relations
- Add Query Parameters To Data Selection
- Add Recommendation Algorithm Options
- Add Multiple Recommendation Support To One Single Model
- User Based Recommendations
- Similarity Calculation Takes To Much Time
- Similarity Score Is not Stored In Recommendation Table
- Laravel 10.* Support
- Getting recommendation for similar posts based on user likes
- Cannot get Recommendations of different model types. HOT 1
- PHP 8.3 Support
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-model-recommendation.