Code Monkey home page Code Monkey logo

laravel-model-recommendation's Introduction

Hi ๐Ÿ‘‹,

I'm Umut IลŸฤฑk, a software engineer ๐Ÿ‘จโ€๐Ÿ’ป who is passionate about web technologies and open source. Iโ€™m currently working as Engineering Manager at Intenseye.

More...

laravel-model-recommendation's People

Contributors

bretoreta avatar raidouahioune avatar umutphp avatar xoshbin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

laravel-model-recommendation's Issues

Getting recommendation for similar posts based on user likes

The package creates item-based collaborative filtering but in some cases user-based filtering is also needed. With this issue, user-based filtering algorithm will be added as a new algorithm.

Discussed in #21

Originally posted by Kyzegs September 21, 2023
I came across this package today and I'm struggling to figure out exactly how to use it to achieve what I want. I'm aiming to develop a feature where I can recommend posts to users based on the content of the posts they've previously liked.

image

Laravel 10.* Support

Discussed in #15

Originally posted by bretoreta August 14, 2023
Can we add support for Laravel 10.* ?

Cannot get Recommendations of different model types.

I have a table called user_views like shown bellow
image
And here is the code to config the recommendation i used

<?php

namespace App\Business\Recommendation;

use App\Models\Course;
use App\Models\Document;
use App\Models\Question;

trait HasViewsRecommendation
{


    public static $recommendations = [
        Document::class => 'suggested_documents',
        Course::class => 'suggested_courses',
        Question::class => 'suggested_questions'
    ];

    public static $recommendationCount = 5;
    private static function generateRelationAlgorithmArray(string $model, string $name): array
    {

        return
            [$name => [
                'recommendation_algorithm'         => 'db_relation',
                'recommendation_data_table'        => 'user_views',
                'recommendation_data_table_filter' => [],
                'recommendation_data_field'        => 'viewable_id',
                'recommendation_data_field_type'   => $model,
                'recommendation_group_field'       => 'user_id',
                'recommendation_count'             => self::$recommendationCount
            ]];
    }
    public static function getRecommendationAlgorithmArray(): array
    {
        $result = [];
        foreach (self::$recommendations as $model => $name) {
            $result = array_merge($result, self::generateRelationAlgorithmArray($model, $name));
        }
        return $result;
    }
}

And for sure I overided the the static function like this

class User extends Authenticatable implements  InteractWithRecommendation
{

    use HasFactory,
        HasRecommendation,
        HasViewsRecommendation,
  

    /**
     * The user recommendation config.
     * @return array
     */
    public static function getRecommendationConfig(): array
    {
        return self::getRecommendationAlgorithmArray();
    }

And i generated some recommendations using the laravel-model-recommendation table and here is some rows
image

Now based on my understanding .if the user logged in is of id 7 and i called the fuction php $user->getRecommendations('suggested_courses'); I should get the First 5 rows that are of type Courses .But the thing is that i always get an empty array .
To better undestand the situation I inspected the source code and I think it"s because of this query
image
The target_type is hardcoded to be the same as the source type.

Add Recommendation Algorithm Options

The algorithm uses item based filtering with an unsupervised algorithm. We need to add multiple algorithm choices and a config option to choose which algorithm to use.

Similarity Calculation Takes To Much Time

As the number of products gets bigger, the duration of the similarity calculation grows dramatically. Instead of using matrix calculation (n^2 operations for n products), we need to find a way to reduce the number of operations. Possible solutions;

  1. Selecting a random product and use it to calculate the similarity scores of the products.
  2. Creating an imaginary product with unique values.

Wrong id in source_id

Following the use case 6 to recommend posts for user based on votes, I came across this bug where when generating the data in the table it's adding the id of the subject_id for the source_id instead of using user_id from the interactions table.
Following the bug i found that at this line below, the group_field is not passed down in the foreach loop I couldn't go further but I think from there and on this field is gone.

foreach ($dataGroup as $group) {

that's the config I use, same as use case 6 except changed user class to Post::class

public static function getRecommendationConfig(): array
    {
        return [
            'recommended_posts' => [
                'recommendation_algorithm'         => 'db_relation',
                'recommendation_data_table'        => 'interactions',
                'recommendation_data_table_filter' => [
                    'relation' => 'upvote' // possible values are follow/like/subscribe/favorite/upvote/downvote. Choose the one that you want to generate the recommendation for.
                ],
                'recommendation_data_field'        => 'subject_id',
                'recommendation_data_field_type'   => Post::class,
                'recommendation_group_field'       => 'user_id',
                'recommendation_count'             => 5
            ]
        ];
    }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.