module datasets.duration

Short summary

module papierstat.datasets.duration

Jeux de données artificiel lié à la prédiction de durées.

source on GitHub

Functions

function

truncated documentation

duration_selling

Construit un jeu de données artificiel qui simule des paquets préparés par un magasin. Chaque paquet est préparé dès …

Documentation

Jeux de données artificiel lié à la prédiction de durées.

source on GitHub

papierstat.datasets.duration.duration_selling(date_begin=None, date_end=None, mean_per_day=10, sigma_per_day=5, week_pattern=None, hour_begin=9, hour_end=19, gamma_k=6.0, gamma_theta=0.25)[source]

Construit un jeu de données artificiel qui simule des paquets préparés par un magasin. Chaque paquet est préparé dès la réception d’une commande à une heure précise, il est ensuite stocké jusqu’à ce qu’un client viennent le chercher.

Paramètres
  • date_begin – première date

  • date_end – dernière date

  • hour_begin – heure d’ouverture du magasin

  • hour_end – heure de fermeture du magasin

  • week_pattern – tableau de 7 valeurs ou None pour une distribution uniforme sur les jours de la semaine

  • mean_per_day – nombre de paquets moyen par jour (suit une loi gaussienne)

  • sigma_per_day – écart type pour la loi gaussienne

  • gamma_k – paramètre k d’une loi gamma

  • gamma_theta – paramètre \theta d’une loi gamma

Renvoie

jeu de données

<<<

from papierstat.datasets.duration import duration_selling
print(duration_selling().head())

>>>

                        commande  true_duration                  reception
    0 2018-10-10 09:36:42.713800       0.904420 2018-10-10 10:30:58.626018
    1 2018-10-10 14:32:52.287656       0.658284 2018-10-10 15:12:22.109578
    2 2018-10-10 10:59:44.829696       0.959805 2018-10-10 11:57:20.126893
    3 2018-10-10 13:05:21.005918       0.809227 2018-10-10 13:53:54.223203
    4 2018-10-10 16:40:01.062655       1.496862 2018-10-10 18:09:49.765555

Les commandes sont réparties de façon uniformes sur la journée même si c’est peu probable. La durée suit une loi \Gamma. Cette durée est ajoutée à l’heure où est passée la commande, les heures nocturnes et le week-end ne sont pas comptées. La durée ne peut excéder 10h.

source on GitHub

papierstat.datasets.duration.gamma(shape, scale=1.0, size=None)

Draw samples from a Gamma distribution.

Samples are drawn from a Gamma distribution with specified parameters, shape (sometimes designated « k ») and scale (sometimes designated « theta »), where both parameters are > 0.

Paramètres
  • shape (float or array_like of floats) – The shape of the gamma distribution. Must be non-negative.

  • scale (float or array_like of floats, optional) – The scale of the gamma distribution. Must be non-negative. Default is equal to 1.

  • size (int or tuple of ints, optional) – Output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn. If size is None (default), a single value is returned if shape and scale are both scalars. Otherwise, np.broadcast(shape, scale).size samples are drawn.

Renvoie

out – Drawn samples from the parameterized gamma distribution.

Type renvoyé

ndarray or scalar

Voir aussi

scipy.stats.gamma()

probability density function, distribution or cumulative density function, etc.

Notes

The probability density for the Gamma distribution is

p(x) = x^{k-1}\frac{e^{-x/\theta}}{\theta^k\Gamma(k)},

where k is the shape and \theta the scale, and \Gamma is the Gamma function.

The Gamma distribution is often used to model the times to failure of electronic components, and arises naturally in processes for which the waiting times between Poisson distributed events are relevant.

Références

1

Weisstein, Eric W. « Gamma Distribution. » From MathWorld–A Wolfram Web Resource. http://mathworld.wolfram.com/GammaDistribution.html

2

Wikipedia, « Gamma distribution », https://en.wikipedia.org/wiki/Gamma_distribution

Exemples

Draw samples from the distribution:

>>> shape, scale = 2., 2.  # mean=4, std=2*sqrt(2)
>>> s = np.random.gamma(shape, scale, 1000)

Display the histogram of the samples, along with the probability density function:

>>> import matplotlib.pyplot as plt
>>> import scipy.special as sps  
>>> count, bins, ignored = plt.hist(s, 50, density=True)
>>> y = bins**(shape-1)*(np.exp(-bins/scale) /  
...                      (sps.gamma(shape)*scale**shape))
>>> plt.plot(bins, y, linewidth=2, color='r')  
>>> plt.show()
papierstat.datasets.duration.rand(d0, d1, ..., dn)

Random values in a given shape.

Note

This is a convenience function for users porting code from Matlab, and wraps numpy.random.random_sample. That function takes a tuple to specify the size of the output, which is consistent with other NumPy functions like numpy.zeros and numpy.ones.

Create an array of the given shape and populate it with random samples from a uniform distribution over [0, 1).

Paramètres

d1, .., dn (d0,) – The dimensions of the returned array, must be non-negative. If no argument is given a single Python float is returned.

Renvoie

out – Random values.

Type renvoyé

ndarray, shape (d0, d1, ..., dn)

Voir aussi

random()

Exemples

>>> np.random.rand(3,2)
array([[ 0.14022471,  0.96360618],  #random
       [ 0.37601032,  0.25528411],  #random
       [ 0.49313049,  0.94909878]]) #random
papierstat.datasets.duration.randn(d0, d1, ..., dn)

Return a sample (or samples) from the « standard normal » distribution.

Note

This is a convenience function for users porting code from Matlab, and wraps numpy.random.standard_normal. That function takes a tuple to specify the size of the output, which is consistent with other NumPy functions like numpy.zeros and numpy.ones.

If positive int_like arguments are provided, randn generates an array of shape (d0, d1, ..., dn), filled with random floats sampled from a univariate « normal » (Gaussian) distribution of mean 0 and variance 1. A single float randomly sampled from the distribution is returned if no argument is provided.

Paramètres

d1, .., dn (d0,) – The dimensions of the returned array, must be non-negative. If no argument is given a single Python float is returned.

Renvoie

Z – A (d0, d1, ..., dn)-shaped array of floating-point samples from the standard normal distribution, or a single such float if no parameters were supplied.

Type renvoyé

ndarray or float

Voir aussi

standard_normal()

Similar, but takes a tuple as its argument.

normal()

Also accepts mu and sigma arguments.

Notes

For random samples from N(\mu, \sigma^2), use:

sigma * np.random.randn(...) + mu

Exemples

>>> np.random.randn()
2.1923875335537315  # random

Two-by-four array of samples from N(3, 6.25):

>>> 3 + 2.5 * np.random.randn(2, 4)
array([[-4.49401501,  4.00950034, -1.81814867,  7.29718677],   # random
       [ 0.39924804,  4.68456316,  4.99394529,  4.84057254]])  # random