6

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?

Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
Gabriel L. Oliveira
  • 3,922
  • 6
  • 31
  • 40
  • 3
    A distribution isn't a best fit curve. It has a max of `1` and a min of `0`, and an integral from `-inf` to `inf` which equals `1`. What are you trying to do with this curve? – Blender Apr 23 '11 at 05:51
  • @Blender I have, for example, 10 types of operations (work with a vessel). And a history of 10 years of work with this types of operations. I'm trying to simulate the next year of opearations, based on the history, but applying random generators for each type of operation. This random generator will be applied to the duration of each request, the date when each request occurs and how many requests will happen. And I'm not interested on user enter this data. Because of that I'm looking for a way to automatically entry these random distributions. – Gabriel L. Oliveira Apr 23 '11 at 21:58

3 Answers3

13

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.

TiTo
  • 833
  • 2
  • 7
  • 28
joaquin
  • 82,968
  • 29
  • 138
  • 152
1

there's also curve_fit

from scipy.optimize import curve_fit
user96265
  • 510
  • 5
  • 6
0

You may want to try the time series analysis in statsmodels.tsa. Check out the code below:

from statsmodels.tsa.seasonal import seasonal_decompose
decomp = seasonal_decompose(df_train)

trend = decomp.trend
seasonal = decomp.seasonal
residual = decomp.resid

One caveat. I found the seasonal part not to handle heterostascedy well -- this si when your periodic function amplitude grows with time. It keeps the periodic amplitude constant (that is part of seasonal) and then your residual will show a periodic effect.

user96265
  • 510
  • 5
  • 6