Skip to content

Repository files navigation

BiGraph

PyPI versionPyPI versionPyPI - Python Version

GitHub Repo stars

BiGraph is a Python package for Link prediction in bipartite networks.

Node based similarities and Katz has been implemented. you can find algorithms in bigraph module. Algorithms implemented so far:

Algorithms table
NumberAlgorithm
1jaccard
2adamic adar
3common neighbors
4 preferential attachment
5katz similarity

Installation

Install the latest version of BiGraph:

$ pip install bigraph

Simple example

Predicting new links in a randomly generated graph using Adamic-Adar algorithm:

frombigraph.predictimportaa_predictfrombigraph.preprocessingimportimport_files, make_graphdefadamic_adar_prediction():
""" Link prediction on bipartite networks :return: A dictionary containing predicted links """df, df_nodes=import_files()
print(df)
print(f"Graph Nodes: ", df_nodes)
G=make_graph(df)
print(G)
predicted=aa_predict(G) # Here we have called Adamic Adar method from bigraph modulereturnpredicted# Executing the functionif__name__=='__main__':
adamic_adar_prediction()

Evaluating Adamic-Adar algorithm.
You can try other provided prediction algorithms by replacing the "aa" argument.

frombigraph.evaluation.evaluationimportevaluatefrombigraph.preprocessingimportimport_files, make_graphdefadamic_adar_evaluation():
""" Evaluate Adamic-Adar algorithm using 10-Fold cross-validation  :return: A dictionary containing the evaluation results """df, df_nodes=import_files()
G=make_graph(df)
results=evaluate(G, k=10,
method='aa') # Here we have evaluated adamic-adar# methods using evaluation module. Methods are 'jc', 'aa', 'pa', 'cn'returnresults# Executing the functionif__name__=='__main__':
adamic_adar_evaluation()

Call for Contributions

The Bigraph project welcomes your expertise and enthusiasm!

Ways to contribute to Bigraph:

  • Writing code
  • Review pull requests
  • Develop tutorials, presentations, and other educational materials
  • Translate documentation and readme contents

Issues

If you happened to encounter any issue in the codes, please report it here. A better way is to fork the repository on Github and/or create a pull request.

Metrics

Metrics that are calculated during evaluation:

Metrics table
NumberEvaluattion metrics
1Precision
2AUC
3ROC
4returns fpr*
5returns tpr*
  • For further usages and calculating different metrics

Dataset format

Your dataset should be in the following format (Exclude the 'Row' column):

Sample edges (links) dataset
Rowleft_sideright_sideWeight*
1u0v11
2u2v11
3u1v21
4u3v31
5u4v32
  • Note that running
    from bigraph.preprocessing import import_files
    df, df_nodes = import_files()
    will create a sample graph for you and will place it in the inputs directory.
  • Although the weight has not been involved in current version, but, the format will be the same.

More examples

Predicting new links in a randomly generated graph using following algorithms:

  • Preferential attachment
  • Jaccard similarity
  • Common neighbours
frombigraph.predictimportpa_predict, jc_predict, cn_predictfrombigraph.preprocessingimportimport_files, make_graphdefmain():
""" Link prediction on bipartite networks :return: """df, df_nodes=import_files()
G=make_graph(df)
pa_predict(G) # Preferential attachmentjc_predict(G) # Jaccard coefficientcn_predict(G) # Common neighbors# Executing the functionif__name__=='__main__':
main()

References

References table
NumberReferenceYear
1Yang, Y., Lichtenwalter, R.N. & Chawla, N.V. Evaluating link prediction methods. Knowl Inf Syst 45, 751–782 (2015).https://doi.org/10.1007/s10115-014-0789-02015
2Liben-nowell, David & Kleinberg, Jon. (2003). The Link Prediction Problem for Social Networks. Journal of the American Society for Information Science and Technology.https://doi.org/58.10.1002/asi.205912003
2......

Future work

  • Modulate the functions
  • Add more algorithms
  • Run on CUDA cores
  • Make it faster using vectorization etc.
  • Add more preprocessors
  • Add dataset, graph, and dataframe manipulations
  • Unify and reconstruct the architecture and eliminate redundancy

Notes

  • It can export the graph in .json and .gexf format for further usages. For instance: Gephi etc.

If you found it helpful, please give us a

License

Released under the BSD license

Copyright © 2017-2021 BiGraph Developers
Soran Ghadri (soran.gdr.cs@gmail.com)
Taleb Zarhesh (taleb.zarhesh@gmail.com)