aliyun-PAI-基于协同过滤的商品推荐
aliyun-PAI-基于协同过滤的商品推荐
nickles 发表于8个月前
aliyun-PAI-基于协同过滤的商品推荐
• 发表于 8个月前
• 阅读 11
• 收藏 1
• 评论 0

1.概述

一个推荐系统的评判标准：用户满意度、预测准确度、覆盖率、多样性、新颖性、惊喜度、信任度、实时性、健壮性、商业目标。

2.主要推荐系统算法

``````def User_Similarity(train):
W=dict()
for u in train.keys():
for v in train.keys():
if u == v:
continue;
W[u][v] = len(train[u],train[v])
W[u][v] /= math.sqrt(len(train[u]) * len(train[v]) * 1.0)``````

``````#!/usr/bin/env python
# coding=utf-8
def UserSimilarity(train):
#建立倒排表
item_users = dict()
for u,items in train.items():
for i in item.keys():
if i not in item_users:
items_users[i] = set()
#item_users即为物品到用户的倒排表
#计算用户之间的相关度
C = dict()#任意用户之间的相关度
N = dict()#用户正反馈物品的数目
for i ,users in item_users:
for u in users:
N[u] += 1
for v in users:
if u == v:
continue:
C[u][v] += 1
#最后计算结果矩阵
W = dict()
for u ,related_users in C.items():
for v,cuv in related_users:
W[u][v] = cuv / math.sqrt(N[u]* N[v]*1.0)
return W``````

S(u,K)包含和用户u兴趣最相近的K的用户；

Wuv用户u和用户v的兴趣相似度；

Rvi用户v对物品i的兴趣度；

``````def Recommend(user,train,W):
rank = dict()
interacted_items = train[user]
for v , wuv in sort(W[u].items,key = itemgetter(1),reverse = True)[0:k]:
for i ,rvi in train[v].items:
if i in interacted_items:
continue
rank[i] += wuv * rvi
return rank``````

×