{ } Raw JSON

bundles / scipy 1.17.1 / scipy / stats / _continuous_distns / uniform_gen / fit

function

scipy.stats._continuous_distns:uniform_gen.fit

source: /scipy/stats/_continuous_distns.py :10919

Signature

def   fit ( self data * args ** kwds )

Summary

Maximum likelihood estimate for the location and scale parameters.

Extended Summary

uniform.fit uses only the following parameters. Because exact formulas are used, the parameters related to optimization that are available in the fit method of other distributions are ignored here. The only positional argument accepted is data.

Parameters

data : array_like

Data to use in calculating the maximum likelihood estimate.

floc : float, optional

Hold the location parameter fixed to the specified value.

fscale : float, optional

Hold the scale parameter fixed to the specified value.

Returns

loc, scale : float

Maximum likelihood estimates for the location and scale.

Notes

An error is raised if floc is given and any values in data are less than floc, or if fscale is given and fscale is less than data.max() - data.min(). An error is also raised if both floc and fscale are given.

Examples

import numpy as np
from scipy.stats import uniform
We'll fit the uniform distribution to `x`:
x = np.array([2, 2.5, 3.1, 9.5, 13.0])
For a uniform distribution MLE, the location is the minimum of the data, and the scale is the maximum minus the minimum.
loc, scale = uniform.fit(x)
loc
scale
If we know the data comes from a uniform distribution where the support starts at 0, we can use ``floc=0``:
loc, scale = uniform.fit(x, floc=0)
loc
scale
Alternatively, if we know the length of the support is 12, we can use ``fscale=12``:
loc, scale = uniform.fit(x, fscale=12)
loc
scale
In that last example, the support interval is [1.5, 13.5]. This solution is not unique. For example, the distribution with ``loc=2`` and ``scale=12`` has the same likelihood as the one above. When `fscale` is given and it is larger than ``data.max() - data.min()``, the parameters returned by the `fit` method center the support over the interval ``[data.min(), data.max()]``.

Aliases

  • scipy.stats._continuous_distns.uniform_gen.fit