There is a blog post with a recursive implementation of piecewise regression. That solution fits discontinuous regression. If you are unsatisfied with discontinuous model and want continuous seting, I would propose to look for your curve in a basis of k L-shaped curves, using Lasso for sparsity:. import numpy as np import matplotlib.pyplot as plt from sklearn.linear_model import Lasso ... More @Wikipedia
Hover over any link to get a description of the article. Please note that search keywords are sometimes hidden within the full article and don't appear in the description or title.