cjekel / piecewise_linear_fit_py

fit piecewise linear data for a specified number of line segments
MIT License
300 stars 60 forks source link

.fit() fails with 1 segment #100

Closed pabloslash closed 2 years ago

pabloslash commented 2 years ago

Is there a reason why the fit cannot be done for a single (1-segment) linear regression?

danhamill commented 2 years ago

I came across this the other day and am also interested in the answer.

cjekel commented 2 years ago

So the expected api would be able to do something like .fit(1)?

1 segment would be a special routine. You don't need the underlying optimization routine to move 'breakpoints' around.

I guess all the underlying mechanisms are there to support fits of 1 segment, I would just need to write this special routine, then query it when .fit() or .fitfast() were called.

cjekel commented 2 years ago

that routine would be

def fit_with_one_segment(self):
    self.fit_with_breaks([self.break_0, self.break_n])
cjekel commented 2 years ago

Thanks for the suggestion! I've added it to the code, and released a new version 2.2.1.

You can now do fit and fitfast for one line segment. In both cases, simple linear regression is applied.

pabloslash commented 2 years ago

Great improvement. Thanks!

On Sat, May 7, 2022 at 2:59 PM Charles Jekel @.***> wrote:

Thanks for the suggestion! I've added it to the code, and released a new version 2.2.1.

You can now do fit and fitfast for one line segment. In both cases, simple linear regression is applied.

— Reply to this email directly, view it on GitHub https://github.com/cjekel/piecewise_linear_fit_py/issues/100#issuecomment-1120301875, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABLELUQ7YSV3MGDQVBNM3DLVI3RULANCNFSM5VAJIXKA . You are receiving this because you authored the thread.Message ID: @.***>