{ "info": { "author": "Daniel Kaslovsky", "author_email": "dkaslovsky@gmail.com", "bugtrack_url": null, "classifiers": [ "Environment :: Console", "License :: OSI Approved :: MIT License", "Natural Language :: English", "Operating System :: OS Independent", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7" ], "description": "# GraphRole\n\n[![Build Status](https://travis-ci.org/dkaslovsky/GraphRole.svg?branch=master)](https://travis-ci.org/dkaslovsky/GraphRole)\n[![Coverage Status](https://coveralls.io/repos/github/dkaslovsky/GraphRole/badge.svg?branch=master)](https://coveralls.io/github/dkaslovsky/GraphRole?branch=master)\n[![Python 3.6](https://img.shields.io/badge/python-3.6-blue.svg)](https://www.python.org/downloads/release/python-360/)\n[![Python 3.7](https://img.shields.io/badge/python-3.7-blue.svg)](https://www.python.org/downloads/release/python-370/)\n\nAutomatic feature extraction and node role assignment for transfer learning on graphs; based on the ReFeX/RolX algorithms [1, 2] of Henderson, et al.\n\n

\n\n

\n\n### Overview\nA fundamental problem for learning on graphs is extracting meaningful features. `GraphRole` provides the `RecursiveFeatureExtractor` class to automate this process by extracting recursive features capturing local and neighborhood (\"regional\") structural properties of a given graph. The specific implementation follows that of the ReFeX algorithm [1]. Node features (e.g., degree) and ego-net features (e.g., neighbors, number of internal vs. external edges) are extracted and then recursively aggregated over each node's neighbors' features until no additional information is encoded. As is shown in [1], these recursive, \"regional\" features facilitate node classification and perform quite well in transfer learning tasks.\n\n`GraphRole` also provides the `RoleExtractor` class for node role assignment (a form of classification). Different nodes play different structural roles in a graph, and using recursive regional features, these roles can be identified and assigned to collections of nodes. As they are structural in nature, node roles differ from and are often more intuitive than the commonly used communities of nodes. In particular, roles can generalize across graphs whereas the notion of communities cannot [2]. Identification and assignment of node roles has been shown to facilitate many graph learning tasks.\n\nPlease see [1, 2] for more technical details.\n\n### Installation\nThis package is hosted on PyPI and can be installed via `pip`:\n```\n$ pip install graphrole\n```\nTo instead install from source:\n```\n$ git clone https://github.com/dkaslovsky/GraphRole.git\n$ cd GraphRole\n$ python setup.py install\n```\n\n### Example\nAn example of `GraphRole` usage is found in the `examples` directory. The notebook\n[example.ipynb](./examples/example.ipynb)\n(also available via [nbviewer](https://nbviewer.jupyter.org/github/dkaslovsky/GraphRole/blob/master/examples/example.ipynb))\nwalks through feature extraction and role assignment for the well-known `karate_club_graph` that is included with `NetworkX`. Recursive features are extracted and used to learn role assignments for each node in the graph. The graph is shown above with each node colored corresponding to its role.\n\nThe extracted roles reflect structural properties of the graph at the node level. The nodes `0` and `33` (dark green) are central to the graph and are connected to many other nodes. Nodes `1`, `2`, `3`, and `32` are assigned to a similar role (red). In contrast, the roles colored as dark blue, light blue, and pink are found at the periphery of the graph. Notably, nodes need not be near one another to be assigned to the same role; instead nodes with similar properties are grouped together across the graph by their role assignments.\n\nAlthough not reflected by this example, weighted and directed graphs are also supported and will yield weighted and directed variants of the extracted features.\n\n### Usage\nFor general usage, begin by importing the two feature and role extraction classes:\n```\n>>> from graphrole import RecursiveFeatureExtractor, RoleExtractor\n```\nFeatures are then extracted from a graph `G` into a `pandas.DataFrame`:\n```\n>>> feature_extractor = RecursiveFeatureExtractor(G)\n>>> features = feature_extractor.extract_features()\n```\nNext, these features are used to learn roles. The number of roles is automatically determined by\na model selection procedure when `n_roles=None` is passed to the `RoleExtractor` class instance.\nAlternatively, `n_roles` can be set to a desired number of roles to be extracted.\n```\n>>> role_extractor = RoleExtractor(n_roles=None)\n>>> role_extractor.extract_role_factors(features)\n```\nThe role assignment for each node can be retrieved as a dictionary:\n```\n>>> role_extractor.roles\n```\nAlternatively, roles can be viewed as a soft assignment and a node's percent membership to each role\ncan be retrieved as a `pandas.DataFrame`:\n```\n>>> role_extractor.role_percentage\n```\n\n### Graph Interfaces\nAn interface for graph data structures is provided in the `graphrole.graph.interface` module. Implementations for `networkx` and `igraph` are included.\n\nThe `igraph` package is not included in `requirements.txt` and thus will need to be manually installed\nif desired. This is due to additional installation requirements beyond `pip install python-igraph`; see\nthe [igraph documentation](https://igraph.org/python/#pyinstall) for more details. Note that all tests\nthat require `igraph` will be skipped if it is not installed.\n\nTo add an implementation of an additional graph library or data structure:\n1. Subclass the `BaseGraphInterface` ABC in `graphrole.graph.interface.base.py` and implement the required methods\n1. Update the `INTERFACES` dict in `graphrole.graph.interface.__init__.py` to make the new subclass discoverable\n1. Add tests by trivially implementing a `setUpClass()` classmethod of a subclass of `BaseGraphInterfaceTest.BaseGraphInterfaceTestCases` in the `tests.test_graph.test_interface.py` module\n1. If desired, a similar procedure allows the feature extraction tests to be run using the added interface\nby again trivially implementing a `setUpClass()` classmethod of a subclass of `BaseRecursiveFeatureExtractorTest.TestCases` in the `tests.test_features.test_extract.py` module\n\n### Future Development\nModel explanation (\"sense making\") will be added to the `RoleExtractor` class in a future release.\n\n### Tests\nTo run tests:\n```\n$ python -m unittest discover -v\n```\nAs noted above, the tests for the `igraph` interface are skipped when `igraph` is not installed. Because this package is intentionally not required, the test coverage reported above is much lower than when `igraph` is installed and its interface tests are not skipped (__97% coverage__ to date).\n\n### References\n[1] Henderson, et al. [It\u2019s Who You Know: Graph Mining Using Recursive Structural Features](http://www.cs.cmu.edu/~leili/pubs/henderson-kdd2011.pdf).\n\n[2] Henderson, et al. [RolX: Structural Role Extraction & Mining in Large Graphs](https://static.googleusercontent.com/media/research.google.com/en//pubs/archive/46591.pdf).\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/dkaslovsky/GraphRole", "keywords": "graph,feature extraction,transfer learning,network,graph analysis,network analysis,refex,rolx", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "graphrole", "package_url": "https://pypi.org/project/graphrole/", "platform": "", "project_url": "https://pypi.org/project/graphrole/", "project_urls": { "Homepage": "https://github.com/dkaslovsky/GraphRole" }, "release_url": "https://pypi.org/project/graphrole/1.0.0/", "requires_dist": [ "networkx (==2.2)", "numpy (==1.15.3)", "pandas (==0.23.4)", "scikit-learn (==0.20.2)", "scipy (==1.1.0)" ], "requires_python": "", "summary": "Automatic feature extraction and node role assignment for transfer learning on graphs", "version": "1.0.0" }, "last_serial": 4913789, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "a6f3eec806bcb22568395c48c858a6da", "sha256": "ee4892dced05e6383360ad3c50248c22e20b3e41f887a7116ac15df4cc077305" }, "downloads": -1, "filename": "graphrole-1.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "a6f3eec806bcb22568395c48c858a6da", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 28699, "upload_time": "2019-03-08T04:57:15", "url": "https://files.pythonhosted.org/packages/94/44/f1a4c707ebae736acd78a56f40cd037d87d6e2b3814401e6842e7e62d90b/graphrole-1.0.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "a94bddedf42116ff25dc2128e083b749", "sha256": "dbadb0defc0e06ee7a916bd474ae130ccf9681f3f6099d2382831968a086fd4b" }, "downloads": -1, "filename": "graphrole-1.0.0.tar.gz", "has_sig": false, "md5_digest": "a94bddedf42116ff25dc2128e083b749", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 20577, "upload_time": "2019-03-08T04:57:17", "url": "https://files.pythonhosted.org/packages/f7/d1/ca7486a731a6667bae1418c8d056c30b9a02e3c3e4382f716a3038579845/graphrole-1.0.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "a6f3eec806bcb22568395c48c858a6da", "sha256": "ee4892dced05e6383360ad3c50248c22e20b3e41f887a7116ac15df4cc077305" }, "downloads": -1, "filename": "graphrole-1.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "a6f3eec806bcb22568395c48c858a6da", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 28699, "upload_time": "2019-03-08T04:57:15", "url": "https://files.pythonhosted.org/packages/94/44/f1a4c707ebae736acd78a56f40cd037d87d6e2b3814401e6842e7e62d90b/graphrole-1.0.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "a94bddedf42116ff25dc2128e083b749", "sha256": "dbadb0defc0e06ee7a916bd474ae130ccf9681f3f6099d2382831968a086fd4b" }, "downloads": -1, "filename": "graphrole-1.0.0.tar.gz", "has_sig": false, "md5_digest": "a94bddedf42116ff25dc2128e083b749", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 20577, "upload_time": "2019-03-08T04:57:17", "url": "https://files.pythonhosted.org/packages/f7/d1/ca7486a731a6667bae1418c8d056c30b9a02e3c3e4382f716a3038579845/graphrole-1.0.0.tar.gz" } ] }