{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# MDI 720 : Statistiques\n", "## IntroIC\n", "### *Joseph Salmon*\n", "\n", "This notebook reproduces the pictures for the course \"IntroStatics\"\n", "\n", "REM:\n", " - you need TeX install on your machine (otherwise errors could appends)\n", " - you need plot_species_kde.py in the same directory" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# import packages\n", "import numpy as np\n", "import matplotlib.pyplot as plt # for plots\n", "from matplotlib import rc\n", "import seaborn as sns\n", "from os import mkdir, path\n", "from scipy import stats\n", "import pandas as pd\n", "from mpl_toolkits.mplot3d import Axes3D\n", "from statsmodels.nonparametric.kde import KDEUnivariate\n", "from scipy.stats import norm\n", "sns.set_style(\"white\")\n", "sns.set_palette(\"Blues\")\n", "%matplotlib notebook" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "saving = True\n", "dirname = \"../prebuiltimages/\"\n", "imageformat = '.pdf'\n", "\n", "if not path.exists(dirname):\n", " mkdir(dirname)\n", "\n", "def my_saving_display(fig, dirname, filename, imageformat):\n", " \"\"\"\"Saving with personal function.\"\"\"\n", " filename = filename.replace('.', 'pt') # remove \".\" to avoid floats issues\n", " if saving is True:\n", " dirname + filename + imageformat\n", " image_name = dirname + filename + imageformat\n", " fig.savefig(image_name)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "n_repetition = 500\n", "tab_n_samples = [5, 20, 50, 500]\n", "np.random.seed(seed=44)\n", "fig = plt.figure()\n", "for i, n_samples in enumerate(tab_n_samples):\n", " X = np.random.randn(n_samples, n_repetition)\n", " vect_1n = np.arange(1,n_samples + 1) \n", " kde = KDEUnivariate(np.sort(np.mean(X,0) * np.sqrt(n_samples)))\n", " kde.fit(bw=0.25, kernel='gau')\n", " x_grid = np.linspace(-3, 3, 100)\n", " pdf_est = kde.evaluate(x_grid)\n", " plt.plot(x_grid, pdf_est,label=str(n_samples))\n", "\n", "plt.plot(x_grid, norm.pdf(x_grid), c='k', linewidth=2,label=\"asymptotic\")\n", "plt.legend()\n", "plt.title('TCL: convergence of $\\\\bar{y}_n$ density w.r.t the number of samples')\n", "plt.show()\n", "\n", "my_saving_display(fig, dirname, \"TCL_illustration\", imageformat)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.0" } }, "nbformat": 4, "nbformat_minor": 2 }