14

I'm trying to fit some data and stuff, I know there is a simple command to do this with python/numpy/matplotlib, but I can't find it. I think it is something like

popt,popc = numpy.curvefit(f,x)

where popt is the paramters of f, popc is the fit quality and f is a predefined function of f. Does any of you know it?

1
  • 1
    If this is a one-off, it's easier to just plug the values into the function finder at zunzun.com and let it find the best matching curve. Their Python code is available, too. Commented Dec 2, 2011 at 14:57

2 Answers 2

29

Take a look at scipy.optimize.curve_fit:

scipy.optimize.curve_fit(f, xdata, ydata, p0=None, sigma=None, **kw)

Use non-linear least squares to fit a function, f, to data.

Sign up to request clarification or add additional context in comments.

1 Comment

One question: is there an easy way to get R-squared value out of curve_fit, or get SSE so that I can calculate R-squared? I can do some work and get it done in scipy.optimize.leastsq, but the code will be much more verbose.
-1

Found it. Curve_fit from optimize in scipy

1 Comment

Isn't this answer a duplicate of the accepted answer?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.