make_distribution#
- scipy.stats.make_distribution(dist)[source]#
Generate a ContinuousDistribution from an instance of
rv_continuous
The returned value is a ContinuousDistribution subclass. Like any subclass of ContinuousDistribution, it must be instantiated (i.e. by passing all shape parameters as keyword arguments) before use. Once instantiated, the resulting object will have the same interface as any other instance of ContinuousDistribution; e.g.,
scipy.stats.Normal
.Note
make_distribution
does not work perfectly with all instances ofrv_continuous
. Known failures includelevy_stable
andvonmises
, and some methods of some distributions will not support array shape parameters.- Parameters:
- dist
rv_continuous
Instance of
rv_continuous
.
- dist
- Returns:
- CustomDistributionContinuousDistribution
A subclass of ContinuousDistribution corresponding with dist. The initializer requires all shape parameters to be passed as keyword arguments (using the same names as the instance of
rv_continuous
).
Notes
The documentation of ContinuousDistribution is not rendered. See below for an example of how to instantiate the class (i.e. pass all shape parameters of dist to the initializer as keyword arguments). Documentation of all methods is identical to that of
scipy.stats.Normal
. Usehelp
on the returned class or its methods for more information.Examples
>>> import numpy as np >>> import matplotlib.pyplot as plt >>> from scipy import stats >>> LogU = stats.make_distribution(stats.loguniform) >>> X = LogU(a=1.0, b=3.0) >>> np.isclose((X + 0.25).median(), stats.loguniform.ppf(0.5, 1, 3, loc=0.25)) np.True_ >>> X.plot() >>> sample = X.sample(10000, rng=np.random.default_rng()) >>> plt.hist(sample, density=True, bins=30) >>> plt.legend(('pdf', 'histogram')) >>> plt.show()