0-IntroductionDatascience.ipynb 42.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "slideshow": {
     "slide_type": "skip"
    }
   },
   "outputs": [],
   "source": [
    "import numpy as np \n",
    "import csv\n",
    "import matplotlib.pyplot as plt\n",
    "import pandas as pd\n",
    "import seaborn as sns\n",
    "sns.set(color_codes = True)\n",
    "from scipy import stats\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "# 1. La science des données c'est quoi ? \n",
    "\n",
32
    "**Définitions de la donnée du [dictionnaire Larousse](https://www.larousse.fr/dictionnaires/francais/donnée/26436) :** \n",
33 34 35 36 37 38 39 40
    "\n",
    "* Ce qui est connu ou admis comme tel, sur lequel on peut fonder un raisonnement, qui sert de point de départ pour une recherche.\n",
    "* Renseignement qui sert de point d'appui.\n",
    "* Représentation conventionnelle d'une information en vue de son traitement informatique.\n",
    "* Dans un problème de mathématiques, hypothèse figurant dans l'énoncé.\n",
    "* Résultats d'observations ou d'expériences faites délibérément ou à l'occasion d'autres tâches et soumis aux méthodes statistiques."
   ]
  },
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "<span style=\"color: #27AE60\">**Exemple de données :**</span>\n",
    "* documents textes numériques ou numérisés (textes, e-mails, fichiers informatiques, documents scannés, etc.), \n",
    "* fichiers de logs provenant de serveurs, ordinateurs, machines, etc, \n",
    "* enregistrements par des capteurs (température, hydrométrie, etc) ou des objets connectés (rythme cardiaque, position GPS, etc),\n",
    "* bases de données \n",
    "* signaux, images, vidéos, etc"
   ]
  },
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "**La science des données** \n",
    "\n",
    "La science des données est par nature transdiciplinaire, elle fait appel à plusieurs types de connaissances : \n",
    "* la discipline associée à l'application étudiée (physique, chimie, sciences humaines, astronomie, biologie, etc) \n",
    "* les mathématiques pour la modélisation et l'extraction d'information\n",
    "* l'informatique pour la collecte, la sauvegarde, le stockage, le traitement et la représentation des données \n",
    "\n",
    "La science des données a pour but de d'extraire de l'information d'une masse de données, de synthétiser et représenter cette information. Les différentes connaissances pour faire de la science des données peuvent être regroupées dans différentes branches. Une illustration est proposée par Swami Chandrasekaran sous la forme d'un plan de métro où chaque ligne représente une branche/discipline de la science des données."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "![DataScienceMap](http://nirvacana.com/thoughts/wp-content/uploads/2018/01/RoadToDataScientist1.png)\n",
    "Source de l'image : `http://nirvacana.com/thoughts/2013/07/08/becoming-a-data-scientist/`. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "### 1.1. A quoi servent les données \n",
    "\n",
97
    "Les données servent à répondre à une question, il faut donc poser clairement la question, visualiser et modéliser les données, et les interpréter pour répondre à cette question. \n",
98
    "\n",
99
    "Les données seules ne suffisent pas à apporter une réponse, le travail du traiteur de données consiste à inclure des connaissances a priori sur les données. Les données sont rarement neutres puisqu'on les utilise pour répondre à une question (attention au biais !). "
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "### 1.2. Un exemple de jeu de données `movie_metadata.csv` \n",
    "\n",
    "Toutes les notions abordées dans ce cours seront illustrées sur ce jeu de données réelles. Il s'agit d'un extrait de la base de données mise en ligne sur le site [kaggle](kaggle.com) (la base de données a depuis été mise à jour par kaggle sous le nom de [TMdb](https://www.kaggle.com/tmdb/tmdb-movie-metadata)).\n",
    "\n",
    "**Chargement des données avec Pandas** \n",
    "\n",
    "Utilisation du package Pandas ([Python Data Analysis Librairy](https://pandas.pydata.org)) qui fournit notamment l'objet DataFrame dans lequel nous allons stocker le jeu de données étudier. Cet objet DataFrame est muni d'un grand nombre de fonctions permettant :\n",
    "* la récupération et la mise en forme des données \n",
    "* le nettoyage des données (prétraitements) \n",
    "* la représentation graphique et numérique des données \n",
    "* l'analyse statistique des données\n",
    "\n",
    "Consulter la documentation pour l'utilisation des fonctions de la classe DataFrame : http://pandas.pydata.org/pandas-docs/stable/reference/frame.html"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "Nombre de films dans la base : 4125\n"
     ]
    }
   ],
   "source": [
    "DATA = pd.read_csv('data/movie_metadata2.csv', delimiter=';', index_col='movie_title')\n",
    "print(type(DATA))\n",
    "print('Nombre de films dans la base : ' + str(len(DATA.budget))) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>director_name</th>\n",
       "      <th>num_critic_for_reviews</th>\n",
       "      <th>duration</th>\n",
       "      <th>actor_1_name</th>\n",
       "      <th>actor_2_name</th>\n",
       "      <th>num_voted_users</th>\n",
       "      <th>facenumber_in_poster</th>\n",
       "      <th>num_user_for_reviews</th>\n",
       "      <th>language</th>\n",
       "      <th>country</th>\n",
       "      <th>content_rating</th>\n",
       "      <th>budget</th>\n",
       "      <th>title_year</th>\n",
       "      <th>imdb_score</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>movie_title</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>The Shawshank Redemption</th>\n",
       "      <td>Frank Darabont</td>\n",
       "      <td>199</td>\n",
       "      <td>142</td>\n",
       "      <td>Morgan Freeman</td>\n",
       "      <td>Jeffrey DeMunn</td>\n",
       "      <td>1689764</td>\n",
       "      <td>0</td>\n",
       "      <td>4144</td>\n",
       "      <td>English</td>\n",
       "      <td>USA</td>\n",
       "      <td>R</td>\n",
       "      <td>25000000</td>\n",
       "      <td>1994</td>\n",
       "      <td>9.3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>The Dark Knight</th>\n",
       "      <td>Christopher Nolan</td>\n",
       "      <td>645</td>\n",
       "      <td>152</td>\n",
       "      <td>Christian Bale</td>\n",
       "      <td>Heath Ledger</td>\n",
       "      <td>1676169</td>\n",
       "      <td>0</td>\n",
       "      <td>4667</td>\n",
       "      <td>English</td>\n",
       "      <td>USA</td>\n",
       "      <td>PG-13</td>\n",
       "      <td>185000000</td>\n",
       "      <td>2008</td>\n",
       "      <td>9.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Inception</th>\n",
       "      <td>Christopher Nolan</td>\n",
       "      <td>642</td>\n",
       "      <td>148</td>\n",
       "      <td>Leonardo DiCaprio</td>\n",
       "      <td>Tom Hardy</td>\n",
       "      <td>1468200</td>\n",
       "      <td>0</td>\n",
       "      <td>2803</td>\n",
       "      <td>English</td>\n",
       "      <td>USA</td>\n",
       "      <td>PG-13</td>\n",
       "      <td>160000000</td>\n",
       "      <td>2010</td>\n",
       "      <td>8.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Fight Club</th>\n",
       "      <td>David Fincher</td>\n",
       "      <td>315</td>\n",
       "      <td>151</td>\n",
       "      <td>Brad Pitt</td>\n",
       "      <td>Meat Loaf</td>\n",
       "      <td>1347461</td>\n",
       "      <td>2</td>\n",
       "      <td>2968</td>\n",
       "      <td>English</td>\n",
       "      <td>USA</td>\n",
       "      <td>R</td>\n",
       "      <td>63000000</td>\n",
       "      <td>1999</td>\n",
       "      <td>8.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Pulp Fiction</th>\n",
       "      <td>Quentin Tarantino</td>\n",
       "      <td>215</td>\n",
       "      <td>178</td>\n",
       "      <td>Bruce Willis</td>\n",
       "      <td>Eric Stoltz</td>\n",
       "      <td>1324680</td>\n",
       "      <td>1</td>\n",
       "      <td>2195</td>\n",
       "      <td>English</td>\n",
       "      <td>USA</td>\n",
       "      <td>R</td>\n",
       "      <td>8000000</td>\n",
       "      <td>1994</td>\n",
       "      <td>8.9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Forrest Gump</th>\n",
       "      <td>Robert Zemeckis</td>\n",
       "      <td>149</td>\n",
       "      <td>142</td>\n",
       "      <td>Tom Hanks</td>\n",
       "      <td>Siobhan Fallon Hogan</td>\n",
       "      <td>1251222</td>\n",
       "      <td>0</td>\n",
       "      <td>1398</td>\n",
       "      <td>English</td>\n",
       "      <td>USA</td>\n",
       "      <td>PG-13</td>\n",
       "      <td>55000000</td>\n",
       "      <td>1994</td>\n",
       "      <td>8.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>The Lord of the Rings: The Fellowship of the Ring</th>\n",
       "      <td>Peter Jackson</td>\n",
       "      <td>297</td>\n",
       "      <td>171</td>\n",
       "      <td>Christopher Lee</td>\n",
       "      <td>Orlando Bloom</td>\n",
       "      <td>1238746</td>\n",
       "      <td>2</td>\n",
       "      <td>5060</td>\n",
       "      <td>English</td>\n",
       "      <td>New Zealand</td>\n",
       "      <td>PG-13</td>\n",
       "      <td>93000000</td>\n",
       "      <td>2001</td>\n",
       "      <td>8.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>The Matrix</th>\n",
       "      <td>Lana Wachowski</td>\n",
       "      <td>313</td>\n",
       "      <td>136</td>\n",
       "      <td>Keanu Reeves</td>\n",
       "      <td>Marcus Chong</td>\n",
       "      <td>1217752</td>\n",
       "      <td>3</td>\n",
       "      <td>3646</td>\n",
       "      <td>English</td>\n",
       "      <td>USA</td>\n",
       "      <td>R</td>\n",
       "      <td>63000000</td>\n",
       "      <td>1999</td>\n",
       "      <td>8.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>The Lord of the Rings: The Return of the King</th>\n",
       "      <td>Peter Jackson</td>\n",
       "      <td>328</td>\n",
       "      <td>192</td>\n",
       "      <td>Orlando Bloom</td>\n",
       "      <td>Billy Boyd</td>\n",
       "      <td>1215718</td>\n",
       "      <td>2</td>\n",
       "      <td>3189</td>\n",
       "      <td>English</td>\n",
       "      <td>USA</td>\n",
       "      <td>PG-13</td>\n",
       "      <td>94000000</td>\n",
       "      <td>2003</td>\n",
       "      <td>8.9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>The Godfather</th>\n",
       "      <td>Francis Ford Coppola</td>\n",
       "      <td>208</td>\n",
       "      <td>175</td>\n",
       "      <td>Al Pacino</td>\n",
       "      <td>Marlon Brando</td>\n",
       "      <td>1155770</td>\n",
       "      <td>1</td>\n",
       "      <td>2238</td>\n",
       "      <td>English</td>\n",
       "      <td>USA</td>\n",
       "      <td>R</td>\n",
       "      <td>6000000</td>\n",
       "      <td>1972</td>\n",
       "      <td>9.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>The Dark Knight Rises</th>\n",
       "      <td>Christopher Nolan</td>\n",
       "      <td>813</td>\n",
       "      <td>164</td>\n",
       "      <td>Tom Hardy</td>\n",
       "      <td>Christian Bale</td>\n",
       "      <td>1144337</td>\n",
       "      <td>0</td>\n",
       "      <td>2701</td>\n",
       "      <td>English</td>\n",
       "      <td>USA</td>\n",
       "      <td>PG-13</td>\n",
       "      <td>250000000</td>\n",
       "      <td>2012</td>\n",
       "      <td>8.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>The Lord of the Rings: The Two Towers</th>\n",
       "      <td>Peter Jackson</td>\n",
       "      <td>294</td>\n",
       "      <td>172</td>\n",
       "      <td>Christopher Lee</td>\n",
       "      <td>Orlando Bloom</td>\n",
       "      <td>1100446</td>\n",
       "      <td>1</td>\n",
       "      <td>2417</td>\n",
       "      <td>English</td>\n",
       "      <td>USA</td>\n",
       "      <td>PG-13</td>\n",
       "      <td>94000000</td>\n",
       "      <td>2002</td>\n",
       "      <td>8.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Se7en</th>\n",
       "      <td>David Fincher</td>\n",
       "      <td>216</td>\n",
       "      <td>127</td>\n",
       "      <td>Morgan Freeman</td>\n",
       "      <td>Brad Pitt</td>\n",
       "      <td>1023511</td>\n",
       "      <td>0</td>\n",
       "      <td>1080</td>\n",
       "      <td>English</td>\n",
       "      <td>USA</td>\n",
       "      <td>R</td>\n",
       "      <td>33000000</td>\n",
       "      <td>1995</td>\n",
       "      <td>8.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>The Avengers</th>\n",
       "      <td>Joss Whedon</td>\n",
       "      <td>703</td>\n",
       "      <td>173</td>\n",
       "      <td>Chris Hemsworth</td>\n",
       "      <td>Robert Downey Jr.</td>\n",
       "      <td>995415</td>\n",
       "      <td>3</td>\n",
       "      <td>1722</td>\n",
       "      <td>English</td>\n",
       "      <td>USA</td>\n",
       "      <td>PG-13</td>\n",
       "      <td>220000000</td>\n",
       "      <td>2012</td>\n",
       "      <td>8.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Gladiator</th>\n",
       "      <td>Ridley Scott</td>\n",
       "      <td>265</td>\n",
       "      <td>171</td>\n",
       "      <td>Djimon Hounsou</td>\n",
       "      <td>Connie Nielsen</td>\n",
       "      <td>982637</td>\n",
       "      <td>0</td>\n",
       "      <td>2368</td>\n",
       "      <td>English</td>\n",
       "      <td>USA</td>\n",
       "      <td>R</td>\n",
       "      <td>103000000</td>\n",
       "      <td>2000</td>\n",
       "      <td>8.5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                          director_name  \\\n",
       "movie_title                                                               \n",
       "The Shawshank Redemption                                 Frank Darabont   \n",
       "The Dark Knight                                       Christopher Nolan   \n",
       "Inception                                             Christopher Nolan   \n",
       "Fight Club                                                David Fincher   \n",
       "Pulp Fiction                                          Quentin Tarantino   \n",
       "Forrest Gump                                            Robert Zemeckis   \n",
       "The Lord of the Rings: The Fellowship of the Ring         Peter Jackson   \n",
       "The Matrix                                               Lana Wachowski   \n",
       "The Lord of the Rings: The Return of the King             Peter Jackson   \n",
       "The Godfather                                      Francis Ford Coppola   \n",
       "The Dark Knight Rises                                 Christopher Nolan   \n",
       "The Lord of the Rings: The Two Towers                     Peter Jackson   \n",
       "Se7en                                                     David Fincher   \n",
       "The Avengers                                                Joss Whedon   \n",
       "Gladiator                                                  Ridley Scott   \n",
       "\n",
       "                                                   num_critic_for_reviews  \\\n",
       "movie_title                                                                 \n",
       "The Shawshank Redemption                                              199   \n",
       "The Dark Knight                                                       645   \n",
       "Inception                                                             642   \n",
       "Fight Club                                                            315   \n",
       "Pulp Fiction                                                          215   \n",
       "Forrest Gump                                                          149   \n",
       "The Lord of the Rings: The Fellowship of the Ring                     297   \n",
       "The Matrix                                                            313   \n",
       "The Lord of the Rings: The Return of the King                         328   \n",
       "The Godfather                                                         208   \n",
       "The Dark Knight Rises                                                 813   \n",
       "The Lord of the Rings: The Two Towers                                 294   \n",
       "Se7en                                                                 216   \n",
       "The Avengers                                                          703   \n",
       "Gladiator                                                             265   \n",
       "\n",
       "                                                   duration  \\\n",
       "movie_title                                                   \n",
       "The Shawshank Redemption                                142   \n",
       "The Dark Knight                                         152   \n",
       "Inception                                               148   \n",
       "Fight Club                                              151   \n",
       "Pulp Fiction                                            178   \n",
       "Forrest Gump                                            142   \n",
       "The Lord of the Rings: The Fellowship of the Ring       171   \n",
       "The Matrix                                              136   \n",
       "The Lord of the Rings: The Return of the King           192   \n",
       "The Godfather                                           175   \n",
       "The Dark Knight Rises                                   164   \n",
       "The Lord of the Rings: The Two Towers                   172   \n",
       "Se7en                                                   127   \n",
       "The Avengers                                            173   \n",
       "Gladiator                                               171   \n",
       "\n",
       "                                                        actor_1_name  \\\n",
       "movie_title                                                            \n",
       "The Shawshank Redemption                              Morgan Freeman   \n",
       "The Dark Knight                                       Christian Bale   \n",
       "Inception                                          Leonardo DiCaprio   \n",
       "Fight Club                                                 Brad Pitt   \n",
       "Pulp Fiction                                            Bruce Willis   \n",
       "Forrest Gump                                               Tom Hanks   \n",
       "The Lord of the Rings: The Fellowship of the Ring    Christopher Lee   \n",
       "The Matrix                                              Keanu Reeves   \n",
       "The Lord of the Rings: The Return of the King          Orlando Bloom   \n",
       "The Godfather                                              Al Pacino   \n",
       "The Dark Knight Rises                                      Tom Hardy   \n",
       "The Lord of the Rings: The Two Towers                Christopher Lee   \n",
       "Se7en                                                 Morgan Freeman   \n",
       "The Avengers                                         Chris Hemsworth   \n",
       "Gladiator                                             Djimon Hounsou   \n",
       "\n",
       "                                                           actor_2_name  \\\n",
       "movie_title                                                               \n",
       "The Shawshank Redemption                                 Jeffrey DeMunn   \n",
       "The Dark Knight                                            Heath Ledger   \n",
       "Inception                                                     Tom Hardy   \n",
       "Fight Club                                                    Meat Loaf   \n",
       "Pulp Fiction                                                Eric Stoltz   \n",
       "Forrest Gump                                       Siobhan Fallon Hogan   \n",
       "The Lord of the Rings: The Fellowship of the Ring         Orlando Bloom   \n",
       "The Matrix                                                 Marcus Chong   \n",
       "The Lord of the Rings: The Return of the King                Billy Boyd   \n",
       "The Godfather                                             Marlon Brando   \n",
       "The Dark Knight Rises                                    Christian Bale   \n",
       "The Lord of the Rings: The Two Towers                     Orlando Bloom   \n",
       "Se7en                                                         Brad Pitt   \n",
       "The Avengers                                          Robert Downey Jr.   \n",
       "Gladiator                                                Connie Nielsen   \n",
       "\n",
       "                                                   num_voted_users  \\\n",
       "movie_title                                                          \n",
       "The Shawshank Redemption                                   1689764   \n",
       "The Dark Knight                                            1676169   \n",
       "Inception                                                  1468200   \n",
       "Fight Club                                                 1347461   \n",
       "Pulp Fiction                                               1324680   \n",
       "Forrest Gump                                               1251222   \n",
       "The Lord of the Rings: The Fellowship of the Ring          1238746   \n",
       "The Matrix                                                 1217752   \n",
       "The Lord of the Rings: The Return of the King              1215718   \n",
       "The Godfather                                              1155770   \n",
       "The Dark Knight Rises                                      1144337   \n",
       "The Lord of the Rings: The Two Towers                      1100446   \n",
       "Se7en                                                      1023511   \n",
       "The Avengers                                                995415   \n",
       "Gladiator                                                   982637   \n",
       "\n",
       "                                                   facenumber_in_poster  \\\n",
       "movie_title                                                               \n",
       "The Shawshank Redemption                                              0   \n",
       "The Dark Knight                                                       0   \n",
       "Inception                                                             0   \n",
       "Fight Club                                                            2   \n",
       "Pulp Fiction                                                          1   \n",
       "Forrest Gump                                                          0   \n",
       "The Lord of the Rings: The Fellowship of the Ring                     2   \n",
       "The Matrix                                                            3   \n",
       "The Lord of the Rings: The Return of the King                         2   \n",
       "The Godfather                                                         1   \n",
       "The Dark Knight Rises                                                 0   \n",
       "The Lord of the Rings: The Two Towers                                 1   \n",
       "Se7en                                                                 0   \n",
       "The Avengers                                                          3   \n",
       "Gladiator                                                             0   \n",
       "\n",
       "                                                   num_user_for_reviews  \\\n",
       "movie_title                                                               \n",
       "The Shawshank Redemption                                           4144   \n",
       "The Dark Knight                                                    4667   \n",
       "Inception                                                          2803   \n",
       "Fight Club                                                         2968   \n",
       "Pulp Fiction                                                       2195   \n",
       "Forrest Gump                                                       1398   \n",
       "The Lord of the Rings: The Fellowship of the Ring                  5060   \n",
       "The Matrix                                                         3646   \n",
       "The Lord of the Rings: The Return of the King                      3189   \n",
       "The Godfather                                                      2238   \n",
       "The Dark Knight Rises                                              2701   \n",
       "The Lord of the Rings: The Two Towers                              2417   \n",
       "Se7en                                                              1080   \n",
       "The Avengers                                                       1722   \n",
       "Gladiator                                                          2368   \n",
       "\n",
       "                                                  language      country  \\\n",
       "movie_title                                                               \n",
       "The Shawshank Redemption                           English          USA   \n",
       "The Dark Knight                                    English          USA   \n",
       "Inception                                          English          USA   \n",
       "Fight Club                                         English          USA   \n",
       "Pulp Fiction                                       English          USA   \n",
       "Forrest Gump                                       English          USA   \n",
       "The Lord of the Rings: The Fellowship of the Ring  English  New Zealand   \n",
       "The Matrix                                         English          USA   \n",
       "The Lord of the Rings: The Return of the King      English          USA   \n",
       "The Godfather                                      English          USA   \n",
       "The Dark Knight Rises                              English          USA   \n",
       "The Lord of the Rings: The Two Towers              English          USA   \n",
       "Se7en                                              English          USA   \n",
       "The Avengers                                       English          USA   \n",
       "Gladiator                                          English          USA   \n",
       "\n",
       "                                                  content_rating     budget  \\\n",
       "movie_title                                                                   \n",
       "The Shawshank Redemption                                       R   25000000   \n",
       "The Dark Knight                                            PG-13  185000000   \n",
       "Inception                                                  PG-13  160000000   \n",
       "Fight Club                                                     R   63000000   \n",
       "Pulp Fiction                                                   R    8000000   \n",
       "Forrest Gump                                               PG-13   55000000   \n",
       "The Lord of the Rings: The Fellowship of the Ring          PG-13   93000000   \n",
       "The Matrix                                                     R   63000000   \n",
       "The Lord of the Rings: The Return of the King              PG-13   94000000   \n",
       "The Godfather                                                  R    6000000   \n",
       "The Dark Knight Rises                                      PG-13  250000000   \n",
       "The Lord of the Rings: The Two Towers                      PG-13   94000000   \n",
       "Se7en                                                          R   33000000   \n",
       "The Avengers                                               PG-13  220000000   \n",
       "Gladiator                                                      R  103000000   \n",
       "\n",
       "                                                   title_year  imdb_score  \n",
       "movie_title                                                                \n",
       "The Shawshank Redemption                                 1994         9.3  \n",
       "The Dark Knight                                          2008         9.0  \n",
       "Inception                                                2010         8.8  \n",
       "Fight Club                                               1999         8.8  \n",
       "Pulp Fiction                                             1994         8.9  \n",
       "Forrest Gump                                             1994         8.8  \n",
       "The Lord of the Rings: The Fellowship of the Ring        2001         8.8  \n",
       "The Matrix                                               1999         8.7  \n",
       "The Lord of the Rings: The Return of the King            2003         8.9  \n",
       "The Godfather                                            1972         9.2  \n",
       "The Dark Knight Rises                                    2012         8.5  \n",
       "The Lord of the Rings: The Two Towers                    2002         8.7  \n",
       "Se7en                                                    1995         8.6  \n",
       "The Avengers                                             2012         8.1  \n",
       "Gladiator                                                2000         8.5  "
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "DATA.head(n = 15)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "# 2. Vocabulaire utile\n",
    "\n",
    "Afin de parler le même langage, quelques définitions/rappels de statistiques : \n",
    "\n",
    "**Population :** ensemble d’individus ou d’objets étudiés.\n",
    "\n",
    "<span style=\"color: #27AE60\">exemple :</span>\n",
    "\n",
    "**Individu :** élément d’une population.\n",
    "\n",
    "<span style=\"color: #27AE60\">exemple :</span>\n",
    "\n",
    "**Variable(s) :** on parle aussi de caractère(s). Une variable $X$ représente une\n",
    "caractéristique dont on observe/recueille la valeur pour chaque\n",
    "individu d’une population. Une population peut être caractérisée par\n",
    "une (analyse unidimensionnelle) ou plusieurs variables (analyse\n",
    "multidimensionnelle). La variable statistique (ou aléatoire) est notée\n",
    "en majuscule $X$, les valeurs qu’elle prend sont notées en minuscules $(x_1, x_2, \\cdots)$.\n",
    "\n",
    "<span style=\"color: #27AE60\">exemple :</span>\n",
    "\n",
    "**Valeurs :** ce sont les valeurs numériques ou modalités $(x_1, x_2, \\cdots)$ prises par la\n",
    "variable d’intérêt $X$ pour les $N$ individus de la population.\n",
    "\n",
    "<span style=\"color: #27AE60\">exemple :</span>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "**Effectif :** nombre d’individus ni de la population pour lesquels la variable $X$\n",
    "prend une valeur donnée $x_i$.\n",
    "\n",
    "<span style=\"color: #27AE60\">exemple :</span>\n",
    "\n",
    "**Fréquence :** la fréquence $f_i$ associée à la valeur $x_i$ est le rapport de l’effectif de\n",
    "cette valeur sur la taille $N$ de la population. La somme des\n",
    "fréquences est égale à 1 (ou 100 si l’on travaille en $\\%$).\n",
    "\n",
    "<span style=\"color: #27AE60\">exemple :</span>\n",
    "\n",
    "\n",
    "**Etendue :** Soit $(x_1, x_2, \\cdots, x_N)$ un ensemble de valeurs. Notons $x_{max}$ la valeur\n",
    "maximale de l’ensemble $(x_1, x_2, \\cdots, x_N)$ et $x_{min}$ la valeur minimale. On\n",
    "appelle étendue de l’ensemble de valeurs $(x_1, x_2, \\cdots, x_N)$ la différence\n",
    "$x_{max} - x_{min}$.\n",
    "\n",
    "<span style=\"color: #27AE60\">exemple :</span>\n",
    "\n",
    "\n",
    "  "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "**Nom des variables stockées** "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Index(['director_name', 'num_critic_for_reviews', 'duration', 'actor_1_name',\n",
      "       'actor_2_name', 'num_voted_users', 'facenumber_in_poster',\n",
      "       'num_user_for_reviews', 'language', 'country', 'content_rating',\n",
      "       'budget', 'title_year', 'imdb_score'],\n",
      "      dtype='object')\n"
     ]
    }
   ],
   "source": [
    "print(DATA.keys())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "#### Sélection de variables grâce à l'outil `DataFrame` \n",
    "\n",
    "La librairie `pandas` possède une classe `DataFrame` munie d'un grand nombre de fonctions dédiées à l'analyse de tableau de données. Dans l'exemple ci-dessous, 2 variables quantitatives sont extraites de la base de données : le score et le budget, par exemple pour étudier la relation entre ces deux variable.  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "scrolled": true,
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>imdb_score</th>\n",
       "      <th>budget</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>movie_title</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>The Shawshank Redemption</th>\n",
       "      <td>9.3</td>\n",
       "      <td>25000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>The Dark Knight</th>\n",
       "      <td>9.0</td>\n",
       "      <td>185000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Inception</th>\n",
       "      <td>8.8</td>\n",
       "      <td>160000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Fight Club</th>\n",
       "      <td>8.8</td>\n",
       "      <td>63000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Pulp Fiction</th>\n",
       "      <td>8.9</td>\n",
       "      <td>8000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Forrest Gump</th>\n",
       "      <td>8.8</td>\n",
       "      <td>55000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>The Lord of the Rings: The Fellowship of the Ring</th>\n",
       "      <td>8.8</td>\n",
       "      <td>93000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>The Matrix</th>\n",
       "      <td>8.7</td>\n",
       "      <td>63000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>The Lord of the Rings: The Return of the King</th>\n",
       "      <td>8.9</td>\n",
       "      <td>94000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>The Godfather</th>\n",
       "      <td>9.2</td>\n",
       "      <td>6000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                   imdb_score     budget\n",
       "movie_title                                                             \n",
       "The Shawshank Redemption                                  9.3   25000000\n",
       "The Dark Knight                                           9.0  185000000\n",
       "Inception                                                 8.8  160000000\n",
       "Fight Club                                                8.8   63000000\n",
       "Pulp Fiction                                              8.9    8000000\n",
       "Forrest Gump                                              8.8   55000000\n",
       "The Lord of the Rings: The Fellowship of the Ring         8.8   93000000\n",
       "The Matrix                                                8.7   63000000\n",
       "The Lord of the Rings: The Return of the King             8.9   94000000\n",
       "The Godfather                                             9.2    6000000"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame(DATA, columns=['imdb_score', 'budget'])\n",
    "df.head(n = 10)# permet d'afficher les 10 premières lignes du tableau de données pour les colonnes sélectionnées "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "# 3. Les différents types de données\n",
    "\n",
    "### 3.1. Données quantitatives\n",
    "\n",
    "Ce sont des quantités mesurables sur lesquelles on peut faire des calculs et des comparaisons : $ f(x), \\div, \\times, =, \\neq, \\leqslant, \\geqslant$. \n",
    "\n",
    "Une variable quantitative peut être soit continue $x \\in [a,b]$ soit discrète $x\\in \\{a,b,c, \\dots\\}$\n",
    "\n",
    "<span style=\"color: #27AE60\">Exemple de données quantitatives continue dans la base IMdB :</span>\n",
    "\n",
    "$\\vdots$\n",
    "\n",
    "<span style=\"color: #27AE60\">Exemple de données quantitatives discrète dans la base IMdB :</span>\n",
    "\n",
    "$\\vdots$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### 3.2. Données qualitatives\n",
    "\n",
    "Ce sont des caractéristiques non mesurables, on parle de modalités.\n",
    "Une variable qualitative peut être soit nominale, dans ce cas il n'y a pas de notion d'ordre, les seules opérations autorisées sont : $=, \\neq$, soit ordinale, on peut ajouter aux opérations $=$ et $\\neq$ le tri (ordre logique) \n",
    "\n",
    "<span style=\"color: #27AE60\">Exemple de données qualitatives nominales dans la base IMdB :</span>\n",
    "\n",
    "$\\vdots$\n",
    "\n",
    "<span style=\"color: #27AE60\">Exemple de données qualitatives ordinales dans la base IMdB :</span>\n",
    "\n",
    "$\\vdots$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "# Ressources complémentaires\n",
    "\n",
    "Cours de Stéphane Mallat au collège de France : [Leçon inaugurale](https://www.college-de-france.fr/site/stephane-mallat/inaugural-lecture-2018-01-11-18h00.htm), [Cartgographie de la science des données](https://www.college-de-france.fr/site/stephane-mallat/course-2018-01-17-09h30.htm)\n",
974 975
    "\n",
    "Livre [Data science : fondamentaux et études de cas - Machine learning avec Python et R](https://www.eyrolles.com/Chapitres/9782212142433/9782212142433.pdf)"
976
   ]
977 978 979 980 981 982 983
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008
  }
 ],
 "metadata": {
  "celltoolbar": "Diaporama",
  "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.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}