3

Assume the time series X_t is given. Is there any already implemented python function for finding best piecewise constant (not linear in general) approximation for it? Ideally dependent on the number of breaks.

UPD Once again, it differs from How to apply piecewise linear fit in Python?, because I need specifically constant piecewise approximation (curve fit!) with k=0 with given number of breaks.

1 Answers1

0

Would this from numpy work?

You can do something like,

x = np.linspace(-2.5, 2.5, 6)
np.piecewise(x, [x < 0, x >= 0], [-1, 1])

Hope this helps.

devdob
  • 1,404
  • 12
  • 13