gumbel_l_gen.fit(self, data, *args, **kwds)
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).
With method="MLE"
(default), the fit is computed by minimizing the negative log-likelihood function. A large, finite penalty (rather than infinite negative log-likelihood) is applied for observations beyond the support of the distribution.
With method="MM"
, the fit is computed by minimizing the L2 norm of the relative errors between the first k raw (about zero) data moments and the corresponding distribution moments, where k is the number of non-fixed parameters. More precisely, the objective function is
(((data_moments - dist_moments)
/ np.maximum(np.abs(data_moments), 1e-8))**2).sum()
where the constant 1e-8
avoids division by zero in case of vanishing data moments. Typically, this error norm can be reduced to zero. Note that the standard method of moments can produce parameters for which some data are outside the support of the fitted distribution; this implementation does nothing to prevent this.
For either method, the returned answer is not guaranteed to be globally optimal; it may only be locally optimal, or the optimization may fail altogether. If the data contain any of np.nan
, np.inf
, or -np.inf
, the fit method will raise a RuntimeError
.
Data to use in estimating the distribution parameters.
Starting value(s) for any shape-characterizing arguments (those not provided will be determined by a call to _fitstart(data)
). No default value.
Special keyword arguments are recognized as holding certain parameters fixed:
If an input is invalid
If fitting fails or the fit produced would be invalid
Estimates 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. norm
).
Return estimates of shape (if applicable), location, and scale parameters from data. The default estimation method is Maximum Likelihood Estimation (MLE), but Method of Moments (MM) is also available.
from scipy.stats import beta
a, b = 1., 2.
x = beta.rvs(a, b, size=1000)
a1, b1, loc1, scale1 = beta.fit(x)
a1, b1, loc1, scale1 = beta.fit(x, floc=0, fscale=1)
loc1, scale1
a1, b1, loc1, scale1 = beta.fit(x, fa=1, floc=0, fscale=1)
a1
from scipy.stats import norm
x = norm.rvs(a, b, size=1000, random_state=123)
loc1, scale1 = norm.fit(x)
loc1, scale1
The following pages refer to to this document either explicitly or contain code examples using this.
scipy.stats._continuous_distns:gumbel_l_gen.fit
Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.
Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)
SVG is more flexible but power hungry; and does not scale well to 50 + nodes.
All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them