I am trying to find the change of slope in a time series. I used the ruptures (for 2 break points using model = rpt.Dynp(model="l1"
) and this is what I got (please see the attached image).
I am not happy with the break point location. Based on my visual inspection of the data, I feel the break-point is earlier than what I am getting. I wanted to do a "Two-phase linear regression" to check my results. I found that there is a function available in Matlab. I am wondering if there is any python package available to do the same thing what this Matlab function does, because I know nothing about Matlab.
Thank you in advance for your inputs.
[If anyone is wondering what happens if I try to find 3 or 4 break-points in my data, instead of looking for 2 break-points, then please see the images below. I am still not happy with the first change point location.]
I wanted to do a "Two-phase linear regression" to check my results.
You aren't doing that. By specifying model="l1"
, you are asking the package to use a piecewise constant model (rather than a linear regression) for each segment. This models each segment as the mean of all the elements in that segment. The error is calculated as the sum of the absolute values of the difference between each element and the mean (the $L^1$ norm). Apparently asking for two breakpoints means one internal breakpoint, or two segments that collectively span the dataset.
That is not a good model of your dataset, and it is not a linear regression.