Skip to main content

n-SBC: A novel machine learning model

Project description

n-SBC

PyPI Python License Paper

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}
}

License

MIT -- see LICENSE for details.

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

nsbc-1.2.1.tar.gz (21.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nsbc-1.2.1-py3-none-any.whl (19.4 kB view details)

Uploaded Python 3

File details

Details for the file nsbc-1.2.1.tar.gz.

File metadata

  • Download URL: nsbc-1.2.1.tar.gz
  • Upload date:
  • Size: 21.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for nsbc-1.2.1.tar.gz
Algorithm Hash digest
SHA256 0fff21f916068f4c6fee4df4688e82e6b7a1a9db837398b8ddea647a9864e7c2
MD5 648946ffa7c8469ad8a1fbd14e491744
BLAKE2b-256 65f41e2ed233c76b2fec9c2c0917c5f9d13cb438b38f7d7ea2dcb797e8650f14

See more details on using hashes here.

Provenance

The following attestation bundles were made for nsbc-1.2.1.tar.gz:

Publisher: publish.yml on valdolab/n-sbc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nsbc-1.2.1-py3-none-any.whl.

File metadata

  • Download URL: nsbc-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 19.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for nsbc-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 218b11a79c930d6633de16b3e1aa5ecfa4cd706e7de76f08181d9056277d9a75
MD5 fbea5bf24f64044aa9ef54124130f2ad
BLAKE2b-256 1b4ac697e97935eab62f1e07ed2dbd2ff269332de49fb0a181e2395bcee9e0ff

See more details on using hashes here.

Provenance

The following attestation bundles were made for nsbc-1.2.1-py3-none-any.whl:

Publisher: publish.yml on valdolab/n-sbc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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