Skip to main content

Python package for link prediction

Project description

linkpred is a Python package for link prediction: given a network, linkpred provides a number of heuristics (known as predictors) that assess the likelihood of potential links in a future snapshot of the network.

While some predictors are fairly straightforward (e.g., if two people have a large number of mutual friends, it seems likely that eventually they will meet and become friends), others are more involved.

https://travis-ci.org/rafguns/linkpred.svg?branch=master https://coveralls.io/repos/rafguns/linkpred/badge.svg?branch=master

linkpred can both be used as a command-line tool and as a Python library in your own code.

Installation

linkpred (v0.5 and later) works under Python 3.6, 3.7, and 3.8. Version 0.4.1 was the last to support versions 3.4 and 3.5. It depends on:

  • matplotlib

  • networkx

  • numpy

  • pyyaml

  • scipy

  • smokesignal

You should be able to install linkpred and its dependencies using pip (pip install linkpred or python -m pip install linkpred). If you do not yet have Python installed, I recommend starting with Anaconda, which includes optimized versions of packages like numpy. If you want to use the Community predictor, which relies on community structure of the network, make sure you also have the python-louvain package by installing with pip install linkpred[all].

Example usage as command-line tool

A good starting point is linkpred --help, which lists all the available options. To save the predictions of the CommonNeighbours predictor, for instance, run:

$ linkpred examples/inf1990-2004.net -p CommonNeighbours --output cache-predictions

where examples/inf1990-2004.net is a network file in Pajek format. Other supported formats include GML and GraphML. The full output looks like this:

$ linkpred examples/inf1990-2004.net -p CommonNeighbours --output cache-predictions
16:43:13 - INFO - Reading file 'examples/inf1990-2004.net'...
16:43:13 - INFO - Successfully read file.
16:43:13 - INFO - Starting preprocessing...
16:43:13 - INFO - Removed 35 nodes (degree < 1)
16:43:13 - INFO - Finished preprocessing.
16:43:13 - INFO - Executing CommonNeighbours...
16:43:14 - INFO - Finished executing CommonNeighbours.
16:43:14 - INFO - Prediction run finished

$ head examples/inf1990-2004-CommonNeighbours-predictions_2016-04-22_16.43.txt
"Ikogami, K"    "Ikegami, K"    5.0
"Durand, T"     "Abd El Kader, M"       5.0
"Sharma, L"     "Kumar, S"      4.0
"Paul, A"       "Durand, T"     4.0
"Paul, A"       "Dudognon, G"   4.0
"Paul, A"       "Abd El Kader, M"       4.0
"Karisiddippa, CR"      "Garg, KC"      4.0
"Wu, YS"        "Kretschmer, H" 3.0
"Veugelers, R"  "Deleus, F"     3.0
"Veugelers, R"  "Andries, P"    3.0

Example usage within Python

>>> import linkpred
>>> G = linkpred.read_network("examples/training.net")
11:49:00 - INFO - Reading file 'examples/training.net'...
11:49:00 - INFO - Successfully read file.
>>> len(G)   # number of nodes
632
>>> # We exclude edges already present, to predict only new links
>>> simrank = linkpred.predictors.SimRank(G, excluded=G.edges())
>>> simrank_results = simrank.predict(c=0.5)
>>> top = simrank_results.top(5)
>>> for authors, score in top.items():
...    print(authors, score)
...
Tomizawa, H - Fujigaki, Y 0.188686630053
Shirabe, M - Hayashi, T 0.143866427916
Garfield, E - Fuseler, EA 0.148097050146
Persson, O - Larsen, IM 0.138516589957
Vanleeuwen, TN - Noyons, ECM 0.185040358711

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

linkpred-0.5.1.tar.gz (23.6 kB view details)

Uploaded Source

File details

Details for the file linkpred-0.5.1.tar.gz.

File metadata

  • Download URL: linkpred-0.5.1.tar.gz
  • Upload date:
  • Size: 23.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.6.7

File hashes

Hashes for linkpred-0.5.1.tar.gz
Algorithm Hash digest
SHA256 4a1910eb781c03ecaaf94ecc46b937ae2f5ff99a6a26b49fad4caa2428602ded
MD5 8d638d0a505b36797618b539035f5139
BLAKE2b-256 a66bbcf5e197b7b0750b41159e06b364b5f4b302f4f16479811e01fdb2c658f8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page