How do I determine a good function to fit a set of data?

360 Views Asked by At

I have a calculated some rates based on data, but I was wondering if there is a way to determine a good math function that might fit this data. For example, consider the following:

0.1387 
0.3840 
0.2744 
0.1654 
0.1062 
0.0748 
0.0502 
0.0397 
0.0342 
0.0268 
0.0204 
0.0089 
0.0064 
0.0102 
0.0092 
0.0064 
0.0039 
0.0036 

This looks like the following: Graphical representation.

I tried a polynomial function, but that (perhaps obviously) doesn't work. I also tried the poisson function, but the fit did not appear to be very good. So I'm wondering how I go about thinking what function might be better.

Thanks in advance.

1

There are 1 best solutions below

0
On

Based on all the feedback and helpful advice received above, I did the following (leverages python to figure out parameter estimates):

from scipy.optimize import curve_fit
from scipy.misc import factorial
from scipy.optimize import minimize
xs = np.arange(18)
ys = np.array([
    0.1387,
    0.3840,
    0.2744,
    0.1654,
    0.1062,
    0.0748,
    0.0502,
    0.0397,
    0.0342,
    0.0268,
    0.0204,
    0.0089,
    0.0064,
    0.0102,
    0.0092,
    0.0064,
    0.0039,
    0.0036,
])
plt.plot(xs, ys, ls='-', marker='o', markersize=4, markerfacecolor='#FFFFFF', label='Actual')
fn = lambda x, a, α, β, b, θ: a * x ** α * np.exp(-β * x) + θ * (1 - (x / (abs(x - 1) + 1))) # second
fit_params, pcov = curve_fit(fn, xs, ys)
y_new = fn(xs, *fit_params)
plt.plot(xs, y_new, ls='-', marker='o', markersize=4, markerfacecolor='#FFFFFF', label='Model')
plt.legend()
plt.show()

The results seem promising: enter image description here

Thanks for the help!