Home > Software engineering >  Most computational-time efficient/fastest way to compute rolling (linear) regression in Python (Nump
Most computational-time efficient/fastest way to compute rolling (linear) regression in Python (Nump

Time:01-11

I have a need to do very very fast and efficient way of rolling linear regression. I looked through these two threads :

enter image description here

So, obviously, same results as roll_np (which, I've checked the same way, are the same results as the two others. With also the same variation on indexing since all 3 methods have not the same strategy for border)

And the interesting part, timings:

Method Time
pandas 2.10 s
numpy roll 2.03 s
stat 3.58 s
numpy view/vectorize 0.46 s

So, you see, it is not supposed to be for performance, and yet, I gain more that x4 times with it.

I am pretty sure that a more vectorized method (alas, lstsq doesn't allow directly it, unlike most numpy functions) would be even faster.

  • Related