基于项目历史的推荐

时间:2015-04-20 05:11:45

标签: recommendation-engine collaborative-filtering

我有以下格式的csv文件/表格数据,

UserId Item1 Item2                  
1      url1   url3                                                                                     
1      url4   url6            
2      url2   url3         
2      url2   url4      
2      url4   url6     
3      url4   url6     
3      url2   url3      

所以,在这里,如果知道item1的值,我想预测一个特定用户的item2。我们可以使用协同过滤吗?如果是,请指导:)

1 个答案:

答案 0 :(得分:0)

我确定它会起作用,你必须弄明白你是如何决定用户是否相似。以下为您提供了一个基于item2值与item1s配对的建议字段(反之亦然) - 它排除了用户已经拥有的项目..当然,您可以做更复杂的事情,但这里有一些东西要开始

select *, ISNULL((SELECT STUFF
            ((SELECT ', ' + CAST(ITEM2 AS VARCHAR(10)) [text()] from
                    ((select top 5 ISNULL(item2,'') item2, count(item2) as cnt from items as CountTable1 where item1=Res.item1 and item2 is not null and len(item2) > 0
                     and item2 not in (select item2 from items where id=Res.id UNION select item1 from items where id=Res.id)
                    group by item2 order by cnt desc)
                    UNION
                    /* Below includes suggestions from item1 */
                    (select top 5 ISNULL(item1,'') item1, count(item1) as cnt from items as CountTable2 where item2=Res.item1 and item1 is not null and len(item1) > 0
                     and item1 not in (select item1 from items where id=Res.id UNION select item2 from items where id=Res.id)
                    group by item1 order by cnt desc))
                as Suggs where item1=Res.item1 FOR XML PATH('')
                , TYPE)
            .value('.','NVARCHAR(MAX)'),1,2,' ')
        List_Output)
    ,'') as Suggestions from items as Res

Sql Fiddle