Sequential tree models for tabular synthetic data generation
Project description
seqtrees
Sequential tree models for tabular synthetic data generation.
seqtrees is a small open source Python library for generating synthetic tabular
data with a sequential tree model. Its API follows familiar estimator naming
conventions:
from seqtrees import SequentialTreeSynthesizer
data = [
{"age": 24.5, "sex_code": 0, "income_bin": 1, "risk_code": 0},
{"age": 31.2, "sex_code": 1, "income_bin": 1, "risk_code": 0},
{"age": 67.4, "sex_code": 0, "income_bin": 3, "risk_code": 2},
{"age": 73.0, "sex_code": 1, "income_bin": 3, "risk_code": 2},
]
model = SequentialTreeSynthesizer(
variable_order=["age", "sex_code", "income_bin", "risk_code"],
tree_backend="auto",
continuous_strategy="empirical",
continuous_columns=["age"],
discrete_columns=["sex_code", "income_bin", "risk_code"],
n_jobs=-1,
random_state=7,
)
model.fit(data)
synthetic = model.sample(10)
The model factorizes a table into a sequence of conditional distributions:
P(X1, X2, ..., Xd) = P(X1) P(X2 | X1) ... P(Xd | X1, ..., Xd-1)
The first variable is sampled from its empirical marginal distribution. Each
later variable is sampled from a conditional decision tree trained on the
previous variables in the sequence. This mirrors the sequential data synthesis
workflow shown in Figure 1 of the attached paper (ocaa249.pdf).
SeqTrees expects model-ready, preprocessed data with no null values. It accepts only:
- continuous variables as floats;
- discrete variables as integer category codes, including binary 0/1 variables.
It does not encode raw categorical columns, and it is not intended for one-hot
encoded inputs. Categorical variables should be mapped before fit, for
example by your preprocessing library, and passed as stable integer codes or
bins such as sex_code, income_bin, and risk_code.
By default, all generated values are sampled from observed training values. For continuous float columns, you can opt into within-leaf interpolation:
model = SequentialTreeSynthesizer(
continuous_strategy="interpolate",
continuous_columns=["age", "bmi"],
discrete_columns=["sex_code", "income_bin", "risk_code"],
)
When type lists are supplied, continuous_columns and discrete_columns must
classify every input column exactly once.
Features
fit,sample, andfit_samplemethods.- User-specified variable ordering with
variable_order. - Greedy learned ordering with
optimize_order=True. - Parallel fitting and order-search candidates with
n_jobs. - Parallel row synthesis with
sample(..., n_jobs=...). - Optional LightGBM and scikit-learn backends with
tree_backend="lightgbm",tree_backend="sklearn", ortree_backend="auto". - Optional within-leaf interpolation for continuous float variables.
- Supports any number of preprocessed variables.
- Accepts lists of dictionaries, lists of row sequences, and pandas DataFrames when pandas is installed.
- Does not provide encoders, imputers, scalers, or category mapping utilities.
- Pure-Python core with no mandatory runtime dependencies.
- PlantUML diagrams in
docs/diagrams.
Install For Development
python -m venv .venv
source .venv/bin/activate
python -m pip install -e ".[dev]"
For faster compiled tree fitting:
python -m pip install -e ".[fast]"
For LightGBM only:
python -m pip install -e ".[lightgbm]"
To run the notebooks in examples/:
python -m pip install -e ".[examples]"
jupyter lab examples
Use all available cores:
model = SequentialTreeSynthesizer(tree_backend="lightgbm", n_jobs=-1)
Documentation
Start with docs/index.md. The package includes PlantUML source files for the training and sampling flow:
Build the documentation locally with MkDocs:
python -m venv .venv
source .venv/bin/activate
python -m pip install -e ".[docs]"
mkdocs serve
GitHub Pages documentation is published by .github/workflows/docs.yml when
changes land on main.
Release
Releases are published to PyPI by .github/workflows/publish.yml when a GitHub
Release is published. The workflow uses PyPI Trusted Publishing, so the PyPI
project needs a trusted publisher configured for:
- repository:
EulerLettersAI/seqtrees - workflow:
.github/workflows/publish.yml - environment:
pypi
References
- The implementation is based on the sequential synthetic data workflow
described in the attached paper (
ocaa249.pdf), especially the Figure 1 sequential data synthesis process. - Breiman, Friedman, Olshen, and Stone. Classification and Regression Trees. Wadsworth, 1984.
- Quinlan. "Induction of Decision Trees." Machine Learning, 1986.
Project details
Release history Release notifications | RSS feed
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 seqtrees-0.1.0.tar.gz.
File metadata
- Download URL: seqtrees-0.1.0.tar.gz
- Upload date:
- Size: 20.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aed80c1ab85616226e59db2011219123d53ec9b042970f4a2ec1cb3525c88036
|
|
| MD5 |
1399898289141359831b240c09351d22
|
|
| BLAKE2b-256 |
30716f6346dd302f7c59576d694738fe00a688a8dad651d75497f053b1b145b6
|
File details
Details for the file seqtrees-0.1.0-py3-none-any.whl.
File metadata
- Download URL: seqtrees-0.1.0-py3-none-any.whl
- Upload date:
- Size: 20.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e5f81d31a715911f9fc5be1aace976e7ec53fe3f78e0d0d601e38c66d8141c26
|
|
| MD5 |
a0a544e4ebf659ce14fc533c74cca88c
|
|
| BLAKE2b-256 |
ac417f67c4e5b7c42959ab9f6b60b19f75f1929f1ca080667dbc24b6c8d61eb6
|