mirror of
https://github.com/apachecn/ailearning.git
synced 2026-05-08 06:33:55 +08:00
完全推荐系统的python代码
This commit is contained in:
17
src/python/16.RecommendedSystem/test_graph-based.py
Normal file
17
src/python/16.RecommendedSystem/test_graph-based.py
Normal file
@@ -0,0 +1,17 @@
|
||||
|
||||
def PersonalRank(G, alpha, root):
|
||||
rank = dict()
|
||||
rank = {x:0 for x in G.keys()}
|
||||
rank[root] = 1
|
||||
for k in range(20):
|
||||
tmp = {x:0 for x in G.keys()}
|
||||
for i, ri in G.items():
|
||||
for j, wij in ri.items():
|
||||
if j not in tmp:
|
||||
tmp[j] = 0
|
||||
tmp[j] += 0.6 * rank[i] / (1.0 * len(ri))
|
||||
if j == root:
|
||||
tmp[j] += 1 - alpha
|
||||
rank = tmp
|
||||
return rank
|
||||
|
||||
Reference in New Issue
Block a user