Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: Find a best fit function for a list of data

I am aware of many probabilistic functions builted-in Python, with the random module.

I'd like to know if, given a list of floats, it would be possible to find the distribution equation that best fits the list?

I don't know if numpy does it, but this function could be compared (not equal, but similar) with the Excel's "Trend" function.

How would I do that?

like image 834
Gabriel L. Oliveira Avatar asked Apr 23 '11 05:04

Gabriel L. Oliveira


2 Answers

Look at numpy.polyfit

numpy.polyfit(x, y, deg, rcond=None, full=False)

Least squares polynomial fit.

Fit a polynomial p(x) = p[0] * x**deg + ... + p[deg] of degree deg to points (x, y). Returns a vector of coefficients p that minimises the squared error.

like image 96
joaquin Avatar answered Nov 02 '22 16:11

joaquin


there's also curve_fit

from scipy.optimize import curve_fit
like image 41
user96265 Avatar answered Nov 02 '22 16:11

user96265