Un ipython notebook garde ses résultats depuis la dernière fois, mais pas son état. Il convient donc re-exécuter depuis le début.


In [1]:
import numpy as np
import scipy.stats as ss
import matplotlib.pyplot as plt
import sklearn
import pandas as pd

%matplotlib inline

In [2]:
x = np.linspace(-100, 100, 201)
plt.plot(x, x * x)


Out[2]:
[<matplotlib.lines.Line2D at 0x7efebf843dd8>]

Example of sampling from a probability distribution.

Note that we use the ppf (percent point function) = the inverse of the probability density function. This is where it will likely arise most.


In [3]:
x = np.linspace(ss.norm.ppf(.01), ss.norm.ppf(.99), 100)
plt.plot(x, ss.norm.pdf(x))
plt.show()


Running mean example

D'abord nous générons un échantillon aléatoire. Puis nous calculons la somme et la visualisons.

Questions :

  • Qu'est-ce qui se passe si on change num_points?
  • Qu'est-ce qui est la différence entre les deux courbes?

In [4]:
num_points = 100
index = np.linspace(1, num_points, num_points)
sample = [ss.norm.rvs() for x in range(num_points)]
plt.plot(index, np.cumsum(sample))
plt.plot(index, [x / (i + 1) for i, x in enumerate(sample)])


Out[4]:
[<matplotlib.lines.Line2D at 0x7efebf83c278>]