ExpTransf_gen.fit(data, *args, **kwds)
Return MLEs for shape (if applicable), location, and scale parameters from data.
MLE stands for Maximum Likelihood Estimate. Starting estimates for the fit are given by input arguments; for any arguments not provided with starting estimates, self._fitstart(data)
is called to generate such.
One can hold some parameters fixed to specific values by passing in keyword arguments f0
, f1
, …, fn
(for shape parameters) and floc
and fscale
(for location and scale parameters, respectively).
Parameters: |
|
---|---|
Returns: |
mle_tuple – MLEs for any shape parameters (if applicable), followed by those for location and scale. For most random variables, shape statistics will be returned, but there are exceptions (e.g. |
Return type: |
tuple of floats |
This fit is computed by maximizing a log-likelihood function, with penalty applied for samples outside of range of the distribution. The returned answer is not guaranteed to be the globally optimal MLE, it may only be locally optimal, or the optimization may fail altogether.
Generate some data to fit: draw random variates from the beta
distribution
>>> from scipy.stats import beta >>> a, b = 1., 2. >>> x = beta.rvs(a, b, size=1000)
Now we can fit all four parameters (a
, b
, loc
and scale
):
>>> a1, b1, loc1, scale1 = beta.fit(x)
We can also use some prior knowledge about the dataset: let’s keep loc
and scale
fixed:
>>> a1, b1, loc1, scale1 = beta.fit(x, floc=0, fscale=1) >>> loc1, scale1 (0, 1)
We can also keep shape parameters fixed by using f
-keywords. To keep the zero-th shape parameter a
equal 1, use f0=1
or, equivalently, fa=1
:
>>> a1, b1, loc1, scale1 = beta.fit(x, fa=1, floc=0, fscale=1) >>> a1 1
Not all distributions return estimates for the shape parameters. norm
for example just returns estimates for location and scale:
>>> from scipy.stats import norm >>> x = norm.rvs(a, b, size=1000, random_state=123) >>> loc1, scale1 = norm.fit(x) >>> loc1, scale1 (0.92087172783841631, 2.0015750750324668)
© 2009–2012 Statsmodels Developers
© 2006–2008 Scipy Developers
© 2006 Jonathan E. Taylor
Licensed under the 3-clause BSD License.
http://www.statsmodels.org/stable/generated/statsmodels.sandbox.distributions.transformed.ExpTransf_gen.fit.html