--- id: piecewise-regression version: "1.5.0" license: MIT license_treatment: permissive maintenance: dormant --- # piecewise-regression — piecewise (segmented) regression in python License: permissive · Maintenance: dormant · Downloads: 133.8K/mo ## What it is and what it does Piecewise-regression implements Muggeo's iterative algorithm to fit piecewise linear models—straight lines with one or more breakpoints where the slope changes. You provide x and y data plus either initial breakpoint guesses or a desired number of breakpoints, and the package estimates the segment gradients, breakpoint positions, and confidence intervals for all parameters. It includes a Davies test to assess whether breakpoints exist statistically. The package uses bootstrap restarting to escape local optima and improve the chance of finding a global solution, though convergence is not guaranteed. It also offers a ModelSelection tool based on Bayesian Information Criterion (BIC) to compare models with different numbers of breakpoints. Results can be extracted as structured data or plotted with matplotlib for visualization of the fit, breakpoints, and confidence bands. Use it for: - Detect and quantify shifts in trend in time-series data, such as changes in growth rate before and after a policy intervention. - Identify optimal threshold points in dose-response or dose-effect studies where biological or physical response changes slope. - Analyze piecewise relationships in economic or environmental data where structural breaks occur at known or unknown transition points. - Compare competing segmented models using BIC to select the number of breakpoints that best explains the data. - Extract confidence intervals around estimated breakpoint positions for hypothesis testing or uncertainty quantification. ## Worth the install? AI-flagged interpretation of the facts above — verify before relying. Fits piecewise linear regression models to data with one or more breakpoints, estimating segment gradients and breakpoint positions with confidence intervals. Yes, if you need to fit piecewise linear models with statistical inference. The package is well-maintained enough (last commit mid-2024), has no known vulnerabilities, and low install friction. Dormant status is not a blocker for a stable, narrowly-scoped tool. Install with caution if you require active development or frequent updates; for one-off analysis or established workflows, it is reliable. ## Install pip install piecewise-regression uv add piecewise-regression poetry add piecewise-regression ## Installing piecewise-regression Before you install: Low install friction with a pure Python wheel and four standard scientific dependencies (numpy, scipy, matplotlib, statsmodels). Maintenance is dormant—last release was 2023-12-18 and last commit 2024-06-09—but the repository remains active and unarchived. License in practice: MIT license is permissive; you can use, modify, and distribute this package freely in commercial and private projects with minimal restrictions. Quickstart: pip install piecewise-regression import piecewise_regression import numpy as np x = np.linspace(0, 20, 100) y = 100 - 4*x + 2*np.maximum(x - 7, 0) + np.random.normal(size=100) pw_fit = piecewise_regression.Fit(x, y, n_breakpoints=1) pw_fit.summary() Verify before relying: - Whether the package handles edge cases (e.g., collinear data, very few observations) gracefully or requires specific data characteristics. - Performance characteristics on large datasets or high-dimensional breakpoint searches. - Whether bootstrap restarting convergence guarantees improve with specific parameter tuning beyond n_boot. ## Package facts - License: MIT (permissive) - Python support: unspecified - Install friction: low - Maintenance: dormant - Downloads: 133.8K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags piecewise linear regression, segmented regression breakpoints, fitting lines with breakpoints, regression model breakpoint detection, multi-segment linear fitting, change point regression, segmented line fitting, regression-analysis, statistical-modeling, breakpoint-detection [View on SkillFed](https://skillfed.io/packages/piecewise-regression) · [View on PyPI](https://pypi.org/project/piecewise-regression/)