Piecewise-regression is a Python library for performing segmented (or piecewise) regression analysis. It allows fitting models with one or more breakpoints, identifying where the relationship between independent and dependent variables changes. The current version is 1.5.0, with a moderate release cadence focused on statistical improvements and convenience features.
pip install piecewise-regressionVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to generate synthetic data with a breakpoint, initialize the `PiecewiseRegression` model, fit it to the data, and then visualize the results. It highlights the core workflow from data preparation to model interpretation.
Be aware that statistical results related to breakpoint significance might differ. Refer to the v1.5.0 release notes and cited literature (Muggeo, 2008) for details on the new methodology.
Start with a reasonable number based on domain knowledge or visual inspection of the data. Use statistical tests provided by the library (e.g., Davies test for 1 breakpoint) or information criteria (e.g., AIC, BIC) for model selection, though these are not directly implemented for breakpoint count in the library itself.
Inspect any warnings during the `fit()` process. Consider pre-processing your data, checking for outliers, or experimenting with different `n_breakpoints` values. Ensure your data distribution is suitable for linear regression segments.