How can I implement a recommendation engine?

前端 未结 4 715
礼貌的吻别
礼貌的吻别 2021-01-31 20:15

Please be patient with my writing, as my English is not proficient.

As a programmer, I wanna learn about the algorithm, or the machine learning intelligence, that are im

4条回答
  •  半阙折子戏
    2021-01-31 20:51

    A first attempt could look like this:

    //First Calculate how often any product pair was bought together
    //The time/memory should be about Sum over all Customers of Customer.BoughtProducts^2
    Dictionary> boughtTogether=new Dictionary>();
    foreach(Customer in Customers)
    {
        foreach(product1 in Customer.BoughtProducts)
            foreach(product2 in Customer.BoughtProducts)
                {
                    int counter=boughtTogether[Pair(product1,product2)] or 0 if missing;
                    counter++;
                    boughtTogether[Pair(product1,product2)]=counter;
                }
    }
    
    boughtTogether.GroupBy(entry.Key.First).Select(group.OrderByDescending(entry=>entry.Value).Take(10).Select(new{key.Second as ProductID,Value as Count}));
    

    First I calculate how often each pair of products was bought together, and then I group them by the product and select the top 20 other products bought with it. The result should be put into some kind of dictionary keyed by product ID.

    This might get too slow or cost too much memory for large databases.

提交回复
热议问题