Skip to main content

NSPPK

Documentation

Neighbourhood Subgraph Pairwise Pathway Kernel (NSPPK) converts labeled NetworkX graphs into fixed-width graph or node feature vectors for use with scikit-learn models.

Install

Python 3.10 or newer is required. Install NSPPK from PyPI with:

python -m pip install nsppk

For local development from a checkout, use editable mode instead:

python -m pip install -e .

This installs the core dependencies. Optional source readers need extra packages:

  • SMILES and SDF: pip install rdkit
  • PyTorch Geometric files: install PyTorch for your platform, then pip install torch_geometric. See the PyTorch installation guide and PyG installation guide for compatible platform and accelerator commands.

These optional packages are not installed with NSPPK.

Quick start

Create simple undirected NetworkX graphs. Node and edge labels are optional; missing labels are treated as 0 during encoding.

import networkx as nx
from nsppk import NSPPK, NodeNSPPK


def labeled_graph(node_labels, edges):
    graph = nx.Graph()
    graph.add_nodes_from(
        (node_id, {"label": label})
        for node_id, label in enumerate(node_labels)
    )
    graph.add_edges_from(
        (u, v, {"label": "bond"})
        for u, v in edges
    )
    return graph


graphs = [
    labeled_graph(["C", "O", "C"], [(0, 1), (1, 2)]),
    labeled_graph(["C", "N", "C"], [(0, 1), (1, 2)]),
    labeled_graph(["O", "C", "O"], [(0, 1), (1, 2)]),
]

encoder = NSPPK(nbits=8, dense=False, parallel=False)
X = encoder.fit_transform(graphs)
print(X.shape)  # (3, 256)

NSPPK returns one feature row per graph. With no continuous node attributes and the default graph-level mode, the width is 2 ** nbits. dense=False returns a SciPy sparse matrix; the default dense=True returns a NumPy array.

For node-level vectors, use NodeNSPPK. Its output is a list with one node-by-feature matrix per input graph:

node_encoder = NodeNSPPK(nbits=8, dense=False, parallel=False)
node_features = node_encoder.fit_transform(graphs)
print(node_features[0].shape)  # (number of nodes in graphs[0], 256)

Rows follow each graph’s graph.nodes() iteration order. See the API reference for graph requirements, parameter meanings, and output shapes.

For supervised learning directly from graph lists, use NSPPKClassifier or NSPPKRegressor. Both accept any compatible scikit-learn estimator, with "linear" and "rf" shortcuts:

from nsppk import NSPPKClassifier

classifier = NSPPKClassifier(
    estimator="linear",
    estimator_params={"C": 0.5},
    nbits=14,
    parallel=False,
)
classifier.fit(train_graphs, y_train)
predictions = classifier.predict(test_graphs)

The "linear" shortcut uses logistic regression for classification and Ridge regression for regression. The "rf" shortcut uses the corresponding random forest. See the API reference for custom estimators and parameter options.

Documentation

Examples

Runnable notebooks are in notebooks/:

  • Demo.ipynb: graph-level feature extraction
  • Importance Demo.ipynb: node and edge importance on a synthetic dataset
  • Streaming Benchmark.ipynb: loading and streaming examples
  • Molecular Graph Learning Curve.ipynb, Molecular Graph nbits Benchmark.ipynb, and Molecular Graph Speed Benchmark.ipynb: molecular graph experiments
  • NSPPK Classifier Benchmark.ipynb: compare the linear and rf supervised estimator shortcuts on HIV

Some notebooks require optional chemistry or machine-learning packages beyond NSPPK’s core dependencies. The graph readers and their optional requirements are documented in IO.md.

Citation

The repository’s Zenodo DOI is 10.5281/zenodo.14261713.

Metadata

Release files for nsppk 1.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nsppk 1.3.1
File Size Uploaded Provenance Actions
nsppk-1.3.1.tar.gz 35.3 kB With provenance Details for nsppk-1.3.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for nsppk 1.3.1
File Interpreter ABI Platform Actions
nsppk-1.3.1-py3-none-any.whl Python 3 none any Details for nsppk-1.3.1-py3-none-any.whl

Total release size: 64.2 kB

Release files / nsppk-1.3.1.tar.gz

Download URL nsppk-1.3.1.tar.gz
Size 35.3 kB
Tags Source
SHA-256 checksum
How to use checksums
8f58a76ad8e37b68886ed0dfa9f48096e228b00a609ea01781c4a855e8baf9b8
BLAKE2b-256 checksum
How to use checksums
e1ffc767e1743cb49e6c837458ec8a66fc794fdc31e862abad35abfa421874af
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

Release files / nsppk-1.3.1-py3-none-any.whl

Download URL nsppk-1.3.1-py3-none-any.whl
Size 28.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3429fcbbcc1b719c198eaaebb6652229697caba2a2f790e9ec672ecaa8fbd468
BLAKE2b-256 checksum
How to use checksums
e72d8020c41bdca0f5939ee5149f63587a8dcdf7cbc67777ed064a4a4d78150f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

Security for nsppk 1.3.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for nsppk-1.3.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page