MDI 720 : Statistiques


Joseph Salmon

This notebook reproduces the pictures for the course "IntroStatics"


  • you need TeX install on your machine (otherwise errors could appends)
  • you need in the same directory
In [ ]:
# import packages
import numpy as np
import matplotlib.pyplot as plt  # for plots
from matplotlib import rc
import seaborn as sns
from os import mkdir, path
from scipy import stats
import pandas as pd
from mpl_toolkits.mplot3d import Axes3D
from statsmodels.nonparametric.kde import KDEUnivariate
from scipy.stats import norm
%matplotlib notebook
In [ ]:
saving = True
dirname = "../prebuiltimages/"
imageformat = '.pdf'

if not path.exists(dirname):

def my_saving_display(fig, dirname, filename, imageformat):
    """"Saving with personal function."""
    filename = filename.replace('.', 'pt')  # remove "." to avoid floats issues
    if saving is True:
        dirname + filename + imageformat
        image_name = dirname + filename + imageformat
In [ ]:
n_repetition = 500
tab_n_samples =  [5, 20, 50, 500]
fig = plt.figure()
for i, n_samples in enumerate(tab_n_samples):
    X = np.random.randn(n_samples, n_repetition)
    vect_1n = np.arange(1,n_samples + 1)    
    kde = KDEUnivariate(np.sort(np.mean(X,0) * np.sqrt(n_samples))), kernel='gau')
    x_grid = np.linspace(-3, 3, 100)
    pdf_est = kde.evaluate(x_grid)
    plt.plot(x_grid, pdf_est,label=str(n_samples))

plt.plot(x_grid, norm.pdf(x_grid), c='k', linewidth=2,label="asymptotic")
plt.title('TCL: convergence of $\\bar{y}_n$ density w.r.t the number of samples')

my_saving_display(fig, dirname, "TCL_illustration", imageformat)