scikit-sampling 0.1.0__py3-none-any.whl
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.
@@ -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,6 @@
|
|
1
|
+
scikit_sampling-0.1.0.dist-info/licenses/LICENSE,sha256=BuRfz6RXIKQR8frB2PtJIz6R6wqIHKmvmGg1aHRCzLg,1089
|
2
|
+
sksampling/__init__.py,sha256=AUk6Srlfv6aBUbBzSis0cbVto4Y81615tUaq6QdAyBk,1331
|
3
|
+
scikit_sampling-0.1.0.dist-info/METADATA,sha256=eRHUEjZMsboHwx9cF_WRspW0tWLMO0SosentTT5fo4Q,2280
|
4
|
+
scikit_sampling-0.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
5
|
+
scikit_sampling-0.1.0.dist-info/top_level.txt,sha256=xE9a_qmMKqDdkQeQSUSgM-FZldsPmWeetW4RF1UgNsE,11
|
6
|
+
scikit_sampling-0.1.0.dist-info/RECORD,,
|
@@ -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 @@
|
|
1
|
+
sksampling
|
sksampling/__init__.py
ADDED
@@ -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))
|