Vous êtes un professionnel et vous avez besoin d'une formation ?
Deep Learning avec Python
et Keras et Tensorflow
Voir le programme détaillé
Module « scipy.stats »
Classe « rv_histogram »
Informations générales
Héritage
builtins.object
rv_generic
rv_continuous
rv_histogram
Définition
class rv_histogram(rv_continuous):
help(rv_histogram)
Generates a distribution given by a histogram.
This is useful to generate a template distribution from a binned
datasample.
As a subclass of the `rv_continuous` class, `rv_histogram` inherits from it
a collection of generic methods (see `rv_continuous` for the full list),
and implements them based on the properties of the provided binned
datasample.
Parameters
----------
histogram : tuple of array_like
Tuple containing two array_like objects.
The first containing the content of n bins,
the second containing the (n+1) bin boundaries.
In particular, the return value of `numpy.histogram` is accepted.
density : bool, optional
If False, assumes the histogram is proportional to counts per bin;
otherwise, assumes it is proportional to a density.
For constant bin widths, these are equivalent, but the distinction
is important when bin widths vary (see Notes).
If None (default), sets ``density=True`` for backwards compatibility,
but warns if the bin widths are variable. Set `density` explicitly
to silence the warning.
.. versionadded:: 1.10.0
Notes
-----
When a histogram has unequal bin widths, there is a distinction between
histograms that are proportional to counts per bin and histograms that are
proportional to probability density over a bin. If `numpy.histogram` is
called with its default ``density=False``, the resulting histogram is the
number of counts per bin, so ``density=False`` should be passed to
`rv_histogram`. If `numpy.histogram` is called with ``density=True``, the
resulting histogram is in terms of probability density, so ``density=True``
should be passed to `rv_histogram`. To avoid warnings, always pass
``density`` explicitly when the input histogram has unequal bin widths.
There are no additional shape parameters except for the loc and scale.
The pdf is defined as a stepwise function from the provided histogram.
The cdf is a linear interpolation of the pdf.
.. versionadded:: 0.19.0
Examples
--------
Create a scipy.stats distribution from a numpy histogram
>>> import scipy.stats
>>> import numpy as np
>>> data = scipy.stats.norm.rvs(size=100000, loc=0, scale=1.5,
... random_state=123)
>>> hist = np.histogram(data, bins=100)
>>> hist_dist = scipy.stats.rv_histogram(hist, density=False)
Behaves like an ordinary scipy rv_continuous distribution
>>> hist_dist.pdf(1.0)
0.20538577847618705
>>> hist_dist.cdf(2.0)
0.90818568543056499
PDF is zero above (below) the highest (lowest) bin of the histogram,
defined by the max (min) of the original dataset
>>> hist_dist.pdf(np.max(data))
0.0
>>> hist_dist.cdf(np.max(data))
1.0
>>> hist_dist.pdf(np.min(data))
7.7591907244498314e-05
>>> hist_dist.cdf(np.min(data))
0.0
PDF and CDF follow the histogram
>>> import matplotlib.pyplot as plt
>>> X = np.linspace(-5.0, 5.0, 100)
>>> fig, ax = plt.subplots()
>>> ax.set_title("PDF from Template")
>>> ax.hist(data, density=True, bins=100)
>>> ax.plot(X, hist_dist.pdf(X), label='PDF')
>>> ax.plot(X, hist_dist.cdf(X), label='CDF')
>>> ax.legend()
>>> fig.show()
Constructeur(s)
Liste des propriétés
random_state | Get or set the generator object for generating random variates. [extrait de random_state.__doc__] |
Liste des opérateurs
Opérateurs hérités de la classe object
__eq__,
__ge__,
__gt__,
__le__,
__lt__,
__ne__
Liste des méthodes
Toutes les méthodes
Méthodes d'instance
Méthodes statiques
Méthodes dépréciées
Méthodes héritées de la classe rv_continuous
__getstate__, __init_subclass__, __subclasshook__, cdf, expect, fit, fit_loc_scale, isf, logcdf, logpdf, logsf, pdf, ppf, sf
Méthodes héritées de la classe rv_generic
__call__, __setstate__, entropy, freeze, interval, mean, median, moment, nnlf, rvs, stats, std, support, var
Méthodes héritées de la classe object
__delattr__,
__dir__,
__format__,
__getattribute__,
__hash__,
__reduce__,
__reduce_ex__,
__repr__,
__setattr__,
__sizeof__,
__str__
Vous êtes un professionnel et vous avez besoin d'une formation ?
RAG (Retrieval-Augmented Generation)et Fine Tuning d'un LLM
Voir le programme détaillé
Améliorations / Corrections
Vous avez des améliorations (ou des corrections) à proposer pour ce document : je vous remerçie par avance de m'en faire part, cela m'aide à améliorer le site.
Emplacement :
Description des améliorations :