scikit-sampling 0.1.0__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.
- scikit_sampling-0.1.0/LICENSE +21 -0
- scikit_sampling-0.1.0/PKG-INFO +60 -0
- scikit_sampling-0.1.0/README.md +36 -0
- scikit_sampling-0.1.0/pyproject.toml +50 -0
- scikit_sampling-0.1.0/scikit_sampling.egg-info/PKG-INFO +60 -0
- scikit_sampling-0.1.0/scikit_sampling.egg-info/SOURCES.txt +10 -0
- scikit_sampling-0.1.0/scikit_sampling.egg-info/dependency_links.txt +1 -0
- scikit_sampling-0.1.0/scikit_sampling.egg-info/requires.txt +4 -0
- scikit_sampling-0.1.0/scikit_sampling.egg-info/top_level.txt +1 -0
- scikit_sampling-0.1.0/setup.cfg +4 -0
- scikit_sampling-0.1.0/sksampling/__init__.py +44 -0
- scikit_sampling-0.1.0/tests/test_sampling.py +31 -0
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2025 Leonardo Moraes <leomaurodesenv>
|
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.
|
@@ -0,0 +1,60 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: scikit-sampling
|
3
|
+
Version: 0.1.0
|
4
|
+
Summary: A set of python modules for dataset sampling
|
5
|
+
Author-email: Leonardo Moraes <leomaurodesenv@users.noreply.github.com>
|
6
|
+
License-Expression: MIT
|
7
|
+
Classifier: Intended Audience :: Science/Research
|
8
|
+
Classifier: Intended Audience :: Developers
|
9
|
+
Classifier: Programming Language :: Python
|
10
|
+
Classifier: Topic :: Scientific/Engineering
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
17
|
+
Requires-Python: >=3.10
|
18
|
+
Description-Content-Type: text/markdown
|
19
|
+
License-File: LICENSE
|
20
|
+
Requires-Dist: scipy<2,>=1.15.0
|
21
|
+
Provides-Extra: build
|
22
|
+
Requires-Dist: setuptools<90,>=80.9.0; extra == "build"
|
23
|
+
Dynamic: license-file
|
24
|
+
|
25
|
+
# 🧪 Scikit-Sampling
|
26
|
+
|
27
|
+
[](https://github.com/leomaurodesenv/scikit-sampling)
|
28
|
+
[](LICENSE)
|
29
|
+
[](https://github.com/leomaurodesenv/scikit-sampling/actions/workflows/continuous-integration.yml)
|
30
|
+
|
31
|
+
|
32
|
+
Scikit-Sampling (or `sksampling`) is a Python library for dataset sampling techniques. It provides a unified API for common sampling strategies, making it easy to integrate into your data science and machine learning workflows.
|
33
|
+
|
34
|
+
## Installation
|
35
|
+
|
36
|
+
You can install `sksampling` using pip:
|
37
|
+
|
38
|
+
```bash
|
39
|
+
pip install scikit-sampling
|
40
|
+
```
|
41
|
+
|
42
|
+
## Features
|
43
|
+
|
44
|
+
`sksampling` offers a range of sampling methods, including:
|
45
|
+
|
46
|
+
- `sample_size`: Computes the ideal sample size based confidence level and interval.
|
47
|
+
|
48
|
+
## Usage
|
49
|
+
|
50
|
+
`sksampling` follows the `scikit-learn` API, making it intuitive to use.
|
51
|
+
|
52
|
+
```python
|
53
|
+
from sksampling import sample_size
|
54
|
+
|
55
|
+
# Example usage
|
56
|
+
population_size: int = 100_000
|
57
|
+
confidence_level: float = 0.95
|
58
|
+
confidence_interval: float = 0.02
|
59
|
+
sample_size(population_size, confidence_level, confidence_interval) # approx 2345
|
60
|
+
```
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# 🧪 Scikit-Sampling
|
2
|
+
|
3
|
+
[](https://github.com/leomaurodesenv/scikit-sampling)
|
4
|
+
[](LICENSE)
|
5
|
+
[](https://github.com/leomaurodesenv/scikit-sampling/actions/workflows/continuous-integration.yml)
|
6
|
+
|
7
|
+
|
8
|
+
Scikit-Sampling (or `sksampling`) is a Python library for dataset sampling techniques. It provides a unified API for common sampling strategies, making it easy to integrate into your data science and machine learning workflows.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
You can install `sksampling` using pip:
|
13
|
+
|
14
|
+
```bash
|
15
|
+
pip install scikit-sampling
|
16
|
+
```
|
17
|
+
|
18
|
+
## Features
|
19
|
+
|
20
|
+
`sksampling` offers a range of sampling methods, including:
|
21
|
+
|
22
|
+
- `sample_size`: Computes the ideal sample size based confidence level and interval.
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
`sksampling` follows the `scikit-learn` API, making it intuitive to use.
|
27
|
+
|
28
|
+
```python
|
29
|
+
from sksampling import sample_size
|
30
|
+
|
31
|
+
# Example usage
|
32
|
+
population_size: int = 100_000
|
33
|
+
confidence_level: float = 0.95
|
34
|
+
confidence_interval: float = 0.02
|
35
|
+
sample_size(population_size, confidence_level, confidence_interval) # approx 2345
|
36
|
+
```
|
@@ -0,0 +1,50 @@
|
|
1
|
+
[build-system]
|
2
|
+
requires = ["setuptools>=80.9.0,<90"]
|
3
|
+
build-backend = "setuptools.build_meta"
|
4
|
+
|
5
|
+
[project]
|
6
|
+
name = "scikit-sampling"
|
7
|
+
license = "MIT"
|
8
|
+
license-files = ["LICENSE"]
|
9
|
+
readme = "README.md"
|
10
|
+
version = "0.1.0"
|
11
|
+
requires-python = ">=3.10"
|
12
|
+
description = "A set of python modules for dataset sampling"
|
13
|
+
authors = [
|
14
|
+
{name = "Leonardo Moraes", email = "leomaurodesenv@users.noreply.github.com"}
|
15
|
+
]
|
16
|
+
classifiers=[
|
17
|
+
"Intended Audience :: Science/Research",
|
18
|
+
"Intended Audience :: Developers",
|
19
|
+
"Programming Language :: Python",
|
20
|
+
"Topic :: Scientific/Engineering",
|
21
|
+
"Development Status :: 4 - Beta",
|
22
|
+
"Programming Language :: Python :: 3",
|
23
|
+
"Programming Language :: Python :: 3.10",
|
24
|
+
"Programming Language :: Python :: 3.11",
|
25
|
+
"Programming Language :: Python :: 3.12",
|
26
|
+
"Programming Language :: Python :: 3.13",
|
27
|
+
]
|
28
|
+
|
29
|
+
dependencies = [
|
30
|
+
"scipy>=1.15.0,<2",
|
31
|
+
]
|
32
|
+
|
33
|
+
[project.optional-dependencies]
|
34
|
+
build = [
|
35
|
+
"setuptools>=80.9.0,<90",
|
36
|
+
]
|
37
|
+
|
38
|
+
[dependency-groups]
|
39
|
+
dev = [
|
40
|
+
"commitizen>=4.8.3,<5",
|
41
|
+
"pre-commit>=4.2.0,<5",
|
42
|
+
"pytest>=8.4.1,<9",
|
43
|
+
"pytest-cov>=6.2.1,<7",
|
44
|
+
]
|
45
|
+
|
46
|
+
[tool.pytest.ini_options]
|
47
|
+
pythonpath = [
|
48
|
+
"."
|
49
|
+
]
|
50
|
+
addopts = "--cov=sksampling --cov-report term-missing"
|
@@ -0,0 +1,60 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: scikit-sampling
|
3
|
+
Version: 0.1.0
|
4
|
+
Summary: A set of python modules for dataset sampling
|
5
|
+
Author-email: Leonardo Moraes <leomaurodesenv@users.noreply.github.com>
|
6
|
+
License-Expression: MIT
|
7
|
+
Classifier: Intended Audience :: Science/Research
|
8
|
+
Classifier: Intended Audience :: Developers
|
9
|
+
Classifier: Programming Language :: Python
|
10
|
+
Classifier: Topic :: Scientific/Engineering
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
17
|
+
Requires-Python: >=3.10
|
18
|
+
Description-Content-Type: text/markdown
|
19
|
+
License-File: LICENSE
|
20
|
+
Requires-Dist: scipy<2,>=1.15.0
|
21
|
+
Provides-Extra: build
|
22
|
+
Requires-Dist: setuptools<90,>=80.9.0; extra == "build"
|
23
|
+
Dynamic: license-file
|
24
|
+
|
25
|
+
# 🧪 Scikit-Sampling
|
26
|
+
|
27
|
+
[](https://github.com/leomaurodesenv/scikit-sampling)
|
28
|
+
[](LICENSE)
|
29
|
+
[](https://github.com/leomaurodesenv/scikit-sampling/actions/workflows/continuous-integration.yml)
|
30
|
+
|
31
|
+
|
32
|
+
Scikit-Sampling (or `sksampling`) is a Python library for dataset sampling techniques. It provides a unified API for common sampling strategies, making it easy to integrate into your data science and machine learning workflows.
|
33
|
+
|
34
|
+
## Installation
|
35
|
+
|
36
|
+
You can install `sksampling` using pip:
|
37
|
+
|
38
|
+
```bash
|
39
|
+
pip install scikit-sampling
|
40
|
+
```
|
41
|
+
|
42
|
+
## Features
|
43
|
+
|
44
|
+
`sksampling` offers a range of sampling methods, including:
|
45
|
+
|
46
|
+
- `sample_size`: Computes the ideal sample size based confidence level and interval.
|
47
|
+
|
48
|
+
## Usage
|
49
|
+
|
50
|
+
`sksampling` follows the `scikit-learn` API, making it intuitive to use.
|
51
|
+
|
52
|
+
```python
|
53
|
+
from sksampling import sample_size
|
54
|
+
|
55
|
+
# Example usage
|
56
|
+
population_size: int = 100_000
|
57
|
+
confidence_level: float = 0.95
|
58
|
+
confidence_interval: float = 0.02
|
59
|
+
sample_size(population_size, confidence_level, confidence_interval) # approx 2345
|
60
|
+
```
|
@@ -0,0 +1,10 @@
|
|
1
|
+
LICENSE
|
2
|
+
README.md
|
3
|
+
pyproject.toml
|
4
|
+
scikit_sampling.egg-info/PKG-INFO
|
5
|
+
scikit_sampling.egg-info/SOURCES.txt
|
6
|
+
scikit_sampling.egg-info/dependency_links.txt
|
7
|
+
scikit_sampling.egg-info/requires.txt
|
8
|
+
scikit_sampling.egg-info/top_level.txt
|
9
|
+
sksampling/__init__.py
|
10
|
+
tests/test_sampling.py
|
@@ -0,0 +1 @@
|
|
1
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
sksampling
|
@@ -0,0 +1,44 @@
|
|
1
|
+
import math
|
2
|
+
import scipy.stats as st
|
3
|
+
|
4
|
+
|
5
|
+
def _get_z_score(confidence_level: float) -> float:
|
6
|
+
"""
|
7
|
+
Retrieves the Z-score for a given confidence level.
|
8
|
+
|
9
|
+
Args:
|
10
|
+
confidence_level: The confidence level as a float (e.g., 0.95 for 95%).
|
11
|
+
|
12
|
+
Returns:
|
13
|
+
The Z-score for the given confidence level.
|
14
|
+
"""
|
15
|
+
return st.norm.ppf(1 - (1 - confidence_level) / 2)
|
16
|
+
|
17
|
+
|
18
|
+
def sample_size(
|
19
|
+
population_size: int,
|
20
|
+
confidence_level: float = 0.95,
|
21
|
+
confidence_interval: float = 0.02,
|
22
|
+
) -> int:
|
23
|
+
"""
|
24
|
+
Calculates the sample size for a finite population using Cochran's formula.
|
25
|
+
|
26
|
+
Args:
|
27
|
+
population_size: The total size of the population.
|
28
|
+
confidence_level: The desired confidence level (e.g., 0.95 for 95%).
|
29
|
+
confidence_interval: The desired confidence interval (margin of error).
|
30
|
+
Default is 0.02 (2%).
|
31
|
+
|
32
|
+
Returns:
|
33
|
+
The calculated sample size as an integer.
|
34
|
+
"""
|
35
|
+
|
36
|
+
# For sample size calculation, we assume the worst-case variance, where p=0.5
|
37
|
+
p = 0.5
|
38
|
+
z_score = _get_z_score(confidence_level)
|
39
|
+
# Calculate sample size for an infinite population
|
40
|
+
n_0 = (z_score**2 * p * (1 - p)) / (confidence_interval**2)
|
41
|
+
# Adjust sample size for the finite population
|
42
|
+
n = n_0 / (1 + (n_0 - 1) / population_size)
|
43
|
+
|
44
|
+
return int(math.ceil(n))
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import pytest
|
2
|
+
from sksampling import _get_z_score, sample_size
|
3
|
+
|
4
|
+
|
5
|
+
def test_sample_size_basic():
|
6
|
+
"""
|
7
|
+
Tests the sample_size function with a few known sets of inputs and
|
8
|
+
expected outputs.
|
9
|
+
"""
|
10
|
+
error_margin = 1
|
11
|
+
# Test case from original print statement
|
12
|
+
assert sample_size(100_000, 0.95, 0.02) == pytest.approx(2345, abs=error_margin)
|
13
|
+
# Test with a smaller population
|
14
|
+
assert sample_size(500, 0.95, 0.05) == pytest.approx(218, abs=error_margin)
|
15
|
+
# Test with higher confidence and smaller interval
|
16
|
+
assert sample_size(10_000, 0.99, 0.01) == pytest.approx(6239, abs=error_margin)
|
17
|
+
# Test with a very large population, approaching the infinite case
|
18
|
+
assert sample_size(1_000_000, 0.95, 0.05) == pytest.approx(385, abs=error_margin)
|
19
|
+
|
20
|
+
|
21
|
+
def test_z_score():
|
22
|
+
"""
|
23
|
+
Tests the _get_z_score helper function with common confidence levels.
|
24
|
+
"""
|
25
|
+
error_margin = 1e-2
|
26
|
+
# Z-score for 90% confidence level should be approximately 1.645
|
27
|
+
assert _get_z_score(0.90) == pytest.approx(1.645, abs=error_margin)
|
28
|
+
# Z-score for 95% confidence level should be approximately 1.96
|
29
|
+
assert _get_z_score(0.95) == pytest.approx(1.96, abs=error_margin)
|
30
|
+
# Z-score for 99% confidence level should be approximately 2.58
|
31
|
+
assert _get_z_score(0.99) == pytest.approx(2.58, abs=error_margin)
|