Created
June 1, 2022 04:38
-
-
Save jimbonant/966f99d55b3d7e8e89f110ca2a1f6513 to your computer and use it in GitHub Desktop.
RandomForest_Iris_dataset.ipynb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"colab": { | |
"name": "RandomForest_Iris_dataset.ipynb", | |
"provenance": [], | |
"authorship_tag": "ABX9TyNDZ5Azj7q6wuFumPm+WMez", | |
"include_colab_link": true | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
}, | |
"language_info": { | |
"name": "python" | |
} | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "view-in-github", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"<a href=\"https://colab.research.google.com/gist/jimbonant/966f99d55b3d7e8e89f110ca2a1f6513/randomforest_iris_dataset.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 35, | |
"metadata": { | |
"id": "bN22nLUBW75f" | |
}, | |
"outputs": [], | |
"source": [ | |
"from sklearn import datasets\n", | |
"from sklearn.model_selection import train_test_split\n", | |
"from sklearn.ensemble import RandomForestClassifier\n", | |
"from sklearn.datasets import make_classification" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"iris = datasets.load_iris()" | |
], | |
"metadata": { | |
"id": "0xuWy6S0YVTz" | |
}, | |
"execution_count": 36, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"iris" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "Z2OQN0OQYa7g", | |
"outputId": "068ff8b6-344f-47e3-8264-5b0d91c6f84a" | |
}, | |
"execution_count": 37, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"{'DESCR': '.. _iris_dataset:\\n\\nIris plants dataset\\n--------------------\\n\\n**Data Set Characteristics:**\\n\\n :Number of Instances: 150 (50 in each of three classes)\\n :Number of Attributes: 4 numeric, predictive attributes and the class\\n :Attribute Information:\\n - sepal length in cm\\n - sepal width in cm\\n - petal length in cm\\n - petal width in cm\\n - class:\\n - Iris-Setosa\\n - Iris-Versicolour\\n - Iris-Virginica\\n \\n :Summary Statistics:\\n\\n ============== ==== ==== ======= ===== ====================\\n Min Max Mean SD Class Correlation\\n ============== ==== ==== ======= ===== ====================\\n sepal length: 4.3 7.9 5.84 0.83 0.7826\\n sepal width: 2.0 4.4 3.05 0.43 -0.4194\\n petal length: 1.0 6.9 3.76 1.76 0.9490 (high!)\\n petal width: 0.1 2.5 1.20 0.76 0.9565 (high!)\\n ============== ==== ==== ======= ===== ====================\\n\\n :Missing Attribute Values: None\\n :Class Distribution: 33.3% for each of 3 classes.\\n :Creator: R.A. Fisher\\n :Donor: Michael Marshall (MARSHALL%PLU@io.arc.nasa.gov)\\n :Date: July, 1988\\n\\nThe famous Iris database, first used by Sir R.A. Fisher. The dataset is taken\\nfrom Fisher\\'s paper. Note that it\\'s the same as in R, but not as in the UCI\\nMachine Learning Repository, which has two wrong data points.\\n\\nThis is perhaps the best known database to be found in the\\npattern recognition literature. Fisher\\'s paper is a classic in the field and\\nis referenced frequently to this day. (See Duda & Hart, for example.) The\\ndata set contains 3 classes of 50 instances each, where each class refers to a\\ntype of iris plant. One class is linearly separable from the other 2; the\\nlatter are NOT linearly separable from each other.\\n\\n.. topic:: References\\n\\n - Fisher, R.A. \"The use of multiple measurements in taxonomic problems\"\\n Annual Eugenics, 7, Part II, 179-188 (1936); also in \"Contributions to\\n Mathematical Statistics\" (John Wiley, NY, 1950).\\n - Duda, R.O., & Hart, P.E. (1973) Pattern Classification and Scene Analysis.\\n (Q327.D83) John Wiley & Sons. ISBN 0-471-22361-1. See page 218.\\n - Dasarathy, B.V. (1980) \"Nosing Around the Neighborhood: A New System\\n Structure and Classification Rule for Recognition in Partially Exposed\\n Environments\". IEEE Transactions on Pattern Analysis and Machine\\n Intelligence, Vol. PAMI-2, No. 1, 67-71.\\n - Gates, G.W. (1972) \"The Reduced Nearest Neighbor Rule\". IEEE Transactions\\n on Information Theory, May 1972, 431-433.\\n - See also: 1988 MLC Proceedings, 54-64. Cheeseman et al\"s AUTOCLASS II\\n conceptual clustering system finds 3 classes in the data.\\n - Many, many more ...',\n", | |
" 'data': array([[5.1, 3.5, 1.4, 0.2],\n", | |
" [4.9, 3. , 1.4, 0.2],\n", | |
" [4.7, 3.2, 1.3, 0.2],\n", | |
" [4.6, 3.1, 1.5, 0.2],\n", | |
" [5. , 3.6, 1.4, 0.2],\n", | |
" [5.4, 3.9, 1.7, 0.4],\n", | |
" [4.6, 3.4, 1.4, 0.3],\n", | |
" [5. , 3.4, 1.5, 0.2],\n", | |
" [4.4, 2.9, 1.4, 0.2],\n", | |
" [4.9, 3.1, 1.5, 0.1],\n", | |
" [5.4, 3.7, 1.5, 0.2],\n", | |
" [4.8, 3.4, 1.6, 0.2],\n", | |
" [4.8, 3. , 1.4, 0.1],\n", | |
" [4.3, 3. , 1.1, 0.1],\n", | |
" [5.8, 4. , 1.2, 0.2],\n", | |
" [5.7, 4.4, 1.5, 0.4],\n", | |
" [5.4, 3.9, 1.3, 0.4],\n", | |
" [5.1, 3.5, 1.4, 0.3],\n", | |
" [5.7, 3.8, 1.7, 0.3],\n", | |
" [5.1, 3.8, 1.5, 0.3],\n", | |
" [5.4, 3.4, 1.7, 0.2],\n", | |
" [5.1, 3.7, 1.5, 0.4],\n", | |
" [4.6, 3.6, 1. , 0.2],\n", | |
" [5.1, 3.3, 1.7, 0.5],\n", | |
" [4.8, 3.4, 1.9, 0.2],\n", | |
" [5. , 3. , 1.6, 0.2],\n", | |
" [5. , 3.4, 1.6, 0.4],\n", | |
" [5.2, 3.5, 1.5, 0.2],\n", | |
" [5.2, 3.4, 1.4, 0.2],\n", | |
" [4.7, 3.2, 1.6, 0.2],\n", | |
" [4.8, 3.1, 1.6, 0.2],\n", | |
" [5.4, 3.4, 1.5, 0.4],\n", | |
" [5.2, 4.1, 1.5, 0.1],\n", | |
" [5.5, 4.2, 1.4, 0.2],\n", | |
" [4.9, 3.1, 1.5, 0.2],\n", | |
" [5. , 3.2, 1.2, 0.2],\n", | |
" [5.5, 3.5, 1.3, 0.2],\n", | |
" [4.9, 3.6, 1.4, 0.1],\n", | |
" [4.4, 3. , 1.3, 0.2],\n", | |
" [5.1, 3.4, 1.5, 0.2],\n", | |
" [5. , 3.5, 1.3, 0.3],\n", | |
" [4.5, 2.3, 1.3, 0.3],\n", | |
" [4.4, 3.2, 1.3, 0.2],\n", | |
" [5. , 3.5, 1.6, 0.6],\n", | |
" [5.1, 3.8, 1.9, 0.4],\n", | |
" [4.8, 3. , 1.4, 0.3],\n", | |
" [5.1, 3.8, 1.6, 0.2],\n", | |
" [4.6, 3.2, 1.4, 0.2],\n", | |
" [5.3, 3.7, 1.5, 0.2],\n", | |
" [5. , 3.3, 1.4, 0.2],\n", | |
" [7. , 3.2, 4.7, 1.4],\n", | |
" [6.4, 3.2, 4.5, 1.5],\n", | |
" [6.9, 3.1, 4.9, 1.5],\n", | |
" [5.5, 2.3, 4. , 1.3],\n", | |
" [6.5, 2.8, 4.6, 1.5],\n", | |
" [5.7, 2.8, 4.5, 1.3],\n", | |
" [6.3, 3.3, 4.7, 1.6],\n", | |
" [4.9, 2.4, 3.3, 1. ],\n", | |
" [6.6, 2.9, 4.6, 1.3],\n", | |
" [5.2, 2.7, 3.9, 1.4],\n", | |
" [5. , 2. , 3.5, 1. ],\n", | |
" [5.9, 3. , 4.2, 1.5],\n", | |
" [6. , 2.2, 4. , 1. ],\n", | |
" [6.1, 2.9, 4.7, 1.4],\n", | |
" [5.6, 2.9, 3.6, 1.3],\n", | |
" [6.7, 3.1, 4.4, 1.4],\n", | |
" [5.6, 3. , 4.5, 1.5],\n", | |
" [5.8, 2.7, 4.1, 1. ],\n", | |
" [6.2, 2.2, 4.5, 1.5],\n", | |
" [5.6, 2.5, 3.9, 1.1],\n", | |
" [5.9, 3.2, 4.8, 1.8],\n", | |
" [6.1, 2.8, 4. , 1.3],\n", | |
" [6.3, 2.5, 4.9, 1.5],\n", | |
" [6.1, 2.8, 4.7, 1.2],\n", | |
" [6.4, 2.9, 4.3, 1.3],\n", | |
" [6.6, 3. , 4.4, 1.4],\n", | |
" [6.8, 2.8, 4.8, 1.4],\n", | |
" [6.7, 3. , 5. , 1.7],\n", | |
" [6. , 2.9, 4.5, 1.5],\n", | |
" [5.7, 2.6, 3.5, 1. ],\n", | |
" [5.5, 2.4, 3.8, 1.1],\n", | |
" [5.5, 2.4, 3.7, 1. ],\n", | |
" [5.8, 2.7, 3.9, 1.2],\n", | |
" [6. , 2.7, 5.1, 1.6],\n", | |
" [5.4, 3. , 4.5, 1.5],\n", | |
" [6. , 3.4, 4.5, 1.6],\n", | |
" [6.7, 3.1, 4.7, 1.5],\n", | |
" [6.3, 2.3, 4.4, 1.3],\n", | |
" [5.6, 3. , 4.1, 1.3],\n", | |
" [5.5, 2.5, 4. , 1.3],\n", | |
" [5.5, 2.6, 4.4, 1.2],\n", | |
" [6.1, 3. , 4.6, 1.4],\n", | |
" [5.8, 2.6, 4. , 1.2],\n", | |
" [5. , 2.3, 3.3, 1. ],\n", | |
" [5.6, 2.7, 4.2, 1.3],\n", | |
" [5.7, 3. , 4.2, 1.2],\n", | |
" [5.7, 2.9, 4.2, 1.3],\n", | |
" [6.2, 2.9, 4.3, 1.3],\n", | |
" [5.1, 2.5, 3. , 1.1],\n", | |
" [5.7, 2.8, 4.1, 1.3],\n", | |
" [6.3, 3.3, 6. , 2.5],\n", | |
" [5.8, 2.7, 5.1, 1.9],\n", | |
" [7.1, 3. , 5.9, 2.1],\n", | |
" [6.3, 2.9, 5.6, 1.8],\n", | |
" [6.5, 3. , 5.8, 2.2],\n", | |
" [7.6, 3. , 6.6, 2.1],\n", | |
" [4.9, 2.5, 4.5, 1.7],\n", | |
" [7.3, 2.9, 6.3, 1.8],\n", | |
" [6.7, 2.5, 5.8, 1.8],\n", | |
" [7.2, 3.6, 6.1, 2.5],\n", | |
" [6.5, 3.2, 5.1, 2. ],\n", | |
" [6.4, 2.7, 5.3, 1.9],\n", | |
" [6.8, 3. , 5.5, 2.1],\n", | |
" [5.7, 2.5, 5. , 2. ],\n", | |
" [5.8, 2.8, 5.1, 2.4],\n", | |
" [6.4, 3.2, 5.3, 2.3],\n", | |
" [6.5, 3. , 5.5, 1.8],\n", | |
" [7.7, 3.8, 6.7, 2.2],\n", | |
" [7.7, 2.6, 6.9, 2.3],\n", | |
" [6. , 2.2, 5. , 1.5],\n", | |
" [6.9, 3.2, 5.7, 2.3],\n", | |
" [5.6, 2.8, 4.9, 2. ],\n", | |
" [7.7, 2.8, 6.7, 2. ],\n", | |
" [6.3, 2.7, 4.9, 1.8],\n", | |
" [6.7, 3.3, 5.7, 2.1],\n", | |
" [7.2, 3.2, 6. , 1.8],\n", | |
" [6.2, 2.8, 4.8, 1.8],\n", | |
" [6.1, 3. , 4.9, 1.8],\n", | |
" [6.4, 2.8, 5.6, 2.1],\n", | |
" [7.2, 3. , 5.8, 1.6],\n", | |
" [7.4, 2.8, 6.1, 1.9],\n", | |
" [7.9, 3.8, 6.4, 2. ],\n", | |
" [6.4, 2.8, 5.6, 2.2],\n", | |
" [6.3, 2.8, 5.1, 1.5],\n", | |
" [6.1, 2.6, 5.6, 1.4],\n", | |
" [7.7, 3. , 6.1, 2.3],\n", | |
" [6.3, 3.4, 5.6, 2.4],\n", | |
" [6.4, 3.1, 5.5, 1.8],\n", | |
" [6. , 3. , 4.8, 1.8],\n", | |
" [6.9, 3.1, 5.4, 2.1],\n", | |
" [6.7, 3.1, 5.6, 2.4],\n", | |
" [6.9, 3.1, 5.1, 2.3],\n", | |
" [5.8, 2.7, 5.1, 1.9],\n", | |
" [6.8, 3.2, 5.9, 2.3],\n", | |
" [6.7, 3.3, 5.7, 2.5],\n", | |
" [6.7, 3. , 5.2, 2.3],\n", | |
" [6.3, 2.5, 5. , 1.9],\n", | |
" [6.5, 3. , 5.2, 2. ],\n", | |
" [6.2, 3.4, 5.4, 2.3],\n", | |
" [5.9, 3. , 5.1, 1.8]]),\n", | |
" 'data_module': 'sklearn.datasets.data',\n", | |
" 'feature_names': ['sepal length (cm)',\n", | |
" 'sepal width (cm)',\n", | |
" 'petal length (cm)',\n", | |
" 'petal width (cm)'],\n", | |
" 'filename': 'iris.csv',\n", | |
" 'frame': None,\n", | |
" 'target': array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n", | |
" 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n", | |
" 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n", | |
" 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n", | |
" 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\n", | |
" 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\n", | |
" 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]),\n", | |
" 'target_names': array(['setosa', 'versicolor', 'virginica'], dtype='<U10')}" | |
] | |
}, | |
"metadata": {}, | |
"execution_count": 37 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"print(iris.target_names)" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "zP4BsEBXZHTT", | |
"outputId": "62e057d0-93ba-43b5-bd02-7af944bad00f" | |
}, | |
"execution_count": 38, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"['setosa' 'versicolor' 'virginica']\n" | |
] | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"print(iris.feature_names)" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "JfL2rTuRZNQ0", | |
"outputId": "b35342a5-f7ec-4cb7-edce-083ba82f2793" | |
}, | |
"execution_count": 39, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"['sepal length (cm)', 'sepal width (cm)', 'petal length (cm)', 'petal width (cm)']\n" | |
] | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"print(iris.target)" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "63npw0bQZpN5", | |
"outputId": "44e79621-8ce3-4211-ec2c-e1f6b3084a1d" | |
}, | |
"execution_count": 40, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", | |
" 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n", | |
" 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2\n", | |
" 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2\n", | |
" 2 2]\n" | |
] | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"print(iris.data)" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "2CUazMX4ZsIq", | |
"outputId": "66aad4e5-f0e2-4ebe-90cd-af9f5d516984" | |
}, | |
"execution_count": 41, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"[[5.1 3.5 1.4 0.2]\n", | |
" [4.9 3. 1.4 0.2]\n", | |
" [4.7 3.2 1.3 0.2]\n", | |
" [4.6 3.1 1.5 0.2]\n", | |
" [5. 3.6 1.4 0.2]\n", | |
" [5.4 3.9 1.7 0.4]\n", | |
" [4.6 3.4 1.4 0.3]\n", | |
" [5. 3.4 1.5 0.2]\n", | |
" [4.4 2.9 1.4 0.2]\n", | |
" [4.9 3.1 1.5 0.1]\n", | |
" [5.4 3.7 1.5 0.2]\n", | |
" [4.8 3.4 1.6 0.2]\n", | |
" [4.8 3. 1.4 0.1]\n", | |
" [4.3 3. 1.1 0.1]\n", | |
" [5.8 4. 1.2 0.2]\n", | |
" [5.7 4.4 1.5 0.4]\n", | |
" [5.4 3.9 1.3 0.4]\n", | |
" [5.1 3.5 1.4 0.3]\n", | |
" [5.7 3.8 1.7 0.3]\n", | |
" [5.1 3.8 1.5 0.3]\n", | |
" [5.4 3.4 1.7 0.2]\n", | |
" [5.1 3.7 1.5 0.4]\n", | |
" [4.6 3.6 1. 0.2]\n", | |
" [5.1 3.3 1.7 0.5]\n", | |
" [4.8 3.4 1.9 0.2]\n", | |
" [5. 3. 1.6 0.2]\n", | |
" [5. 3.4 1.6 0.4]\n", | |
" [5.2 3.5 1.5 0.2]\n", | |
" [5.2 3.4 1.4 0.2]\n", | |
" [4.7 3.2 1.6 0.2]\n", | |
" [4.8 3.1 1.6 0.2]\n", | |
" [5.4 3.4 1.5 0.4]\n", | |
" [5.2 4.1 1.5 0.1]\n", | |
" [5.5 4.2 1.4 0.2]\n", | |
" [4.9 3.1 1.5 0.2]\n", | |
" [5. 3.2 1.2 0.2]\n", | |
" [5.5 3.5 1.3 0.2]\n", | |
" [4.9 3.6 1.4 0.1]\n", | |
" [4.4 3. 1.3 0.2]\n", | |
" [5.1 3.4 1.5 0.2]\n", | |
" [5. 3.5 1.3 0.3]\n", | |
" [4.5 2.3 1.3 0.3]\n", | |
" [4.4 3.2 1.3 0.2]\n", | |
" [5. 3.5 1.6 0.6]\n", | |
" [5.1 3.8 1.9 0.4]\n", | |
" [4.8 3. 1.4 0.3]\n", | |
" [5.1 3.8 1.6 0.2]\n", | |
" [4.6 3.2 1.4 0.2]\n", | |
" [5.3 3.7 1.5 0.2]\n", | |
" [5. 3.3 1.4 0.2]\n", | |
" [7. 3.2 4.7 1.4]\n", | |
" [6.4 3.2 4.5 1.5]\n", | |
" [6.9 3.1 4.9 1.5]\n", | |
" [5.5 2.3 4. 1.3]\n", | |
" [6.5 2.8 4.6 1.5]\n", | |
" [5.7 2.8 4.5 1.3]\n", | |
" [6.3 3.3 4.7 1.6]\n", | |
" [4.9 2.4 3.3 1. ]\n", | |
" [6.6 2.9 4.6 1.3]\n", | |
" [5.2 2.7 3.9 1.4]\n", | |
" [5. 2. 3.5 1. ]\n", | |
" [5.9 3. 4.2 1.5]\n", | |
" [6. 2.2 4. 1. ]\n", | |
" [6.1 2.9 4.7 1.4]\n", | |
" [5.6 2.9 3.6 1.3]\n", | |
" [6.7 3.1 4.4 1.4]\n", | |
" [5.6 3. 4.5 1.5]\n", | |
" [5.8 2.7 4.1 1. ]\n", | |
" [6.2 2.2 4.5 1.5]\n", | |
" [5.6 2.5 3.9 1.1]\n", | |
" [5.9 3.2 4.8 1.8]\n", | |
" [6.1 2.8 4. 1.3]\n", | |
" [6.3 2.5 4.9 1.5]\n", | |
" [6.1 2.8 4.7 1.2]\n", | |
" [6.4 2.9 4.3 1.3]\n", | |
" [6.6 3. 4.4 1.4]\n", | |
" [6.8 2.8 4.8 1.4]\n", | |
" [6.7 3. 5. 1.7]\n", | |
" [6. 2.9 4.5 1.5]\n", | |
" [5.7 2.6 3.5 1. ]\n", | |
" [5.5 2.4 3.8 1.1]\n", | |
" [5.5 2.4 3.7 1. ]\n", | |
" [5.8 2.7 3.9 1.2]\n", | |
" [6. 2.7 5.1 1.6]\n", | |
" [5.4 3. 4.5 1.5]\n", | |
" [6. 3.4 4.5 1.6]\n", | |
" [6.7 3.1 4.7 1.5]\n", | |
" [6.3 2.3 4.4 1.3]\n", | |
" [5.6 3. 4.1 1.3]\n", | |
" [5.5 2.5 4. 1.3]\n", | |
" [5.5 2.6 4.4 1.2]\n", | |
" [6.1 3. 4.6 1.4]\n", | |
" [5.8 2.6 4. 1.2]\n", | |
" [5. 2.3 3.3 1. ]\n", | |
" [5.6 2.7 4.2 1.3]\n", | |
" [5.7 3. 4.2 1.2]\n", | |
" [5.7 2.9 4.2 1.3]\n", | |
" [6.2 2.9 4.3 1.3]\n", | |
" [5.1 2.5 3. 1.1]\n", | |
" [5.7 2.8 4.1 1.3]\n", | |
" [6.3 3.3 6. 2.5]\n", | |
" [5.8 2.7 5.1 1.9]\n", | |
" [7.1 3. 5.9 2.1]\n", | |
" [6.3 2.9 5.6 1.8]\n", | |
" [6.5 3. 5.8 2.2]\n", | |
" [7.6 3. 6.6 2.1]\n", | |
" [4.9 2.5 4.5 1.7]\n", | |
" [7.3 2.9 6.3 1.8]\n", | |
" [6.7 2.5 5.8 1.8]\n", | |
" [7.2 3.6 6.1 2.5]\n", | |
" [6.5 3.2 5.1 2. ]\n", | |
" [6.4 2.7 5.3 1.9]\n", | |
" [6.8 3. 5.5 2.1]\n", | |
" [5.7 2.5 5. 2. ]\n", | |
" [5.8 2.8 5.1 2.4]\n", | |
" [6.4 3.2 5.3 2.3]\n", | |
" [6.5 3. 5.5 1.8]\n", | |
" [7.7 3.8 6.7 2.2]\n", | |
" [7.7 2.6 6.9 2.3]\n", | |
" [6. 2.2 5. 1.5]\n", | |
" [6.9 3.2 5.7 2.3]\n", | |
" [5.6 2.8 4.9 2. ]\n", | |
" [7.7 2.8 6.7 2. ]\n", | |
" [6.3 2.7 4.9 1.8]\n", | |
" [6.7 3.3 5.7 2.1]\n", | |
" [7.2 3.2 6. 1.8]\n", | |
" [6.2 2.8 4.8 1.8]\n", | |
" [6.1 3. 4.9 1.8]\n", | |
" [6.4 2.8 5.6 2.1]\n", | |
" [7.2 3. 5.8 1.6]\n", | |
" [7.4 2.8 6.1 1.9]\n", | |
" [7.9 3.8 6.4 2. ]\n", | |
" [6.4 2.8 5.6 2.2]\n", | |
" [6.3 2.8 5.1 1.5]\n", | |
" [6.1 2.6 5.6 1.4]\n", | |
" [7.7 3. 6.1 2.3]\n", | |
" [6.3 3.4 5.6 2.4]\n", | |
" [6.4 3.1 5.5 1.8]\n", | |
" [6. 3. 4.8 1.8]\n", | |
" [6.9 3.1 5.4 2.1]\n", | |
" [6.7 3.1 5.6 2.4]\n", | |
" [6.9 3.1 5.1 2.3]\n", | |
" [5.8 2.7 5.1 1.9]\n", | |
" [6.8 3.2 5.9 2.3]\n", | |
" [6.7 3.3 5.7 2.5]\n", | |
" [6.7 3. 5.2 2.3]\n", | |
" [6.3 2.5 5. 1.9]\n", | |
" [6.5 3. 5.2 2. ]\n", | |
" [6.2 3.4 5.4 2.3]\n", | |
" [5.9 3. 5.1 1.8]]\n" | |
] | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"X = iris.data" | |
], | |
"metadata": { | |
"id": "zi6Sg7MjZ8dz" | |
}, | |
"execution_count": 42, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"Y = iris.target" | |
], | |
"metadata": { | |
"id": "XRTRGU87Z_dK" | |
}, | |
"execution_count": 43, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"print(X.shape)" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "brdbqMkAaDAJ", | |
"outputId": "8b494ede-86cc-449d-d323-6cb95efac599" | |
}, | |
"execution_count": 44, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"(150, 4)\n" | |
] | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"print(Y.shape)" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "s86Cy2sjaPJo", | |
"outputId": "d6189ff0-b587-48cf-b347-0dcacdfe164f" | |
}, | |
"execution_count": 45, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"(150,)\n" | |
] | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"clf = RandomForestClassifier()\n", | |
"clf.fit(X,Y)" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "G4XQ2FY6aRCB", | |
"outputId": "7a0bd69d-cfff-4dbe-f82d-82bd9237c39a" | |
}, | |
"execution_count": 46, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"RandomForestClassifier()" | |
] | |
}, | |
"metadata": {}, | |
"execution_count": 46 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"print(clf.feature_importances_)" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "GJvuFwaVa0Ay", | |
"outputId": "e711533c-1f4d-44ad-ee56-0fab4803526d" | |
}, | |
"execution_count": 47, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"[0.12814193 0.02990922 0.41155218 0.43039667]\n" | |
] | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"X[0]" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "eiE2wsSYbaYP", | |
"outputId": "6e593c92-fc58-4e99-c8cf-c724ec827ce8" | |
}, | |
"execution_count": 48, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"array([5.1, 3.5, 1.4, 0.2])" | |
] | |
}, | |
"metadata": {}, | |
"execution_count": 48 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"print(clf.predict(X[[0]]))" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "mgBtGrGfbkpL", | |
"outputId": "ef1eea05-f7c3-413a-a4eb-75dfd7c63832" | |
}, | |
"execution_count": 49, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"[0]\n" | |
] | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"print(clf.predict_proba(X[[0]]))" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "mbqOOOMccIht", | |
"outputId": "167903ef-277b-4c7d-ab41-38c944630e5e" | |
}, | |
"execution_count": 50, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"[[1. 0. 0.]]\n" | |
] | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"" | |
], | |
"metadata": { | |
"id": "gQLIjWcdcQgF" | |
}, | |
"execution_count": 50, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"X_train, X_test, Y_train, Y_test = train_test_split(X,Y,test_size=.2)" | |
], | |
"metadata": { | |
"id": "0PDDfwdcccqJ" | |
}, | |
"execution_count": 51, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"X_train.shape, Y_train.shape\n" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "HHTCcKLQctz4", | |
"outputId": "a4258edd-5296-47f8-c756-6a4478e886a9" | |
}, | |
"execution_count": 52, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"((120, 4), (120,))" | |
] | |
}, | |
"metadata": {}, | |
"execution_count": 52 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"X_test.shape, Y_test.shape" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "k--iuDn5dGgZ", | |
"outputId": "4c2b2d12-8263-4ea8-9f3e-040410434335" | |
}, | |
"execution_count": 53, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"((30, 4), (30,))" | |
] | |
}, | |
"metadata": {}, | |
"execution_count": 53 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"clf.fit(X_train,Y_train)" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "Zc4kzcZqdarK", | |
"outputId": "75d8ff27-6637-4c12-f570-fb775c2de57d" | |
}, | |
"execution_count": 54, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"RandomForestClassifier()" | |
] | |
}, | |
"metadata": {}, | |
"execution_count": 54 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"clf.predict(X_test )" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "WAiy1Q_2df64", | |
"outputId": "790b1dd0-27b9-4f4a-ca8d-431a3076a4c8" | |
}, | |
"execution_count": 55, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"array([0, 0, 2, 1, 2, 0, 2, 1, 1, 2, 2, 1, 1, 2, 0, 0, 2, 2, 2, 1, 2, 0,\n", | |
" 2, 2, 0, 0, 0, 2, 0, 0])" | |
] | |
}, | |
"metadata": {}, | |
"execution_count": 55 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"print( Y_test)" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "Sb-h0xkydzlP", | |
"outputId": "19c2161c-1fed-4935-c104-f0f7002afec0" | |
}, | |
"execution_count": 56, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"[0 0 2 1 2 0 1 1 2 2 2 1 1 2 0 0 2 2 2 1 2 0 2 2 0 0 0 2 0 0]\n" | |
] | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"print(clf.score(X_test, Y_test))" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "aUOMtSDHd-Na", | |
"outputId": "c4bbb7b0-109b-4979-e673-d9455ae5e4b4" | |
}, | |
"execution_count": 59, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"0.0\n" | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"name": "stderr", | |
"text": [ | |
"/usr/local/lib/python3.7/dist-packages/sklearn/metrics/_classification.py:217: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison\n", | |
" score = y_true == y_pred\n" | |
] | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"clf.fit(iris.data, iris.target_names[iris.target])" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "JElFOLvseYB9", | |
"outputId": "31d55853-3241-4dc2-fb68-ae3efb613e8e" | |
}, | |
"execution_count": 58, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"RandomForestClassifier()" | |
] | |
}, | |
"metadata": {}, | |
"execution_count": 58 | |
} | |
] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment