祎二三四 2020-03-30 22:52 采纳率: 0%
浏览 213

有大神帮我看下这个是不是协同过滤推荐算法?

@Override

public List<Product> getUserLike(Integer uid,Integer pid){

List<UserLook> userLooks = userLookMapper.getListByUid(uid, 5);

List<Product> products = new ArrayList<Product>();

    int sum_xy = 0;
    int sum_x = 0;
    int sum_y = 0;
    double sum_x2 = 0;
    double sum_y2 = 0;
    int n = 0;         

for(UserLook userLook:userLooks) {

List<Product> pList = productService.findProductByRand(userLook.getCsid(), userLook.getPid(), 1);
if(pList!=null && pList.size()>0 && !pid.equals(pList.get(0).getPid())) {!


 Product product = pList.get(0);
 int sellNum = productService.getSellNum(product.getPid());
 product.setSellNum(sellNum);

 n += 1;
             int x = userLook.getUid();
             int y = userLook.getPid();
             sum_xy += x * y;
             sum_x += x;
             sum_y += y;
             sum_x2 += Math.pow(x, 2);
             sum_y2 += Math.pow(y, 2);

             double denominator = Math.sqrt(sum_x2 - Math.pow(sum_x, 2) / n) * Math.sqrt(sum_y2 - Math.pow(sum_y, 2) / n);
 if(denominator==0) {
  products.add(product);
 }

}  

}


return products;

}

uid是用户编号,pid商品编号csid商品分类的类别编号

  • 写回答

1条回答 默认 最新

  • threenewbee 2020-03-31 00:16
    关注
    评论

报告相同问题?

悬赏问题

  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型