sbss 0.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- sbss-0.0.1/LICENSE +21 -0
- sbss-0.0.1/PKG-INFO +62 -0
- sbss-0.0.1/README.md +49 -0
- sbss-0.0.1/sbss/sbss.egg-info/PKG-INFO +62 -0
- sbss-0.0.1/sbss/sbss.egg-info/SOURCES.txt +9 -0
- sbss-0.0.1/sbss/sbss.egg-info/dependency_links.txt +1 -0
- sbss-0.0.1/sbss/sbss.egg-info/requires.txt +1 -0
- sbss-0.0.1/sbss/sbss.egg-info/top_level.txt +1 -0
- sbss-0.0.1/setup.cfg +4 -0
- sbss-0.0.1/setup.py +28 -0
- sbss-0.0.1/tests/test_sbss.py +72 -0
sbss-0.0.1/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 tim
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
sbss-0.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: sbss
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Similarity-Based Stratified Splitting Algorithm
|
|
5
|
+
Home-page: https://github.com/timothyckl/similarity-stratified-split
|
|
6
|
+
Author: timothyckl
|
|
7
|
+
Author-email: timothy.ckl@outlook.com
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
|
|
14
|
+
# Similarity Stratified Split
|
|
15
|
+
|
|
16
|
+
Implementation of the Similarity-Based Stratified Splitting algorithm described in [Similarity Based Stratified Splitting: an approach to train better classifiers](https://arxiv.org/abs/2010.06099).
|
|
17
|
+
|
|
18
|
+
## Overview
|
|
19
|
+
|
|
20
|
+
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.
|
|
21
|
+
|
|
22
|
+
## Install
|
|
23
|
+
|
|
24
|
+
<!-- **PyPI**
|
|
25
|
+
```bash
|
|
26
|
+
pip install sbss
|
|
27
|
+
``` -->
|
|
28
|
+
|
|
29
|
+
**Local**
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
git clone https://github.com/timothyckl/similarity-stratified-split.git
|
|
33
|
+
cd ./similarity-stratified-split
|
|
34
|
+
pip install -e .
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Usage
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
import numpy as np
|
|
41
|
+
from scipy.spatial import distance
|
|
42
|
+
from sbss import SimilarityStratifiedSplit
|
|
43
|
+
|
|
44
|
+
def get_distances(x):
|
|
45
|
+
distances = distance.squareform(distance.pdist(x, metric='euclidean'))
|
|
46
|
+
return distances
|
|
47
|
+
|
|
48
|
+
# inputs are recommended to be normalized
|
|
49
|
+
X = np.random.rand(1000, 128)
|
|
50
|
+
y = np.random.randint(0, 10, (1000,))
|
|
51
|
+
|
|
52
|
+
n_splits = 3
|
|
53
|
+
s = SimilarityStratifiedSplit(n_splits, get_distances)
|
|
54
|
+
|
|
55
|
+
for train_index, test_index in s.split(X, y):
|
|
56
|
+
print(f"Train indices: {train_index}\nTest indices: {test_index}")
|
|
57
|
+
print("="*100)
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## References
|
|
61
|
+
|
|
62
|
+
- 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).
|
sbss-0.0.1/README.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# Similarity Stratified Split
|
|
2
|
+
|
|
3
|
+
Implementation of the Similarity-Based Stratified Splitting algorithm described in [Similarity Based Stratified Splitting: an approach to train better classifiers](https://arxiv.org/abs/2010.06099).
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
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.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
<!-- **PyPI**
|
|
12
|
+
```bash
|
|
13
|
+
pip install sbss
|
|
14
|
+
``` -->
|
|
15
|
+
|
|
16
|
+
**Local**
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
git clone https://github.com/timothyckl/similarity-stratified-split.git
|
|
20
|
+
cd ./similarity-stratified-split
|
|
21
|
+
pip install -e .
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
```python
|
|
27
|
+
import numpy as np
|
|
28
|
+
from scipy.spatial import distance
|
|
29
|
+
from sbss import SimilarityStratifiedSplit
|
|
30
|
+
|
|
31
|
+
def get_distances(x):
|
|
32
|
+
distances = distance.squareform(distance.pdist(x, metric='euclidean'))
|
|
33
|
+
return distances
|
|
34
|
+
|
|
35
|
+
# inputs are recommended to be normalized
|
|
36
|
+
X = np.random.rand(1000, 128)
|
|
37
|
+
y = np.random.randint(0, 10, (1000,))
|
|
38
|
+
|
|
39
|
+
n_splits = 3
|
|
40
|
+
s = SimilarityStratifiedSplit(n_splits, get_distances)
|
|
41
|
+
|
|
42
|
+
for train_index, test_index in s.split(X, y):
|
|
43
|
+
print(f"Train indices: {train_index}\nTest indices: {test_index}")
|
|
44
|
+
print("="*100)
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## References
|
|
48
|
+
|
|
49
|
+
- 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).
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: sbss
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Similarity-Based Stratified Splitting Algorithm
|
|
5
|
+
Home-page: https://github.com/timothyckl/similarity-stratified-split
|
|
6
|
+
Author: timothyckl
|
|
7
|
+
Author-email: timothy.ckl@outlook.com
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
|
|
14
|
+
# Similarity Stratified Split
|
|
15
|
+
|
|
16
|
+
Implementation of the Similarity-Based Stratified Splitting algorithm described in [Similarity Based Stratified Splitting: an approach to train better classifiers](https://arxiv.org/abs/2010.06099).
|
|
17
|
+
|
|
18
|
+
## Overview
|
|
19
|
+
|
|
20
|
+
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.
|
|
21
|
+
|
|
22
|
+
## Install
|
|
23
|
+
|
|
24
|
+
<!-- **PyPI**
|
|
25
|
+
```bash
|
|
26
|
+
pip install sbss
|
|
27
|
+
``` -->
|
|
28
|
+
|
|
29
|
+
**Local**
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
git clone https://github.com/timothyckl/similarity-stratified-split.git
|
|
33
|
+
cd ./similarity-stratified-split
|
|
34
|
+
pip install -e .
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Usage
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
import numpy as np
|
|
41
|
+
from scipy.spatial import distance
|
|
42
|
+
from sbss import SimilarityStratifiedSplit
|
|
43
|
+
|
|
44
|
+
def get_distances(x):
|
|
45
|
+
distances = distance.squareform(distance.pdist(x, metric='euclidean'))
|
|
46
|
+
return distances
|
|
47
|
+
|
|
48
|
+
# inputs are recommended to be normalized
|
|
49
|
+
X = np.random.rand(1000, 128)
|
|
50
|
+
y = np.random.randint(0, 10, (1000,))
|
|
51
|
+
|
|
52
|
+
n_splits = 3
|
|
53
|
+
s = SimilarityStratifiedSplit(n_splits, get_distances)
|
|
54
|
+
|
|
55
|
+
for train_index, test_index in s.split(X, y):
|
|
56
|
+
print(f"Train indices: {train_index}\nTest indices: {test_index}")
|
|
57
|
+
print("="*100)
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## References
|
|
61
|
+
|
|
62
|
+
- 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).
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
numpy==1.23.5
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
sbss-0.0.1/setup.cfg
ADDED
sbss-0.0.1/setup.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
from setuptools import find_packages, setup
|
|
2
|
+
|
|
3
|
+
with open("./README.md", "r") as f:
|
|
4
|
+
long_desc = f.read()
|
|
5
|
+
|
|
6
|
+
setup(
|
|
7
|
+
name="sbss",
|
|
8
|
+
version="0.0.1",
|
|
9
|
+
description="Similarity-Based Stratified Splitting Algorithm",
|
|
10
|
+
package_dir={"": "sbss"},
|
|
11
|
+
packages=find_packages(where="sbss"),
|
|
12
|
+
long_description=long_desc,
|
|
13
|
+
long_description_content_type='text/markdown',
|
|
14
|
+
url="https://github.com/timothyckl/similarity-stratified-split",
|
|
15
|
+
author="timothyckl",
|
|
16
|
+
author_email="timothy.ckl@outlook.com",
|
|
17
|
+
license="",
|
|
18
|
+
classifiers=[
|
|
19
|
+
"License :: OSI Approved :: MIT License",
|
|
20
|
+
"Programming Language :: Python :: 3.9",
|
|
21
|
+
"Operating System :: OS Independent"
|
|
22
|
+
],
|
|
23
|
+
install_requires=["numpy==1.23.5"],
|
|
24
|
+
extra_require={
|
|
25
|
+
"dev": ["pytest==7.4.3"]
|
|
26
|
+
},
|
|
27
|
+
python_require=">=3.9"
|
|
28
|
+
)
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
import numpy as np
|
|
3
|
+
from sbss import SimilarityStratifiedSplit
|
|
4
|
+
|
|
5
|
+
def sample_sim_func(X):
|
|
6
|
+
# Example similarity function returning random values for each pair of samples
|
|
7
|
+
n_samples = X.shape[0]
|
|
8
|
+
return np.random.rand(n_samples, n_samples)
|
|
9
|
+
|
|
10
|
+
class TestSimilarityStratifiedSplit:
|
|
11
|
+
@staticmethod
|
|
12
|
+
def test_init():
|
|
13
|
+
splitter = SimilarityStratifiedSplit(n_splits=3, sim_func=sample_sim_func, shuffle=True)
|
|
14
|
+
assert splitter.n_splits == 3
|
|
15
|
+
assert splitter.sim_func == sample_sim_func
|
|
16
|
+
assert splitter.shuffle is True
|
|
17
|
+
|
|
18
|
+
@staticmethod
|
|
19
|
+
def test_get_n_splits():
|
|
20
|
+
splitter = SimilarityStratifiedSplit(n_splits=5, sim_func=sample_sim_func)
|
|
21
|
+
assert splitter.get_n_splits() == 5
|
|
22
|
+
|
|
23
|
+
@staticmethod
|
|
24
|
+
def test_shuffle_dataset():
|
|
25
|
+
splitter = SimilarityStratifiedSplit(n_splits=2, sim_func=sample_sim_func, shuffle=True)
|
|
26
|
+
X = np.array([[1, 2], [3, 4], [5, 6], [7, 8]])
|
|
27
|
+
y = np.array([0, 1, 0, 1])
|
|
28
|
+
shuffled_X, shuffled_y = splitter._shuffle_dataset(X, y)
|
|
29
|
+
assert len(shuffled_X) == len(X)
|
|
30
|
+
assert len(shuffled_y) == len(y)
|
|
31
|
+
|
|
32
|
+
@staticmethod
|
|
33
|
+
def test_validate():
|
|
34
|
+
splitter = SimilarityStratifiedSplit(n_splits=4, sim_func=sample_sim_func)
|
|
35
|
+
class_counts = np.array([3, 2])
|
|
36
|
+
min_samples_per_class = 2
|
|
37
|
+
with pytest.raises(ValueError):
|
|
38
|
+
splitter._validate(class_counts, min_samples_per_class)
|
|
39
|
+
|
|
40
|
+
@staticmethod
|
|
41
|
+
def test_encode_labels():
|
|
42
|
+
splitter = SimilarityStratifiedSplit(n_splits=2, sim_func=sample_sim_func)
|
|
43
|
+
y = np.array([1, 2, 3, 1, 2, 3])
|
|
44
|
+
num_classes = splitter._encode_labels(y)
|
|
45
|
+
assert num_classes == 3
|
|
46
|
+
|
|
47
|
+
@staticmethod
|
|
48
|
+
def test_split():
|
|
49
|
+
splitter = SimilarityStratifiedSplit(n_splits=2, sim_func=sample_sim_func)
|
|
50
|
+
X = np.array([[1, 2], [3, 4], [5, 6], [7, 8]])
|
|
51
|
+
y = np.array([0, 1, 0, 1])
|
|
52
|
+
splits = list(splitter.split(X, y))
|
|
53
|
+
assert len(splits) == 2
|
|
54
|
+
for train_indices, test_indices in splits:
|
|
55
|
+
assert len(train_indices) + len(test_indices) == len(X)
|
|
56
|
+
assert len(np.intersect1d(train_indices, test_indices)) == 0
|
|
57
|
+
|
|
58
|
+
@staticmethod
|
|
59
|
+
def test_validate_pass():
|
|
60
|
+
splitter = SimilarityStratifiedSplit(n_splits=2, sim_func=sample_sim_func)
|
|
61
|
+
class_counts = np.array([3, 2])
|
|
62
|
+
min_samples_per_class = 2
|
|
63
|
+
splitter._validate(class_counts, min_samples_per_class)
|
|
64
|
+
assert True
|
|
65
|
+
|
|
66
|
+
@staticmethod
|
|
67
|
+
def test_validate_fail():
|
|
68
|
+
splitter = SimilarityStratifiedSplit(n_splits=4, sim_func=sample_sim_func)
|
|
69
|
+
class_counts = np.array([3, 2])
|
|
70
|
+
min_samples_per_class = 2
|
|
71
|
+
with pytest.raises(ValueError):
|
|
72
|
+
splitter._validate(class_counts, min_samples_per_class)
|