Skip to main content

Similarity-Based Stratified Splitting Algorithm

Project description

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).

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

sbss-0.0.6.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

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

sbss-0.0.6-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file sbss-0.0.6.tar.gz.

File metadata

  • Download URL: sbss-0.0.6.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for sbss-0.0.6.tar.gz
Algorithm Hash digest
SHA256 42fbea0caae8b6686157dab9211b5e5674fafda0d9490479b664e98f53327391
MD5 ee317b468826c72a227bb576d9c384a1
BLAKE2b-256 033c4d211c1565a7ab50d48a95b2851bba4a5f15670db7be3fa321988a864c6e

See more details on using hashes here.

File details

Details for the file sbss-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: sbss-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for sbss-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 bfb119051ac4c40115861752fbbde7ab985422219e10fe330a8d2a33d33385b1
MD5 becff6c60fb86c5f4f337f3795fb0dfa
BLAKE2b-256 0f6376a062af3a33abca0adc2054edee402e067c0e100e6e8263a50861e9bffb

See more details on using hashes here.

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