tlf-regression-engine
Country-agnostic regression modeling — part of TLF ("The Living Facts").
Fits three types of regression models over any pandas DataFrame — linear, polynomial, and binary logistic — and returns each result as a plain dict with coefficients, standard errors, p-values, and a fit-quality metric (R² / adjusted R² / pseudo R²) behind it.
Unlike tlf-census-stats, this package has no dependency on a specific country schema — it works on any DataFrame with numeric predictor and target columns.
Built on statsmodels rather than raw linear algebra, so every result carries proper inferential statistics (standard errors, p-values) — the same level of rigor as the tests in tlf-hypothesis-testing and the correlations in tlf-correlation-engine, not just point estimates.
Install
pip install tlf-regression-engine
Or from source, inside the TLF-Data-Analysis monorepo:
cd tlf-regression-engine
pip install -e ".[dev]"
Usage
import pandas as pd
from tlf_regression_engine import RegressionEngine
df = pd.read_csv("census_data.csv")
# Linear: one or more numeric predictors
engine = RegressionEngine(df, regression="linear_regression")
engine.run(target="literacy_rate", predictors=["households", "avg_household_size"])
# Polynomial: single numeric predictor, curved fit
engine = RegressionEngine(df, regression="polynomial_regression")
engine.run(target="literacy_rate", predictor="households", degree=2)
# Logistic: binary target (exactly 2 distinct values), one or more numeric predictors
engine = RegressionEngine(df, regression="logistic_regression")
engine.run(target="is_urban_majority", predictors=["literacy_rate", "avg_household_size"])
Regression types
| Type | Column shape | Use for |
|---|---|---|
linear_regression |
target + predictors (1+ numeric columns) |
Ordinary least squares over one or more predictors |
polynomial_regression |
target + predictor (1 numeric column) + degree |
Curved (non-linear) fit against a single predictor |
logistic_regression |
target (exactly 2 distinct values) + predictors (1+ numeric columns) |
Binary classification / probability modeling |
Predictor columns must already be numeric — this package does not one-hot encode categorical predictors; encode those upstream (e.g. with pandas.get_dummies) before passing them in.
Every result includes coefficients, std_errors, p_values, and n (observations used, after dropping rows with nulls in any of the selected columns). linear_regression/polynomial_regression also include r2/adj_r2; logistic_regression includes pseudo_r2 (McFadden's pseudo R², via statsmodels).
A minimum of 3 complete observations per fitted parameter (predictors + intercept) is required, or InsufficientDataError is raised. Perfectly (or near-perfectly) collinear predictors — or, for logistic regression, predictors that perfectly separate the two classes — raise SingularMatrixError instead of returning a nonsensical fit.
CLI
tlf-regression-engine --data census.csv --regression linear_regression --target literacy_rate --predictors households,avg_household_size
Run with no flags at all for a fully interactive walkthrough (file path → sheet selection → regression type → target/predictor(s) → export format). Column prompts are dtype-aware: numeric columns are listed first, each annotated with its type and unique-value count (e.g. Literacy Rate (numeric, 8 unique)), though every column stays selectable either way.
tlf-regression-engine
For unattended/scripted runs, --yes disables all prompting and fails loudly (rather than silently guessing) if something required — like --data — is missing:
tlf-regression-engine --data census.csv --yes --regression polynomial_regression --target literacy_rate --predictor households --degree 2 --export json --export-path out.json
CLI flags
| Flag | Applies to | Notes |
|---|---|---|
--data |
all | CSV, Excel, or JSON path |
--sheet |
all | Excel sheet name (default: first sheet) |
--regression |
all | linear_regression / polynomial_regression / logistic_regression |
--target |
all | Target (dependent) column |
--predictors |
linear, logistic | Comma-separated column names, e.g. households,avg_household_size |
--predictor |
polynomial | Single column name |
--degree |
polynomial | Default: 2 |
--export / --export-path |
all | csv or json; extension auto-appended if omitted |
--yes |
all | Non-interactive mode |
License
MIT
Metadata
Release files for tlf-regression-engine 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tlf_regression_engine-0.1.0.tar.gz | 18.7 kB | Without provenance | Details for tlf_regression_engine-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tlf_regression_engine-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for tlf_regression_engine-0.1.0-py3-none-any.whl |
Total release size: 34.8 kB
Release files / tlf_regression_engine-0.1.0.tar.gz
| Download URL | tlf_regression_engine-0.1.0.tar.gz |
|---|---|
| Size | 18.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
60b9ff12314616868f593211f05cd815dd72239349c87fdb36141112216e6cbc
|
|
BLAKE2b-256 checksum How to use checksums |
cb6db5a7d864ae08f405c241b7f8d276ad567a594983045740099b49765a390d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.5
|
Release files / tlf_regression_engine-0.1.0-py3-none-any.whl
| Download URL | tlf_regression_engine-0.1.0-py3-none-any.whl |
|---|---|
| Size | 16.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0c477c1e06274f7fd6448ceb59974dd200da15bcb1d33fc73729e0459fdd4d46
|
|
BLAKE2b-256 checksum How to use checksums |
93bd66ca70d3403458a8d8c5c2702d7aeefbb759f4512fae703c8e9ebcc8ab10
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.5
|
Security for tlf-regression-engine 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.