{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "

\n", " KNN : Découverte\n", "\n", "


" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Représenter des points" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXoAAAD4CAYAAADiry33AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjMsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+AADFEAAARxklEQVR4nO3dcYyk913f8ffHdlJ6h0sSvOwktu82pZEhRLUTrUyCReQQMHaw4rYKYOugBlI2QUmbVEQtxFIClSy1qoFGMYp1BJPQLiZtiFOrOImtgBQiQWDPOMTBCTHGPh/n29tgsIOPKlz48sfMKXt7M3e788zdc/fb90sazTPf5zfz+95o97PPPfPM86SqkCS167y+G5AknV4GvSQ1zqCXpMYZ9JLUOINekhp3Qd8NjHPRRRfVwsJC321I0jlj3759X66quXHrzsqgX1hYYGVlpe82JOmckeTxSevcdSNJjTPoJalxBr0kNc6gl6TGGfSS1DiDXpJ6NBhAcuJtMJjdHAa9JPVodXVr9WkY9JLUOINekhpn0EtS4wx6SWrcKc91k+RO4HrgcFW9bFT7EHDZaMjzgL+pqivGPPcx4CvA14CjVbU4o74lqQnz8+M/eJ2fn90cmzmp2QeA24FfP1aoqh8+tpzkF4CnT/L811TVl6dtUJJadujQ6Z/jlEFfVZ9KsjBuXZIAPwR8z2zbkiTNStd99N8NrFbVlyasL+C+JPuSLJ3shZIsJVlJsrK2ttaxLUnSMV2D/ibgrpOsv6qqXgFcB7wlyasnDayqvVW1WFWLc3Njz50vSZrC1EGf5ALg3wAfmjSmqg6O7g8DdwNXTjufJGk6Xbbovxf4QlUdGLcyyc4kFx5bBq4BHuownyRpCqcM+iR3Ab8PXJbkQJI3jlbdyIbdNklelOTe0cN54NNJP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/kJF0ufVJek7eSCaZ9YVUeTvBX4BHA+cGdVfT7JfwFWquoe4FeB/5nkEYZb8jfOoumNDp3+i6hL0jlr6qAHqKp7gXs31N61bvn/Az/YZQ5JUjd+M1aSGmfQS1LjDHpJapxBL0mNy2k42rGzJGvA41M+/SLgyzNs51zme3E834/j+X58XQvvxe6qGvtt07My6LtIslJVi333cTbwvTie78fxfD++rvX3wl03ktQ4g16SGtdi0O/tu4GziO/F8Xw/juf78XVNvxfN7aOXJB2vxS16SdI6Br0kNa6ZoD/Vhcq3kySXJvndJA8n+XySt/XdU9+SnJ/kj5P8v7576VuS5yX5cJIvjH5GXtV3T31K8h9HvycPJbkryTf03dOsNRH0m7xQ+XZyFPjpqvp24JXAW7b5+wHwNuDhvps4S7wH+HhVfRtwOdv4fUlyMfAfgMWqehnDU66fltOp96mJoGdzFyrfNqrqyap6YLT8FYa/yBuv57ttJLkE+AHg/X330rck/wx4NcNrRVBVX62qv+m3q95dAPzT0VXwdnDilfLOea0E/WYuVL4tJVkAXg58pt9OevU/gP8E/EPfjZwF/jmwBvzaaFfW+5Ps7LupvlTVXwK3AfuBJ4Gnq+q+fruavVaCftMXId9Oknwj8FvA26vqmb776UOS64HDVbWv717OEhcArwDeV1UvB54Ftu1nWkmez/B//y8GXgTsTPIj/XY1e60E/WYuVL6tJHkOw5BfrqqP9N1Pj64CXp/kMYa79L4nyf/qt6VeHQAOVNWx/+F9mGHwb1ffC/xFVa1V1d8DHwG+q+eeZq6VoN/Mhcq3jSRhuA/24ar6xb776VNV/WxVXVJVCwx/Ln6nqprbYtusqjoEPJHkslHptcCf9thS3/YDr0yyY/R781oa/HC60zVjzxaTLlTec1t9ugr4UeBzSR4c1d45usav9O+B5dFG0aPAj/fcT2+q6jNJPgw8wPBotT+mwdMheAoESWpcK7tuJEkTGPSS1DiDXpIaZ9BLUuMMeklqnEEvSY0z6CWpcf8IID/e23vL5fgAAAAASUVORK5CYII=\n", "text/plain": [ "
" ] }, "metadata": { "needs_background": "light" }, "output_type": "display_data" } ], "source": [ "import matplotlib.pyplot as plt\n", "X = [0, 2, 5, 9, 7] # tableau avec les abscisses\n", "Y1 = [2*x for x in X] # tableau avec les ordonnées\n", "Y2 = [x + 3 for x in X]\n", "Y3 = [10, 5, 8, 2, 15]\n", "plt.plot(X, Y1, 'bs') # b pour blue, s pour un carré (square) . \n", "plt.plot(X, Y2, 'ro') # r pour red, o pour un cercle. (https://matplotlib.org/api/markers_api.html)\n", "plt.plot(X, Y3, 'gs') # g pour green\n", "plt.show()\n", "plt.close() # Pour fermer la fenêtre graphique. \n", " # Utile si vous nêtes pas sur un fichier jupyter, mais dans un simple éditeur Python" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Les pokemons" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "pokemons = [{'Attaque': '105', 'Nom': 'Aligatueur', 'Points de vie': '85', 'Type': 'Eau'},\n", " {'Attaque': '92', 'Nom': 'Bargantua', 'Points de vie': '70', 'Type': 'Eau'},\n", " {'Attaque': '63', 'Nom': 'Carabaffe', 'Points de vie': '59', 'Type': 'Eau'},\n", " {'Attaque': '100', 'Nom': 'Clamiral', 'Points de vie': '95', 'Type': 'Eau'},\n", " {'Attaque': '125', 'Nom': 'Crefadet', 'Points de vie': '75', 'Type': 'Psy'},\n", " {'Attaque': '80', 'Nom': 'Crocrodil', 'Points de vie': '65', 'Type': 'Eau'},\n", " {'Attaque': '70', 'Nom': 'Deoxys', 'Points de vie': '50', 'Type': 'Psy'},\n", " {'Attaque': '95', 'Nom': 'Deoxys', 'Points de vie': '50', 'Type': 'Psy'},\n", " {'Attaque': '150', 'Nom': 'Deoxys', 'Points de vie': '50', 'Type': 'Psy'},\n", " {'Attaque': '180', 'Nom': 'Deoxys', 'Points de vie': '50', 'Type': 'Psy'},\n", " {'Attaque': '49', 'Nom': 'Ecayon', 'Points de vie': '49', 'Type': 'Eau'},\n", " {'Attaque': '50', 'Nom': 'Eoko', 'Points de vie': '75', 'Type': 'Psy'},\n", " {'Attaque': '73', 'Nom': 'Gamblast', 'Points de vie': '71', 'Type': 'Eau'},\n", " {'Attaque': '70', 'Nom': 'Gobou', 'Points de vie': '50', 'Type': 'Eau'},\n", " {'Attaque': '45', 'Nom': 'Groret', 'Points de vie': '80', 'Type': 'Psy'},\n", " {'Attaque': '75', 'Nom': 'Mateloutre', 'Points de vie': '75', 'Type': 'Eau'},\n", " {'Attaque': '45', 'Nom': 'Mesmerella', 'Points de vie': '60', 'Type': 'Psy'},\n", " {'Attaque': '100', 'Nom': 'Mew', 'Points de vie': '100', 'Type': 'Psy'},\n", " {'Attaque': '110', 'Nom': 'Mewtwo', 'Points de vie': '106', 'Type': 'Psy'},\n", " {'Attaque': '150', 'Nom': 'Mewtwo', 'Points de vie': '106', 'Type': 'Psy'},\n", " {'Attaque': '190', 'Nom': 'Mewtwo', 'Points de vie': '106', 'Type': 'Psy'},\n", " {'Attaque': '25', 'Nom': 'Munna', 'Points de vie': '76', 'Type': 'Psy'},\n", " {'Attaque': '30', 'Nom': 'Nucleos', 'Points de vie': '45', 'Type': 'Psy'},\n", " {'Attaque': '105', 'Nom': 'Octillery', 'Points de vie': '75', 'Type': 'Eau'},\n", " {'Attaque': '23', 'Nom': 'Okeoke', 'Points de vie': '95', 'Type': 'Psy'},\n", " {'Attaque': '80', 'Nom': 'Phione', 'Points de vie': '80', 'Type': 'Eau'},\n", " {'Attaque': '92', 'Nom': 'Poissoroy', 'Points de vie': '80', 'Type': 'Eau'},\n", " {'Attaque': '66', 'Nom': 'Prinplouf', 'Points de vie': '64', 'Type': 'Eau'},\n", " {'Attaque': '84', 'Nom': 'Rosabyss', 'Points de vie': '55', 'Type': 'Eau'},\n", " {'Attaque': '55', 'Nom': 'Siderella', 'Points de vie': '70', 'Type': 'Psy'},\n", " {'Attaque': '25', 'Nom': 'Spoink', 'Points de vie': '60', 'Type': 'Psy'},\n", " {'Attaque': '65', 'Nom': 'Symbios', 'Points de vie': '110', 'Type': 'Psy'},\n", " {'Attaque': '75', 'Nom': 'Tarpaud', 'Points de vie': '90', 'Type': 'Eau'},\n", " {'Attaque': '51', 'Nom': 'Tiplouf', 'Points de vie': '53', 'Type': 'Eau'}]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Nous voulons représenter les Pokémon sur un schéma : Chaque Pokemon est représenté par un point dont l'abscisse est la valeur de ses points de vie, et l'ordonnée la valeur de ses points d'attaque. \n", "\n", "### 1. Ecrire le code qui transforme le dictionnaire `pokemons` \n", "\n", "On veut que les valeurs associées aux clés `Attaque` et `Points de vie` soient de type `ìnt`" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
Cliquer ici pour la réponse \n", "\n", "```python\n", "for dico in pokemons :\n", " dico[\"Attaque\"] = int(dico[\"Attaque\"] )\n", " dico[\"Points de vie\"] = int(dico[\"Points de vie\"])\n", "```\n", "\n", "
" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Votre code" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[{'Attaque': 105, 'Nom': 'Aligatueur', 'Points de vie': 85, 'Type': 'Eau'}, {'Attaque': 92, 'Nom': 'Bargantua', 'Points de vie': 70, 'Type': 'Eau'}, {'Attaque': 63, 'Nom': 'Carabaffe', 'Points de vie': 59, 'Type': 'Eau'}, {'Attaque': 100, 'Nom': 'Clamiral', 'Points de vie': 95, 'Type': 'Eau'}, {'Attaque': 125, 'Nom': 'Crefadet', 'Points de vie': 75, 'Type': 'Psy'}, {'Attaque': 80, 'Nom': 'Crocrodil', 'Points de vie': 65, 'Type': 'Eau'}, {'Attaque': 70, 'Nom': 'Deoxys', 'Points de vie': 50, 'Type': 'Psy'}, {'Attaque': 95, 'Nom': 'Deoxys', 'Points de vie': 50, 'Type': 'Psy'}, {'Attaque': 150, 'Nom': 'Deoxys', 'Points de vie': 50, 'Type': 'Psy'}, {'Attaque': 180, 'Nom': 'Deoxys', 'Points de vie': 50, 'Type': 'Psy'}, {'Attaque': 49, 'Nom': 'Ecayon', 'Points de vie': 49, 'Type': 'Eau'}, {'Attaque': 50, 'Nom': 'Eoko', 'Points de vie': 75, 'Type': 'Psy'}, {'Attaque': 73, 'Nom': 'Gamblast', 'Points de vie': 71, 'Type': 'Eau'}, {'Attaque': 70, 'Nom': 'Gobou', 'Points de vie': 50, 'Type': 'Eau'}, {'Attaque': 45, 'Nom': 'Groret', 'Points de vie': 80, 'Type': 'Psy'}, {'Attaque': 75, 'Nom': 'Mateloutre', 'Points de vie': 75, 'Type': 'Eau'}, {'Attaque': 45, 'Nom': 'Mesmerella', 'Points de vie': 60, 'Type': 'Psy'}, {'Attaque': 100, 'Nom': 'Mew', 'Points de vie': 100, 'Type': 'Psy'}, {'Attaque': 110, 'Nom': 'Mewtwo', 'Points de vie': 106, 'Type': 'Psy'}, {'Attaque': 150, 'Nom': 'Mewtwo', 'Points de vie': 106, 'Type': 'Psy'}, {'Attaque': 190, 'Nom': 'Mewtwo', 'Points de vie': 106, 'Type': 'Psy'}, {'Attaque': 25, 'Nom': 'Munna', 'Points de vie': 76, 'Type': 'Psy'}, {'Attaque': 30, 'Nom': 'Nucleos', 'Points de vie': 45, 'Type': 'Psy'}, {'Attaque': 105, 'Nom': 'Octillery', 'Points de vie': 75, 'Type': 'Eau'}, {'Attaque': 23, 'Nom': 'Okeoke', 'Points de vie': 95, 'Type': 'Psy'}, {'Attaque': 80, 'Nom': 'Phione', 'Points de vie': 80, 'Type': 'Eau'}, {'Attaque': 92, 'Nom': 'Poissoroy', 'Points de vie': 80, 'Type': 'Eau'}, {'Attaque': 66, 'Nom': 'Prinplouf', 'Points de vie': 64, 'Type': 'Eau'}, {'Attaque': 84, 'Nom': 'Rosabyss', 'Points de vie': 55, 'Type': 'Eau'}, {'Attaque': 55, 'Nom': 'Siderella', 'Points de vie': 70, 'Type': 'Psy'}, {'Attaque': 25, 'Nom': 'Spoink', 'Points de vie': 60, 'Type': 'Psy'}, {'Attaque': 65, 'Nom': 'Symbios', 'Points de vie': 110, 'Type': 'Psy'}, {'Attaque': 75, 'Nom': 'Tarpaud', 'Points de vie': 90, 'Type': 'Eau'}, {'Attaque': 51, 'Nom': 'Tiplouf', 'Points de vie': 53, 'Type': 'Eau'}]\n" ] } ], "source": [ "print(pokemons)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 2. Représenter tous les pokémons" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Chaque Pokemon est représenté par un point dont l'abscisse est la valeur de ses points de vie, et l'ordonnée la valeur de ses points d'attaque. " ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [], "source": [ "# Votre code" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
Cliquer ici pour la réponse \n", "\n", "```python\n", "import matplotlib.pyplot as plt\n", "points_de_vie = [pokemon['Points de vie'] for pokemon in pokemons] # Les abscisses\n", "valeur_attaque = [pokemon['Attaque'] for pokemon in pokemons] # Les ordonnées\n", "plt.plot(points_de_vie, valeur_attaque, 'ro', label = \"pokemons\") # construction du graphique\n", "plt.legend() # affiche la légende\n", "plt.show() # affichage du graphique\n", "plt.close()\n", "```\n", "\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 3. Classification des pokemons" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Faites apparaître sur le même graphique, les Pokémons de type 'Eau' en bleu (carré) et les Pokémons de type 'Psy' en rouge (rond).\n", "\n", "On mettra, comme précédemment, leurs points de vie en abscisses et leurs valeurs d'attaques en ordonnées." ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [], "source": [ "# Compléter\n", "\n", "import matplotlib.pyplot as plt\n", "\n", "# Liste des valeurs des points de vie des points de pokemons eau\n", "points_de_vie_eau = [pokemon['Points de vie'] for ... if ... == 'Eau'] \n", "\n", "# Liste des valeurs des attaques des points de pokemons eau\n", "valeur_attaque_eau = ...\n", "\n", "# Liste des valeurs des points de vie des points de pokemons psy\n", "points_de_vie_psy = ...\n", "\n", "# Liste des valeurs des attaques des points de pokemons psy\n", "valeur_attaque_psy = ...\n", "\n", "# afficher les points :\n", "plt.plot(points_de_vie_eau, valeur_attaque_eau, 'bs',label = \"Pokemon Eau\") \n", "plt.plot(points_de_vie_psy, valeur_attaque_psy, 'ro',label = \"Pokemon psy\")\n", "\n", "\n", "plt.plot([65,75,95] , [25,80,125] , 'gs' , label = 'inconnu')\n", "plt.legend()\n", "plt.show() # affichage du graphique\n", "plt.close()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
Cliquer ici pour la réponse \n", "\n", "```python\n", "import matplotlib.pyplot as plt\n", "\n", "# Liste des valeurs des points de vie des points de pokemons eau\n", "points_de_vie_eau = [pokemon['Points de vie'] for pokemon in pokemons if pokemon['Type'] == 'Eau'] \n", "\n", "# Liste des valeurs des attaques des points de pokemons eau\n", "valeur_attaque_eau = [pokemon['Attaque'] for pokemon in pokemons if pokemon['Type'] == 'Eau'] \n", "\n", "# Liste des valeurs des points de vie des points de pokemons psy\n", "points_de_vie_psy = [pokemon['Points de vie'] for pokemon in pokemons if pokemon['Type'] == 'Psy'] \n", "\n", "# Liste des valeurs des attaques des points de pokemons psy\n", "valeur_attaque_psy = [pokemon['Attaque'] for pokemon in pokemons if pokemon['Type'] == 'Psy'] \n", "\n", "# afficher les points :\n", "plt.plot(points_de_vie_eau, valeur_attaque_eau, 'bs',label = \"Pokemon Eau\") \n", "plt.plot(points_de_vie_psy, valeur_attaque_psy, 'ro',label = \"Pokemon psy\")\n", "\n", "\n", "plt.plot([65,75,95] , [25,80,125] , 'gs' , label = 'inconnu')\n", "plt.legend()\n", "plt.show() # affichage du graphique\n", "plt.close()\n", "```\n", "\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "La répartition des points laisse apparaître assez clairement deux classes (catgégories)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "* Un nouveau Pokémon a les caractéristiques suivantes : (points de vie, attaque)= (65, 25). Si vous deviez prédire son type, quel serait-il ?\n", "* Même question avec un Pokémon de caractéristiques (points de vie, attaque)= (75, 80).\n", "* Même question avec un Pokémon de caractéristiques (points de vie, attaque) = (95, 125)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Auteur** Valérie Mousseaux - Lycée Fénelon Ste Marie - Paris\n", "\n", "en collaboration avec Jean-Louis Thirot et Mireille Coilhac\n", "\n", "Publié sous licence CC BY-NC-SA\n", "\n", "\n", "---\n", "\"Creative
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. " ] } ], "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.7.6" } }, "nbformat": 4, "nbformat_minor": 4 }