rafguns / linkpred

Easy link prediction tool
Other
140 stars 46 forks source link

README should have full (standalone) code example #18

Open rafguns opened 6 years ago

rafguns commented 6 years ago

We should give a full standalone code example in the README, including evaluation.

Spinoff from #12. The example I gave there is this (slightly reworked to take advantage of a7121f8):

import linkpred
import random
from matplotlib import pyplot as plt

random.seed(100)

# Read network
G = linkpred.read_network('examples/inf1990-2004.net')

# Create test network
test = G.subgraph(random.sample(G.nodes(), 300))

# Exclude test network from learning phase
training = G.copy()
training.remove_edges_from(test.edges())

simrank = linkpred.predictors.SimRank(training, excluded=training.edges())
simrank_results = simrank.predict(c=0.5)

evaluation = linkpred.evaluation.EvaluationSheet(simrank_results, test.edges())

plt.plot(evaluation.recall(), evaluation.precision())