0
votes

This question is regarding curve fitting in python.

First, I would say that I do not know the curve fit function to insert into "curve_fit" function in the scipy library; therefore, I am trying to use a polyfit which is OK if I am interested in interpolation but my goal is to predict values at future points, in other words extrapolation.

I have attached a screenshot of a raw signal, smoothed and its polyfit result. enter image description hereIt has the correct poly order but still fails at extrapolation. My conclusion is that poly fit is not the right approach here, but I can not estimate the curve function. What are you thoughts?

Please note that this is not a distribution since the y values may keep slowly decreasing infinitely, even below 0.

I'd say the function looks like an exponential Gaussian but again it's not a distribution so dont want to do that.

My last thought was to split the plot into two, the first model can certainly be modeled as a polynomial and the second as an exponential. (values are different than first png cuz it's of a different signal). enter image description here Then, maybe combine the two. What do you think about this? Attached is a screenshot of this too.enter image description here

1
Maxwell–Boltzmann distribution is a classic 'one sided' statistical model: stackoverflow.com/search?q=%5Bpython%5DMaxwell+Boltzmannf5r5e5d
Yes, but it's still a distribution. My signal is not a distribution, check out first pic. Any other ideas?Salchem
That's a verbose way of saying you want to extrapolate some data. My understanding is that your underlying problem is "I want to extrapolate a time series, but I don't know its actual function is. I want to try fitting various functions and evaluate whether they are a good fit. How can I do that?" If I'm wrong, just say whatever you think is right. Of course, also mentioning where the data came from and what the time series looks like doesn't hurt.Reti43
Well said, I agree. Maybe, i should repost it that way, time series is a key term i missed. Maybe i thought for a second it is irrelevant, but it def is.Salchem
exp does not look too good. Can you give some data? I'd probably fiddle with something like ( a+bx+... ) / ( abs(x)**s+t )**umikuszefski

1 Answers

1
votes

Since many curves can fit the data and extrapolate differently, you need to choose the right basis functions to get the behaviour you want.

So far you have tried polynomials for instance, these however tend to +- infinite, which is perhaps not what you want.

I would try and use curve_fit on a sum of Hermite polynomials or Laguerre polynomials. For instance, for Laguerre polynomials, you could try

a + b*exp(-k x) + c*(1-x)*exp(-k x) + d*(x^2 - 4*x + 2)*exp(-k x) + ...

Python has a lot of convenience functions built in for this, see e.g. https://docs.scipy.org/doc/numpy-1.13.0/reference/routines.polynomials.laguerre.html

Note however that you should also fit k to your data, which you could use curve_fit for.