Testing PersonalRank Graph Algorithm Implementation in AILearning
This test suite validates the PersonalRank algorithm implementation for graph-based recommendations in Python. It examines the calculation of node importance scores using random walk probabilities and damping factors in a directed graph structure.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
apachecn/ailearning
src/py3.x/ml/16.RecommenderSystems/test_graph-based.py
def PersonalRank(G, alpha, root):
rank = dict()
rank = {x: 0 for x in G.keys()}
rank[root] = 1
for _ in range(20):
tmp = {x: 0 for x in G.keys()}
for i, ri in G.items():
# j, wij
for j, _ 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