Search code examples
pythonpython-2.7mathcurve-fittingscatter-plot

How to fit math function to the dataset in Python


I have three sets of data as shown below: enter image description here

I wonder what is the function they follow and how to fit these curves in Python?

I guess the first function is something like:

y = axb + cx + d

I tried some arbitrary parameters:

x = numpy.arange(1,10000,2.)
a = 100.
b = -0.003 
c = 50.
d = 0.1
y = -a/x**d+b*x+c
scatter(x,y)

The figure shows like this:

enter image description here

Anyone could help with the other two?


Solution

  • Thank for all your help. I got a solution from my friends.

    y = -a/x**d+b*x+c
    

    Since d makes the fit complicated, it will be easier to set d from 0.1 to 1.0, then use the curve_fit to fit the model. Finally find the best parameter set.