from numpy import * from numpy import linalg as la def ecludSim(inA, inB): return 1.0/(1.0+ la.norm(inA - inB)) def cosSim(inA, inB): num = float(inA.T*inB) denom = la.norm(inA)*la.norm(inB) return 0.5+0.5*(num/denom) def standEst(dataMat, user, simMeas, item): n = shape(dataMat)[1] simTotal = 0.0; ratSimTotal = 0.0 for j in range(n): userRating = dataMat[user,j] if userRating == 0:continue overLap = nonzero(logical_and(dataMat[:,item].A>0,dataMat[:,j].A>0))[0] if len(overLap) == 0:similarity = 0 else:similarity = simMeas(dataMat[overLap,item],dataMat[overLap,j]) simTotal += similarity ratSimTotal += similarity * userRating if simTotal == 0:return 0 else: return ratSimTotal/simTotal def r
利用svd进行用户商品推荐的小实践
最新推荐文章于 2020-08-22 14:52:19 发布
本文介绍了一个使用Python和numpy实现的基于Singular Value Decomposition (SVD)的商品推荐系统。通过计算用户评分数据的欧氏距离和余弦相似度,对未评分商品进行预测评分,并推荐评分最高的项目。示例展示了如何对特定用户进行商品推荐,并给出了推荐结果。
摘要由CSDN通过智能技术生成