duyixian1234

# 建立数据集

``````critics={'Lisa Rose': {'Lady in the Water': 2.5, 'Snakes on a Plane': 3.5,
'Just My Luck': 3.0, 'Superman Returns': 3.5, 'You, Me and Dupree': 2.5,
'The Night Listener': 3.0},
'Gene Seymour': {'Lady in the Water': 3.0, 'Snakes on a Plane': 3.5,
'Just My Luck': 1.5, 'Superman Returns': 5.0, 'The Night Listener': 3.0,
'You, Me and Dupree': 3.5},
'Michael Phillips': {'Lady in the Water': 2.5, 'Snakes on a Plane': 3.0,
'Superman Returns': 3.5, 'The Night Listener': 4.0},
'Claudia Puig': {'Snakes on a Plane': 3.5, 'Just My Luck': 3.0,
'The Night Listener': 4.5, 'Superman Returns': 4.0,
'You, Me and Dupree': 2.5},
'Mick LaSalle': {'Lady in the Water': 3.0, 'Snakes on a Plane': 4.0,
'Just My Luck': 2.0, 'Superman Returns': 3.0, 'The Night Listener': 3.0,
'You, Me and Dupree': 2.0},
'Jack Matthews': {'Lady in the Water': 3.0, 'Snakes on a Plane': 4.0,
'The Night Listener': 3.0, 'Superman Returns': 5.0, 'You, Me and Dupree': 3.5},
'Toby': {'Snakes on a Plane':4.5,'You, Me and Dupree':1.0,'Superman Returns':4.0}}

``````

# 计算欧几里得距离

``````
def sim_distance(prefs,person1,person2):
si = list(filter(lambda x:x in prefs[person2],prefs[person1]))
return 0 if len(si) == 0 else 1 /(1 + sum((prefs[person1][it] - prefs[person2][it]) ** 2
for it in si))
``````

# 计算皮尔逊距离

``````def sim_pearson(prefs,p1,p2):
si = list(filter(lambda x:x in prefs[p2],prefs[p1]))
n = len(si)
sum1 = sum(prefs[p1][item] for item in si)
sum2 = sum(prefs[p2][item] for item in si)
sum1sq = sum([prefs[p1][it] ** 2 for it in si])
sum2sq = sum([prefs[p2][it] ** 2 for it in si])
pSum = sum([prefs[p1][it] * prefs[p2][it] for it in si])
num = pSum - (sum1 * sum2)/n
den = ((sum1sq - sum1 ** 2 / n ) * (sum2sq - sum2 ** 2 / n)) ** 0.5
r = 0 if n == 0 or den == 0 else num / den
return r
``````

#待续

### duyixian1234

mbx8x9u
2018/01/02
0
0

iTacey
2015/03/28
234
1

2017/06/03
0
0

2017/11/22
0
0

2017/11/27
0
0

29分钟前
9
0
debian10使用putty配置交换机console口

W_Lu

10
0
aelf Enterprise 0.8.0 beta有奖公测，“Bug奖金计划”重磅开启

2019年9月30日，aelf Enterprise 0.8.0 beta版正式发布。aelf Enterprise 0.8.0 beta是一个完备的区块链系统, 包含完备的区块链系统、开发套件、开发文档、以及配套的基础应用和基础服务。 ...

AELF开发者社区

10
0
oracle 初始化数据库脚本

create user lpf identified by 123456; create tablespace lpf_ts_cms datafile '/opt/app/oracle/product/11.2.0/lpf.dbf' size 200M; alter user lpf default tablespace lpf_ts_cms; sel......

internetafei

8
0

TurboSanil

7
0