diff --git a/decision tree classification.ipynb b/decision tree classification.ipynb index aa469fa..72186d6 100644 --- a/decision tree classification.ipynb +++ b/decision tree classification.ipynb @@ -11,7 +11,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 25, "metadata": {}, "outputs": [], "source": [ @@ -55,7 +55,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 26, "metadata": {}, "outputs": [], "source": [ @@ -91,7 +91,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 27, "metadata": {}, "outputs": [], "source": [ @@ -334,7 +334,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 28, "metadata": { "scrolled": false }, @@ -374,7 +374,7 @@ " 3.5\n", " 1.4\n", " 0.2\n", - " Setosa\n", + " Iris-setosa\n", " \n", " \n", " 1\n", @@ -382,7 +382,7 @@ " 3.0\n", " 1.4\n", " 0.2\n", - " Setosa\n", + " Iris-setosa\n", " \n", " \n", " 2\n", @@ -390,7 +390,7 @@ " 3.2\n", " 1.3\n", " 0.2\n", - " Setosa\n", + " Iris-setosa\n", " \n", " \n", " 3\n", @@ -398,7 +398,7 @@ " 3.1\n", " 1.5\n", " 0.2\n", - " Setosa\n", + " Iris-setosa\n", " \n", " \n", " 4\n", @@ -406,7 +406,7 @@ " 3.6\n", " 1.4\n", " 0.2\n", - " Setosa\n", + " Iris-setosa\n", " \n", " \n", " ...\n", @@ -422,7 +422,7 @@ " 3.0\n", " 5.2\n", " 2.3\n", - " Virginica\n", + " Iris-virginica\n", " \n", " \n", " 146\n", @@ -430,7 +430,7 @@ " 2.5\n", " 5.0\n", " 1.9\n", - " Virginica\n", + " Iris-virginica\n", " \n", " \n", " 147\n", @@ -438,7 +438,7 @@ " 3.0\n", " 5.2\n", " 2.0\n", - " Virginica\n", + " Iris-virginica\n", " \n", " \n", " 148\n", @@ -446,7 +446,7 @@ " 3.4\n", " 5.4\n", " 2.3\n", - " Virginica\n", + " Iris-virginica\n", " \n", " \n", " 149\n", @@ -454,7 +454,7 @@ " 3.0\n", " 5.1\n", " 1.8\n", - " Virginica\n", + " Iris-virginica\n", " \n", " \n", "\n", @@ -462,30 +462,30 @@ "" ], "text/plain": [ - " sepal_length sepal_width petal_length petal_width type\n", - "0 5.1 3.5 1.4 0.2 Setosa\n", - "1 4.9 3.0 1.4 0.2 Setosa\n", - "2 4.7 3.2 1.3 0.2 Setosa\n", - "3 4.6 3.1 1.5 0.2 Setosa\n", - "4 5.0 3.6 1.4 0.2 Setosa\n", - ".. ... ... ... ... ...\n", - "145 6.7 3.0 5.2 2.3 Virginica\n", - "146 6.3 2.5 5.0 1.9 Virginica\n", - "147 6.5 3.0 5.2 2.0 Virginica\n", - "148 6.2 3.4 5.4 2.3 Virginica\n", - "149 5.9 3.0 5.1 1.8 Virginica\n", + " sepal_length sepal_width petal_length petal_width type\n", + "0 5.1 3.5 1.4 0.2 Iris-setosa\n", + "1 4.9 3.0 1.4 0.2 Iris-setosa\n", + "2 4.7 3.2 1.3 0.2 Iris-setosa\n", + "3 4.6 3.1 1.5 0.2 Iris-setosa\n", + "4 5.0 3.6 1.4 0.2 Iris-setosa\n", + ".. ... ... ... ... ...\n", + "145 6.7 3.0 5.2 2.3 Iris-virginica\n", + "146 6.3 2.5 5.0 1.9 Iris-virginica\n", + "147 6.5 3.0 5.2 2.0 Iris-virginica\n", + "148 6.2 3.4 5.4 2.3 Iris-virginica\n", + "149 5.9 3.0 5.1 1.8 Iris-virginica\n", "\n", "[150 rows x 5 columns]" ] }, - "execution_count": 2, + "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "col_names = ['sepal_length', 'sepal_width', 'petal_length', 'petal_width', 'type']\n", - "data = pd.read_csv(\"iris.csv\", skiprows=1, header=None, names=col_names)\n", + "data = pd.read_csv(\"iris_data.csv\", names=col_names)\n", "data" ] }, @@ -527,7 +527,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 29, "metadata": {}, "outputs": [], "source": [ @@ -548,7 +548,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 30, "metadata": {}, "outputs": [], "source": [ @@ -567,7 +567,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 31, "metadata": {}, "outputs": [ { @@ -575,16 +575,16 @@ "output_type": "stream", "text": [ "X_2 ≤ 1.9 ? 0.337\n", - "1 : left: Setosa\n", + "1 : left: Iris-setosa\n", "1 : right: X_3 ≤ 1.5 ? 0.427\n", "2 : left: X_2 ≤ 4.9 ? 0.051\n", - "3 : left: Versicolor\n", - "3 : right: Virginica\n", + "3 : left: Iris-versicolor\n", + "3 : right: Iris-virginica\n", "2 : right: X_2 ≤ 5.0 ? 0.02\n", "3 : left: X_1 ≤ 2.8 ? 0.208\n", - "4 : left: Virginica\n", - "4 : right: Versicolor\n", - "3 : right: Virginica\n" + "4 : left: Iris-virginica\n", + "4 : right: Iris-versicolor\n", + "3 : right: Iris-virginica\n" ] } ], @@ -598,12 +598,12 @@ "source": [ "## Testing the model\n", "\n", - "We are using the definded method predict() to determine the classes of the Test dataset" + "We are using the definded method predict() to determine the classes of the Test dataset - those will be stored in the Y_pred which we will than compare to Y_test with the help of sklearn library function called accuracy_score" ] }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 32, "metadata": {}, "outputs": [ { @@ -612,7 +612,7 @@ "0.9333333333333333" ] }, - "execution_count": 8, + "execution_count": 32, "metadata": {}, "output_type": "execute_result" } @@ -648,7 +648,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 33, "metadata": {}, "outputs": [], "source": [ @@ -657,7 +657,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 34, "metadata": {}, "outputs": [ { @@ -787,7 +787,7 @@ "[400 rows x 4 columns]" ] }, - "execution_count": 10, + "execution_count": 34, "metadata": {}, "output_type": "execute_result" } @@ -805,7 +805,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 35, "metadata": {}, "outputs": [ { @@ -947,7 +947,7 @@ "[400 rows x 5 columns]" ] }, - "execution_count": 11, + "execution_count": 35, "metadata": {}, "output_type": "execute_result" } @@ -972,7 +972,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 36, "metadata": {}, "outputs": [], "source": [ @@ -985,7 +985,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 37, "metadata": {}, "outputs": [ { @@ -994,7 +994,7 @@ "(320, 80)" ] }, - "execution_count": 13, + "execution_count": 37, "metadata": {}, "output_type": "execute_result" } @@ -1012,7 +1012,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 38, "metadata": {}, "outputs": [], "source": [ @@ -1029,7 +1029,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 39, "metadata": { "scrolled": false }, @@ -1143,7 +1143,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 40, "metadata": {}, "outputs": [ { @@ -1152,7 +1152,7 @@ "0.8625" ] }, - "execution_count": 16, + "execution_count": 40, "metadata": {}, "output_type": "execute_result" }