Skip to main content

n-SBC

PyPI Python License Paper Docs

n-SBC

A novel machine learning classifier based on Hamming similarity over Gray-coded binary representations. Scikit-learn compatible. n-SBC is a lazy learner: it stores the entire training set encoded as Gray-coded binary vectors. At prediction time, it computes the Hamming similarity between a new sample and every training sample, sums the top-u similarities per class, and predicts the class with the highest aggregate similarity. The Gray code encoding ensures that numerically close values differ by only one bit, preserving ordinal relationships in the binary representation.

Velazquez-Gonzalez, O., Alarcon-Paredes, A., & Yanez-Marquez, C. (2026). Medical pattern classification using a novel binary similarity approach based on an associative classifier. Frontiers in Artificial Intelligence, 8. DOI: 10.3389/frai.2025.1610856

Installation

pip install nsbc

Quick Start

from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from nsbc import NSBCClassifier

X, y = load_iris(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)

clf = NSBCClassifier(n_value=3, decimals=2, factor=10)
clf.fit(X_train, y_train)

print(f"Accuracy: {clf.score(X_test, y_test):.2%}")

Parameters

Parameter Type Default Description
n_value int 3 Number of top-u similar samples per class
decimals int 2 Decimal places for rounding during normalization
factor int 10 Multiplicative factor applied after rounding

Explainability

predict_explain() returns a ZMatrix with the full similarity matrix, per-class scores, and per-feature importances:

result = clf.predict_explain(X_test)

# Feature importances for a single prediction
imp = result.feature_importances[0]
order = np.argsort(-imp)
for i in order:
    print(f"{feature_names[i]}: {imp[i]:.4f}")

result.global_feature_importances

Visualize which training samples are most similar and why:

from nsbc.tools import plot_z_scores, plot_feature_importances

fig, ax = plot_z_scores(result, sample_idx=0, y_train=y_train)

# Global feature importances
fig, ax = plot_feature_importances(result, feature_names=feature_names)

Examples

Citation

If you use n-SBC in your research, please cite:

@article{velazquez2026nsbc,
  title={Medical pattern classification using a novel binary similarity approach based on an associative classifier},
  author={Velazquez-Gonzalez, Osvaldo and Alarc{\'o}n-Paredes, Antonio and Ya{\~n}ez-Marquez, Cornelio},
  journal={Frontiers in Artificial Intelligence},
  volume={8},
  year={2026},
  month={1},
  doi={10.3389/frai.2025.1610856}
}

Contributing

See CONTRIBUTING.md for guidelines on reporting bugs, suggesting features, and submitting pull requests.

License

MIT -- see LICENSE for details.

Metadata

Release files for nsbc 1.2.3

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

Source distribution (sdist)

Source distribution for nsbc 1.2.3
File Size Uploaded Provenance Actions
nsbc-1.2.3.tar.gz 21.3 kB With provenance Details for nsbc-1.2.3.tar.gz

Built distribution (wheel)

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

Total release size: 40.8 kB

Release files / nsbc-1.2.3.tar.gz

Download URL nsbc-1.2.3.tar.gz
Size 21.3 kB
Tags Source
SHA-256 checksum
How to use checksums
86d12cf52d6059c350097d490190071894ed90f0c9ad68f36e4543da913745b9
BLAKE2b-256 checksum
How to use checksums
d2cb706954cbf3fac0a0912518d2bc2c79fa6a09439b66a55643285fee1f4e16
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jun 4, 2026.

Transparency log

Release files / nsbc-1.2.3-py3-none-any.whl

Download URL nsbc-1.2.3-py3-none-any.whl
Size 19.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1d47d93b971066ad2e82e1b6e2fb0d824ba6cb7a530d12d480d7d379185d47bf
BLAKE2b-256 checksum
How to use checksums
2123022b0e9ed146a82f2a2321065fc761dfe6f66524d89eb6319d3f7dd98712
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jun 4, 2026.

Transparency log

Security for nsbc 1.2.3

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 nsbc-1.2.3.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 Jun 4, 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