{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "### Ananlyse en composantes principales (ACP) : \n", " - Combien de facteurs ? et comment\n", " - impact sur la classification ?\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Charger les données : \n", "On commence par charger le dataset :" ] }, { "cell_type": "code", "execution_count": 51, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "dict_keys(['data', 'target', 'target_names', 'DESCR', 'feature_names'])\n" ] } ], "source": [ "from sklearn.datasets import load_wine\n", "wine = load_wine()\n", "print(wine.keys())" ] }, { "cell_type": "code", "execution_count": 52, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ ".. _wine_dataset:\n", "\n", "Wine recognition dataset\n", "------------------------\n", "\n", "**Data Set Characteristics:**\n", "\n", " :Number of Instances: 178 (50 in each of three classes)\n", " :Number of Attributes: 13 numeric, predictive attributes and the class\n", " :Attribute Information:\n", " \t\t- Alcohol\n", " \t\t- Malic acid\n", " \t\t- Ash\n", "\t\t- Alcalinity of ash \n", " \t\t- Magnesium\n", "\t\t- Total phenols\n", " \t\t- Flavanoids\n", " \t\t- Nonflavanoid phenols\n", " \t\t- Proanthocyanins\n", "\t\t- Color intensity\n", " \t\t- Hue\n", " \t\t- OD280/OD315 of diluted wines\n", " \t\t- Proline\n", "\n", " - class:\n", " - class_0\n", " - class_1\n", " - class_2\n", "\t\t\n", " :Summary Statistics:\n", " \n", " ============================= ==== ===== ======= =====\n", " Min Max Mean SD\n", " ============================= ==== ===== ======= =====\n", " Alcohol: 11.0 14.8 13.0 0.8\n", " Malic Acid: 0.74 5.80 2.34 1.12\n", " Ash: 1.36 3.23 2.36 0.27\n", " Alcalinity of Ash: 10.6 30.0 19.5 3.3\n", " Magnesium: 70.0 162.0 99.7 14.3\n", " Total Phenols: 0.98 3.88 2.29 0.63\n", " Flavanoids: 0.34 5.08 2.03 1.00\n", " Nonflavanoid Phenols: 0.13 0.66 0.36 0.12\n", " Proanthocyanins: 0.41 3.58 1.59 0.57\n", " Colour Intensity: 1.3 13.0 5.1 2.3\n", " Hue: 0.48 1.71 0.96 0.23\n", " OD280/OD315 of diluted wines: 1.27 4.00 2.61 0.71\n", " Proline: 278 1680 746 315\n", " ============================= ==== ===== ======= =====\n", "\n", " :Missing Attribute Values: None\n", " :Class Distribution: class_0 (59), class_1 (71), class_2 (48)\n", " :Creator: R.A. Fisher\n", " :Donor: Michael Marshall (MARSHALL%PLU@io.arc.nasa.gov)\n", " :Date: July, 1988\n", "\n", "This is a copy of UCI ML Wine recognition datasets.\n", "https://archive.ics.uci.edu/ml/machine-learning-databases/wine/wine.data\n", "\n", "The data is the results of a chemical analysis of wines grown in the same\n", "region in Italy by three different cultivators. There are thirteen different\n", "measurements taken for different constituents found in the three types of\n", "wine.\n", "\n", "Original Owners: \n", "\n", "Forina, M. et al, PARVUS - \n", "An Extendible Package for Data Exploration, Classification and Correlation. \n", "Institute of Pharmaceutical and Food Analysis and Technologies,\n", "Via Brigata Salerno, 16147 Genoa, Italy.\n", "\n", "Citation:\n", "\n", "Lichman, M. (2013). UCI Machine Learning Repository\n", "[https://archive.ics.uci.edu/ml]. Irvine, CA: University of California,\n", "School of Information and Computer Science. \n", "\n", ".. topic:: References\n", "\n", " (1) S. Aeberhard, D. Coomans and O. de Vel, \n", " Comparison of Classifiers in High Dimensional Settings, \n", " Tech. Rep. no. 92-02, (1992), Dept. of Computer Science and Dept. of \n", " Mathematics and Statistics, James Cook University of North Queensland. \n", " (Also submitted to Technometrics). \n", "\n", " The data was used with many others for comparing various \n", " classifiers. The classes are separable, though only RDA \n", " has achieved 100% correct classification. \n", " (RDA : 100%, QDA 99.4%, LDA 98.9%, 1NN 96.1% (z-transformed data)) \n", " (All results using the leave-one-out technique) \n", "\n", " (2) S. Aeberhard, D. Coomans and O. de Vel, \n", " \"THE CLASSIFICATION PERFORMANCE OF RDA\" \n", " Tech. Rep. no. 92-01, (1992), Dept. of Computer Science and Dept. of \n", " Mathematics and Statistics, James Cook University of North Queensland. \n", " (Also submitted to Journal of Chemometrics).\n", "\n" ] } ], "source": [ "print(wine.DESCR)" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(178, 13)" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "X = wine.data\n", "X.shape" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[0 1 2]\n" ] } ], "source": [ "y = wine.target\n", "print(np.unique(y))" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "['class_0' 'class_1' 'class_2']\n" ] } ], "source": [ "print(wine.target_names)" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "['alcohol', 'malic_acid', 'ash', 'alcalinity_of_ash', 'magnesium', 'total_phenols', 'flavanoids', 'nonflavanoid_phenols', 'proanthocyanins', 'color_intensity', 'hue', 'od280/od315_of_diluted_wines', 'proline']\n" ] } ], "source": [ "print(wine.feature_names)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### On récapitule : \n", "- Il y a 178 instances. \n", "- Le nombre de features est de 13. \n", "- Chacune des instances appartient soit à la classe 0, 1 ou 2.\n", "\n", "