A Python package for generating synthetic data.
Project description
📦 synker
synker is a Python package designed for generating synthetic datasets based on real data using kernel density estimation (KDE) methods. It supports bandwidth selection (Scott's and Silverman's rules), 2D KDE, synthetic data generation, and KL divergence evaluation between real and synthetic datasets.
🚀 Features
- Bandwidth Estimation: Scott's Rule and Silverman's Rule
- 2D Kernel Density Estimation
- Synthetic Data Generation based on KDE
- KL Divergence Calculation for model evaluation
- Modular design for easy extension and usage
🧠 Installation
Clone the repository and install the package locally:
git clone https://github.com/dhaselib/synker
cd synker
pip install .
🗂 Example Usage
import numpy as np
from synker.scott import Scott
from synker.silverman import Silverman
from synker.kde import KDE_2D
from synker.kl_div import KL_div
from synker.synthetic import Synthetic
# Generate sample data
np.random.seed(42)
data = np.random.weibull(a=2, size=(100, 2))
# Test Scott's bandwidth
hx = Scott(data[:, 0])
hy = Scott(data[:, 1])
print(f"Scott's Bandwidth hx: {hx}, hy: {hy}")
# Test Silverman's bandwidth
hx_sil = Silverman(data[:, 0])
hy_sil = Silverman(data[:, 1])
print(f"Silverman's Bandwidth hx: {hx_sil}, hy: {hy_sil}")
# Test KDE
grid_x = np.linspace(data[:, 0].min(), data[:, 0].max(), 100)
grid_y = np.linspace(data[:, 1].min(), data[:, 1].max(), 100)
density = KDE_2D(data[:, 0], data[:, 1], grid_x, grid_y, hx, hy)
print(f"KDE Density Shape: {density.shape}")
# Test Synthetic
Synth_data = Synthetic(data, hx=hx, hy=hy, grid_x=grid_x, grid_y=grid_y, n_samples=100)
print(f"Synthetic Data Shape: {Synth_data.shape}")
# Test KL Divergence
kl = KL_div(data, Synth_data, hx, hy)
print(f"KL Divergence (self): {kl}")
✅ Testing
We provide a test_synker.py file to test core functionalities like Scott's Rule, KDE, synthetic sampling, and KL divergence:
Run Tests:
python -m unittest test_synker.py
Tests Include:
- Scott and Silverman bandwidth estimation
- 2D KDE output validation
- Synthetic data shape and bounds
- Non-negative KL divergence check
📁 Project Structure
synker/
│
├── __init__.py
├── scott.py
├── silverman.py
├── kde.py
├── sampling.py
├── kl_divergence.py
├── tests/
│ └── test_synker.py
└── README.md
📜 License - MIT
MIT License
Copyright (c) 2025 Danial Haselibozchaloee
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file synker-0.0.2.tar.gz.
File metadata
- Download URL: synker-0.0.2.tar.gz
- Upload date:
- Size: 6.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
accd60b7ffb8a371a586f4e9ccd04ea2adbd36f6b8efdc743e940fee359ed2a8
|
|
| MD5 |
5e0d6ab78e6cb93b7d80a225267934ef
|
|
| BLAKE2b-256 |
856662e7107eece2d428ceb9fee1e31491b97a8e5d18deab0bcc0c42d8af5863
|
File details
Details for the file synker-0.0.2-py3-none-any.whl.
File metadata
- Download URL: synker-0.0.2-py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
19865f6ecd8e74dec86a9f11866c2b3c8bb7f1cccab0d99e60155a802cb09e51
|
|
| MD5 |
ccd43358bdcb986b32fe2047fcf8673b
|
|
| BLAKE2b-256 |
3c9ddbd0264d3ae5c5280f9c1a2cbcfdad746c003e963ab3ba276a81e1c3e593
|