Code Monkey home page Code Monkey logo

Comments (7)

Xoshbin avatar Xoshbin commented on July 22, 2024 1

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.

umutphp avatar umutphp commented on July 22, 2024 1

@Xoshbin many thanks for the issue and solution. Let me check and update you asap :-)

from laravel-model-recommendation.

umutphp avatar umutphp commented on July 22, 2024

@Xoshbin Is it possible to create a PR for this fix? Theoretically, It is correct. I will merge it soon.

from laravel-model-recommendation.

Xoshbin avatar Xoshbin commented on July 22, 2024

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.

umutphp avatar umutphp commented on July 22, 2024

@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.

umutphp avatar umutphp commented on July 22, 2024

@Xoshbin Regarding the second problem, It should traverse the interactions table to have the both source and target IDs.

from laravel-model-recommendation.

Xoshbin avatar Xoshbin commented on July 22, 2024

@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)

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.