A piecewise linear regression algorithm implemented in MATLAB. It uses dynamic programming to find the set of line segments with the lowest cost (sum of squared errors + λ × number of line segments).
- Sort the points by x-coordinate.
- Calculate the regression parameters (b0, b1) and sum of squared errors for every combination of leftmost and rightmost points.
- For k from 1 to the number of points, find the subsolution with the lowest cost.
- Work backwards to find the combination of line segments with the lowest cost.
Copyright © 2017 Aidan Fitzgerald, GPL 3.0.