3
$\begingroup$

This is my first post. I am trying my best to follow all the "how to ask a question" guidelines and hopefully my question will be clear.

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). enter image description here

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.] enter image description here enter image description here

$\endgroup$
0

1 Answer 1

1
$\begingroup$

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.

$\endgroup$
3
  • $\begingroup$ Thank you David for your reply and nicely explaining why "That is not a good model of your dataset". I am aware that what I am doing is not linear-regression. What I meant to say is, I want to do Two-phase linear regression because I am not happy with the result of what I am doing and I am looking for a python package that can do a Two-phase linear regression. (probably it was not clear in my question). $\endgroup$ Commented Oct 26, 2022 at 9:16
  • $\begingroup$ @BidyutBikashGoswami Look into scikit learn for two phase linear regression. $\endgroup$ Commented Oct 26, 2022 at 9:38
  • $\begingroup$ The package in question (ruptures) could probably do what you want as well. It has a custom model option. $\endgroup$ Commented Oct 26, 2022 at 11:57

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.