Similarity Stratified Split
Implementation of the Similarity-Based Stratified Splitting algorithm described in Similarity Based Stratified Splitting: an approach to train better classifiers.
Overview
The authors propose a Similarity-Based Stratified Splitting (SBSS) technique, which uses both the output and input space information to split a dataset. Splits are generated using similarity functions among samples to place similar samples in different splits. This approach allows for a better representation of the data in the training phase. This strategy leads to a more realistic performance estimation when used in real-world applications.
Install
PyPI
pip install sbss
Local
git clone https://github.com/timothyckl/similarity-stratified-split.git
cd ./similarity-stratified-split
pip install -e .
Usage
import numpy as np
from scipy.spatial import distance
from sbss import SimilarityStratifiedSplit
def get_distances(x):
distances = distance.squareform(distance.pdist(x, metric='euclidean'))
return distances
# inputs are recommended to be normalized
X = np.random.rand(1000, 128)
y = np.random.randint(0, 10, (1000,))
n_splits = 3
s = SimilarityStratifiedSplit(n_splits, dist_func=get_distances)
for train_index, test_index in s.split(X, y):
print(f"Train indices: {train_index}\nTest indices: {test_index}")
print("="*100)
sklearn Compatibility
SimilarityStratifiedSplit is compatible with sklearn's cross-validation utilities. It can be passed directly to cross_val_score, GridSearchCV, and similar tools:
from sklearn.model_selection import cross_val_score
from sklearn.svm import SVC
splitter = SimilarityStratifiedSplit(n_splits=3, dist_func=get_distances)
cv_scores = cross_val_score(SVC(), X, y, cv=splitter)
Note that y is always required by the SBSS algorithm — passing y=None will raise a ValueError.
References
- Farias, F., Ludermir, T. and Bastos-Filho, C. (2020) Similarity based stratified splitting: An approach to train better classifiers, arXiv.org. Available at: https://arxiv.org/abs/2010.06099 (Accessed: 27 November 2023).
Metadata
Release files for sbss 0.0.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sbss-0.0.7.tar.gz | 6.9 kB | Without provenance | Details for sbss-0.0.7.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sbss-0.0.7-py3-none-any.whl | Python 3 | none | any | Details for sbss-0.0.7-py3-none-any.whl |
Total release size: 12.9 kB
Release files / sbss-0.0.7.tar.gz
| Download URL | sbss-0.0.7.tar.gz |
|---|---|
| Size | 6.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d750f7114ab8a806fe8e372533e963a44336757f29c3c5105ad126ae0773186a
|
|
BLAKE2b-256 checksum How to use checksums |
52ed1856d87ef25c10c1d93e882adb941b6544f0eb4380d9d58919a6b09895fd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.14
|
Release files / sbss-0.0.7-py3-none-any.whl
| Download URL | sbss-0.0.7-py3-none-any.whl |
|---|---|
| Size | 5.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
46392f9937e468be20f38cad614b92a9768f1d18bf1fef2538ef3faa6fecc5c3
|
|
BLAKE2b-256 checksum How to use checksums |
edd1148f6aa236f40fc91bbf16d16dd6727cc0c2d418349b15c41649a52923b9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.14
|
Security for sbss 0.0.7
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.