From da390942548215b5c5c1f2a5e0645315f09cac52 Mon Sep 17 00:00:00 2001 From: "Ricardo Pereira da Costa (pereir33)" Date: Tue, 28 Jun 2022 20:41:15 +0100 Subject: [PATCH] Add files via upload --- car_insurance.ipynb | 71 +++++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 35 deletions(-) diff --git a/car_insurance.ipynb b/car_insurance.ipynb index 159e846..bc254ef 100644 --- a/car_insurance.ipynb +++ b/car_insurance.ipynb @@ -9,7 +9,7 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 65, "metadata": {}, "outputs": [], "source": [ @@ -21,7 +21,7 @@ }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 66, "metadata": {}, "outputs": [ { @@ -66,7 +66,7 @@ }, { "cell_type": "code", - "execution_count": 41, + "execution_count": 67, "metadata": {}, "outputs": [ { @@ -256,7 +256,7 @@ "4 0 1 1.0 " ] }, - "execution_count": 41, + "execution_count": 67, "metadata": {}, "output_type": "execute_result" } @@ -282,7 +282,7 @@ }, { "cell_type": "code", - "execution_count": 42, + "execution_count": 68, "metadata": {}, "outputs": [ { @@ -310,7 +310,7 @@ "dtype: int64" ] }, - "execution_count": 42, + "execution_count": 68, "metadata": {}, "output_type": "execute_result" } @@ -322,7 +322,7 @@ }, { "cell_type": "code", - "execution_count": 43, + "execution_count": 69, "metadata": {}, "outputs": [ { @@ -350,7 +350,7 @@ "dtype: int64" ] }, - "execution_count": 43, + "execution_count": 69, "metadata": {}, "output_type": "execute_result" } @@ -362,7 +362,7 @@ }, { "cell_type": "code", - "execution_count": 44, + "execution_count": 70, "metadata": {}, "outputs": [ { @@ -371,7 +371,7 @@ "0" ] }, - "execution_count": 44, + "execution_count": 70, "metadata": {}, "output_type": "execute_result" } @@ -390,7 +390,7 @@ }, { "cell_type": "code", - "execution_count": 45, + "execution_count": 71, "metadata": {}, "outputs": [ { @@ -580,7 +580,7 @@ "4 0 1 1.0 " ] }, - "execution_count": 45, + "execution_count": 71, "metadata": {}, "output_type": "execute_result" } @@ -591,7 +591,7 @@ }, { "cell_type": "code", - "execution_count": 46, + "execution_count": 72, "metadata": {}, "outputs": [], "source": [ @@ -601,7 +601,7 @@ }, { "cell_type": "code", - "execution_count": 47, + "execution_count": 73, "metadata": {}, "outputs": [ { @@ -629,7 +629,7 @@ "dtype: int64" ] }, - "execution_count": 47, + "execution_count": 73, "metadata": {}, "output_type": "execute_result" } @@ -640,7 +640,7 @@ }, { "cell_type": "code", - "execution_count": 48, + "execution_count": 74, "metadata": {}, "outputs": [ { @@ -842,7 +842,7 @@ "4 1 1.0 " ] }, - "execution_count": 48, + "execution_count": 74, "metadata": {}, "output_type": "execute_result" } @@ -872,7 +872,7 @@ }, { "cell_type": "code", - "execution_count": 64, + "execution_count": 75, "metadata": {}, "outputs": [ { @@ -1110,7 +1110,7 @@ }, { "cell_type": "code", - "execution_count": 50, + "execution_count": 76, "metadata": {}, "outputs": [ { @@ -1360,7 +1360,7 @@ }, { "cell_type": "code", - "execution_count": 51, + "execution_count": 77, "metadata": {}, "outputs": [], "source": [ @@ -1374,7 +1374,7 @@ }, { "cell_type": "code", - "execution_count": 52, + "execution_count": 78, "metadata": {}, "outputs": [ { @@ -1383,11 +1383,12 @@ "text": [ "Decision tree regression\n", "The accuricy for the train set is :1.0\n", - "The accuricy for the test set is :0.791002044989775\n" + "The accuricy for the test set is :0.7950920245398773\n" ] } ], "source": [ + "#Building a decision tree classifier model to make predictions\n", "from sklearn.tree import DecisionTreeClassifier\n", "modelDT = DecisionTreeClassifier()\n", "modelDT = modelDT.fit(X_train, y_train)\n", @@ -1399,7 +1400,7 @@ }, { "cell_type": "code", - "execution_count": 53, + "execution_count": 79, "metadata": {}, "outputs": [ { @@ -1412,6 +1413,7 @@ } ], "source": [ + "#Building a KNeighbours classifier model to make predictions\n", "from sklearn.neighbors import KNeighborsClassifier\n", "modelKNC = KNeighborsClassifier()\n", "modelKNC = modelKNC.fit(X_train,y_train)\n", @@ -1429,7 +1431,7 @@ }, { "cell_type": "code", - "execution_count": 54, + "execution_count": 90, "metadata": {}, "outputs": [], "source": [ @@ -1444,13 +1446,12 @@ "ParamsKNC = {\"n_neighbors\":[5,7, 8, 10],\n", " \"metric\": [\"euclidean\", \"manhattan\", \"chebyshev\", \"minkowski\"],\n", " \"algorithm\" : [\"auto\",\"ball_tree\",\"kd_tree\",\"brute\"],\n", - " \"weights\": [\"uniform\",\"distance\"],\n", - " \"p\" :[1,2]}" + " \"weights\": [\"uniform\",\"distance\"]}" ] }, { "cell_type": "code", - "execution_count": 55, + "execution_count": 81, "metadata": {}, "outputs": [], "source": [ @@ -1465,14 +1466,14 @@ }, { "cell_type": "code", - "execution_count": 56, + "execution_count": 82, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "{'criterion': 'gini', 'max_depth': 7, 'max_features': None, 'min_samples_leaf': 1, 'min_weight_fraction_leaf': 0.1, 'splitter': 'random'}\n" + "{'criterion': 'gini', 'max_depth': 11, 'max_features': None, 'min_samples_leaf': 9, 'min_weight_fraction_leaf': 0.1, 'splitter': 'random'}\n" ] } ], @@ -1483,7 +1484,7 @@ }, { "cell_type": "code", - "execution_count": 57, + "execution_count": 91, "metadata": {}, "outputs": [], "source": [ @@ -1497,14 +1498,14 @@ }, { "cell_type": "code", - "execution_count": 58, + "execution_count": 92, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "{'algorithm': 'auto', 'metric': 'manhattan', 'n_neighbors': 10, 'p': 1, 'weights': 'uniform'}\n" + "{'algorithm': 'auto', 'metric': 'manhattan', 'n_neighbors': 10, 'weights': 'uniform'}\n" ] } ], @@ -1522,7 +1523,7 @@ }, { "cell_type": "code", - "execution_count": 59, + "execution_count": 85, "metadata": {}, "outputs": [ { @@ -1547,7 +1548,7 @@ }, { "cell_type": "code", - "execution_count": 60, + "execution_count": 86, "metadata": {}, "outputs": [ { @@ -1561,7 +1562,7 @@ ], "source": [ "#KNeighbours Classifier using the best parameters found\n", - "modelKNC = KNeighborsClassifier(algorithm=\"auto\",metric=\"manhattan\",n_neighbors=10,p=1,weights=\"uniform\")\n", + "modelKNC = KNeighborsClassifier(algorithm=\"auto\",metric=\"manhattan\",n_neighbors=10,weights=\"uniform\")\n", "modelKNC = modelKNC.fit(X_train,y_train)\n", "modelKNC.predict(X_test)\n", "print (\"The accuricy for the train set is :\" + str(modelKNC.score(X_train,y_train)))\n",