n-SBC: A novel machine learning model
Project description
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
- Basic usage: train, predict, evaluate with LOOCV
- Explainability: Z-matrix, feature importances, similarity plots
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nsbc-1.2.2.tar.gz.
File metadata
- Download URL: nsbc-1.2.2.tar.gz
- Upload date:
- Size: 21.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d354e8b8f26a5e40af11318b8c4b5f97baed4759d7fe118938b5ecd6d463ade5
|
|
| MD5 |
33056abd249b85d1b2b31dacc8368436
|
|
| BLAKE2b-256 |
4a7a40a93cfe506f927ce8ce69869ec968e1c21f595822b38d4b2f6eb236e44b
|
Provenance
The following attestation bundles were made for nsbc-1.2.2.tar.gz:
Publisher:
publish.yml on valdolab/n-sbc
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nsbc-1.2.2.tar.gz -
Subject digest:
d354e8b8f26a5e40af11318b8c4b5f97baed4759d7fe118938b5ecd6d463ade5 - Sigstore transparency entry: 1631734385
- Sigstore integration time:
-
Permalink:
valdolab/n-sbc@bd19a6fd979e1b5c1d5b0ba2ee8ef0e0f38d5b5b -
Branch / Tag:
refs/tags/v1.2.2 - Owner: https://github.com/valdolab
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@bd19a6fd979e1b5c1d5b0ba2ee8ef0e0f38d5b5b -
Trigger Event:
release
-
Statement type:
File details
Details for the file nsbc-1.2.2-py3-none-any.whl.
File metadata
- Download URL: nsbc-1.2.2-py3-none-any.whl
- Upload date:
- Size: 19.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
63dc9dcfd0ebc4788d18fa3b966f142e8f0381a7cd1626c326285ba92f4fba2a
|
|
| MD5 |
3c48ac30304f777231306f3a2f652fbb
|
|
| BLAKE2b-256 |
015e4ac3b3f73abddf5203be688c7d3939bdc04cb3e133fa22f269a368dd75f4
|
Provenance
The following attestation bundles were made for nsbc-1.2.2-py3-none-any.whl:
Publisher:
publish.yml on valdolab/n-sbc
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nsbc-1.2.2-py3-none-any.whl -
Subject digest:
63dc9dcfd0ebc4788d18fa3b966f142e8f0381a7cd1626c326285ba92f4fba2a - Sigstore transparency entry: 1631734396
- Sigstore integration time:
-
Permalink:
valdolab/n-sbc@bd19a6fd979e1b5c1d5b0ba2ee8ef0e0f38d5b5b -
Branch / Tag:
refs/tags/v1.2.2 - Owner: https://github.com/valdolab
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@bd19a6fd979e1b5c1d5b0ba2ee8ef0e0f38d5b5b -
Trigger Event:
release
-
Statement type: