MLD-FALL-2022 / Multiple disease prediction system - diabetes.ipynb
Multiple disease prediction system - diabetes.ipynb
Raw
{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"Multiple disease prediction system - diabetes.ipynb","provenance":[],"collapsed_sections":[],"authorship_tag":"ABX9TyNUMtWtqiQOs+bSuSretvw5"},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","metadata":{"id":"LnPbntVRnfvV"},"source":["Importing the Dependencies"]},{"cell_type":"code","metadata":{"id":"-71UtHzNVWjB","executionInfo":{"status":"ok","timestamp":1653200161038,"user_tz":-330,"elapsed":1362,"user":{"displayName":"siddhardh selvam","userId":"13966379820454708749"}}},"source":["import numpy as np\n","import pandas as pd\n","from sklearn.model_selection import train_test_split\n","from sklearn import svm\n","from sklearn.metrics import accuracy_score"],"execution_count":1,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"bmfOfG8joBBy"},"source":["Data Collection and Analysis\n","\n","PIMA Diabetes Dataset"]},{"cell_type":"code","metadata":{"id":"Xpw6Mj_pn_TL","executionInfo":{"status":"ok","timestamp":1653200161039,"user_tz":-330,"elapsed":37,"user":{"displayName":"siddhardh selvam","userId":"13966379820454708749"}}},"source":["# loading the diabetes dataset to a pandas DataFrame\n","diabetes_dataset = pd.read_csv('/content/diabetes.csv') "],"execution_count":2,"outputs":[]},{"cell_type":"code","metadata":{"colab":{"base_uri":"https://localhost:8080/","height":206},"id":"-tjO09ncovoh","executionInfo":{"status":"ok","timestamp":1653200161040,"user_tz":-330,"elapsed":36,"user":{"displayName":"siddhardh selvam","userId":"13966379820454708749"}},"outputId":"f4faaf8a-3fc8-413a-bbd4-bb272589a73c"},"source":["# printing the first 5 rows of the dataset\n","diabetes_dataset.head()"],"execution_count":3,"outputs":[{"output_type":"execute_result","data":{"text/plain":["   Pregnancies  Glucose  BloodPressure  SkinThickness  Insulin   BMI  \\\n","0            6      148             72             35        0  33.6   \n","1            1       85             66             29        0  26.6   \n","2            8      183             64              0        0  23.3   \n","3            1       89             66             23       94  28.1   \n","4            0      137             40             35      168  43.1   \n","\n","   DiabetesPedigreeFunction  Age  Outcome  \n","0                     0.627   50        1  \n","1                     0.351   31        0  \n","2                     0.672   32        1  \n","3                     0.167   21        0  \n","4                     2.288   33        1  "],"text/html":["\n","  <div id=\"df-543bb76d-9958-491b-8063-13990fcca102\">\n","    <div class=\"colab-df-container\">\n","      <div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>Pregnancies</th>\n","      <th>Glucose</th>\n","      <th>BloodPressure</th>\n","      <th>SkinThickness</th>\n","      <th>Insulin</th>\n","      <th>BMI</th>\n","      <th>DiabetesPedigreeFunction</th>\n","      <th>Age</th>\n","      <th>Outcome</th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>0</th>\n","      <td>6</td>\n","      <td>148</td>\n","      <td>72</td>\n","      <td>35</td>\n","      <td>0</td>\n","      <td>33.6</td>\n","      <td>0.627</td>\n","      <td>50</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>1</th>\n","      <td>1</td>\n","      <td>85</td>\n","      <td>66</td>\n","      <td>29</td>\n","      <td>0</td>\n","      <td>26.6</td>\n","      <td>0.351</td>\n","      <td>31</td>\n","      <td>0</td>\n","    </tr>\n","    <tr>\n","      <th>2</th>\n","      <td>8</td>\n","      <td>183</td>\n","      <td>64</td>\n","      <td>0</td>\n","      <td>0</td>\n","      <td>23.3</td>\n","      <td>0.672</td>\n","      <td>32</td>\n","      <td>1</td>\n","    </tr>\n","    <tr>\n","      <th>3</th>\n","      <td>1</td>\n","      <td>89</td>\n","      <td>66</td>\n","      <td>23</td>\n","      <td>94</td>\n","      <td>28.1</td>\n","      <td>0.167</td>\n","      <td>21</td>\n","      <td>0</td>\n","    </tr>\n","    <tr>\n","      <th>4</th>\n","      <td>0</td>\n","      <td>137</td>\n","      <td>40</td>\n","      <td>35</td>\n","      <td>168</td>\n","      <td>43.1</td>\n","      <td>2.288</td>\n","      <td>33</td>\n","      <td>1</td>\n","    </tr>\n","  </tbody>\n","</table>\n","</div>\n","      <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-543bb76d-9958-491b-8063-13990fcca102')\"\n","              title=\"Convert this dataframe to an interactive table.\"\n","              style=\"display:none;\">\n","        \n","  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n","       width=\"24px\">\n","    <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n","    <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n","  </svg>\n","      </button>\n","      \n","  <style>\n","    .colab-df-container {\n","      display:flex;\n","      flex-wrap:wrap;\n","      gap: 12px;\n","    }\n","\n","    .colab-df-convert {\n","      background-color: #E8F0FE;\n","      border: none;\n","      border-radius: 50%;\n","      cursor: pointer;\n","      display: none;\n","      fill: #1967D2;\n","      height: 32px;\n","      padding: 0 0 0 0;\n","      width: 32px;\n","    }\n","\n","    .colab-df-convert:hover {\n","      background-color: #E2EBFA;\n","      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n","      fill: #174EA6;\n","    }\n","\n","    [theme=dark] .colab-df-convert {\n","      background-color: #3B4455;\n","      fill: #D2E3FC;\n","    }\n","\n","    [theme=dark] .colab-df-convert:hover {\n","      background-color: #434B5C;\n","      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n","      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n","      fill: #FFFFFF;\n","    }\n","  </style>\n","\n","      <script>\n","        const buttonEl =\n","          document.querySelector('#df-543bb76d-9958-491b-8063-13990fcca102 button.colab-df-convert');\n","        buttonEl.style.display =\n","          google.colab.kernel.accessAllowed ? 'block' : 'none';\n","\n","        async function convertToInteractive(key) {\n","          const element = document.querySelector('#df-543bb76d-9958-491b-8063-13990fcca102');\n","          const dataTable =\n","            await google.colab.kernel.invokeFunction('convertToInteractive',\n","                                                     [key], {});\n","          if (!dataTable) return;\n","\n","          const docLinkHtml = 'Like what you see? Visit the ' +\n","            '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n","            + ' to learn more about interactive tables.';\n","          element.innerHTML = '';\n","          dataTable['output_type'] = 'display_data';\n","          await google.colab.output.renderOutput(dataTable, element);\n","          const docLink = document.createElement('div');\n","          docLink.innerHTML = docLinkHtml;\n","          element.appendChild(docLink);\n","        }\n","      </script>\n","    </div>\n","  </div>\n","  "]},"metadata":{},"execution_count":3}]},{"cell_type":"code","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"lynParo6pEMB","executionInfo":{"status":"ok","timestamp":1653200161040,"user_tz":-330,"elapsed":28,"user":{"displayName":"siddhardh selvam","userId":"13966379820454708749"}},"outputId":"b8e97658-d5ae-4407-e3c0-f4b7b0d0321e"},"source":["# number of rows and Columns in this dataset\n","diabetes_dataset.shape"],"execution_count":4,"outputs":[{"output_type":"execute_result","data":{"text/plain":["(768, 9)"]},"metadata":{},"execution_count":4}]},{"cell_type":"code","metadata":{"colab":{"base_uri":"https://localhost:8080/","height":300},"id":"3NDJOlrEpmoL","executionInfo":{"status":"ok","timestamp":1653200161041,"user_tz":-330,"elapsed":26,"user":{"displayName":"siddhardh selvam","userId":"13966379820454708749"}},"outputId":"1a166b9c-0ec1-42dc-e0f4-32924aa1ab65"},"source":["# getting the statistical measures of the data\n","diabetes_dataset.describe()"],"execution_count":5,"outputs":[{"output_type":"execute_result","data":{"text/plain":["       Pregnancies     Glucose  BloodPressure  SkinThickness     Insulin  \\\n","count   768.000000  768.000000     768.000000     768.000000  768.000000   \n","mean      3.845052  120.894531      69.105469      20.536458   79.799479   \n","std       3.369578   31.972618      19.355807      15.952218  115.244002   \n","min       0.000000    0.000000       0.000000       0.000000    0.000000   \n","25%       1.000000   99.000000      62.000000       0.000000    0.000000   \n","50%       3.000000  117.000000      72.000000      23.000000   30.500000   \n","75%       6.000000  140.250000      80.000000      32.000000  127.250000   \n","max      17.000000  199.000000     122.000000      99.000000  846.000000   \n","\n","              BMI  DiabetesPedigreeFunction         Age     Outcome  \n","count  768.000000                768.000000  768.000000  768.000000  \n","mean    31.992578                  0.471876   33.240885    0.348958  \n","std      7.884160                  0.331329   11.760232    0.476951  \n","min      0.000000                  0.078000   21.000000    0.000000  \n","25%     27.300000                  0.243750   24.000000    0.000000  \n","50%     32.000000                  0.372500   29.000000    0.000000  \n","75%     36.600000                  0.626250   41.000000    1.000000  \n","max     67.100000                  2.420000   81.000000    1.000000  "],"text/html":["\n","  <div id=\"df-e3ca105c-2704-4b75-87c3-2eac2e0e898f\">\n","    <div class=\"colab-df-container\">\n","      <div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>Pregnancies</th>\n","      <th>Glucose</th>\n","      <th>BloodPressure</th>\n","      <th>SkinThickness</th>\n","      <th>Insulin</th>\n","      <th>BMI</th>\n","      <th>DiabetesPedigreeFunction</th>\n","      <th>Age</th>\n","      <th>Outcome</th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>count</th>\n","      <td>768.000000</td>\n","      <td>768.000000</td>\n","      <td>768.000000</td>\n","      <td>768.000000</td>\n","      <td>768.000000</td>\n","      <td>768.000000</td>\n","      <td>768.000000</td>\n","      <td>768.000000</td>\n","      <td>768.000000</td>\n","    </tr>\n","    <tr>\n","      <th>mean</th>\n","      <td>3.845052</td>\n","      <td>120.894531</td>\n","      <td>69.105469</td>\n","      <td>20.536458</td>\n","      <td>79.799479</td>\n","      <td>31.992578</td>\n","      <td>0.471876</td>\n","      <td>33.240885</td>\n","      <td>0.348958</td>\n","    </tr>\n","    <tr>\n","      <th>std</th>\n","      <td>3.369578</td>\n","      <td>31.972618</td>\n","      <td>19.355807</td>\n","      <td>15.952218</td>\n","      <td>115.244002</td>\n","      <td>7.884160</td>\n","      <td>0.331329</td>\n","      <td>11.760232</td>\n","      <td>0.476951</td>\n","    </tr>\n","    <tr>\n","      <th>min</th>\n","      <td>0.000000</td>\n","      <td>0.000000</td>\n","      <td>0.000000</td>\n","      <td>0.000000</td>\n","      <td>0.000000</td>\n","      <td>0.000000</td>\n","      <td>0.078000</td>\n","      <td>21.000000</td>\n","      <td>0.000000</td>\n","    </tr>\n","    <tr>\n","      <th>25%</th>\n","      <td>1.000000</td>\n","      <td>99.000000</td>\n","      <td>62.000000</td>\n","      <td>0.000000</td>\n","      <td>0.000000</td>\n","      <td>27.300000</td>\n","      <td>0.243750</td>\n","      <td>24.000000</td>\n","      <td>0.000000</td>\n","    </tr>\n","    <tr>\n","      <th>50%</th>\n","      <td>3.000000</td>\n","      <td>117.000000</td>\n","      <td>72.000000</td>\n","      <td>23.000000</td>\n","      <td>30.500000</td>\n","      <td>32.000000</td>\n","      <td>0.372500</td>\n","      <td>29.000000</td>\n","      <td>0.000000</td>\n","    </tr>\n","    <tr>\n","      <th>75%</th>\n","      <td>6.000000</td>\n","      <td>140.250000</td>\n","      <td>80.000000</td>\n","      <td>32.000000</td>\n","      <td>127.250000</td>\n","      <td>36.600000</td>\n","      <td>0.626250</td>\n","      <td>41.000000</td>\n","      <td>1.000000</td>\n","    </tr>\n","    <tr>\n","      <th>max</th>\n","      <td>17.000000</td>\n","      <td>199.000000</td>\n","      <td>122.000000</td>\n","      <td>99.000000</td>\n","      <td>846.000000</td>\n","      <td>67.100000</td>\n","      <td>2.420000</td>\n","      <td>81.000000</td>\n","      <td>1.000000</td>\n","    </tr>\n","  </tbody>\n","</table>\n","</div>\n","      <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-e3ca105c-2704-4b75-87c3-2eac2e0e898f')\"\n","              title=\"Convert this dataframe to an interactive table.\"\n","              style=\"display:none;\">\n","        \n","  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n","       width=\"24px\">\n","    <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n","    <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n","  </svg>\n","      </button>\n","      \n","  <style>\n","    .colab-df-container {\n","      display:flex;\n","      flex-wrap:wrap;\n","      gap: 12px;\n","    }\n","\n","    .colab-df-convert {\n","      background-color: #E8F0FE;\n","      border: none;\n","      border-radius: 50%;\n","      cursor: pointer;\n","      display: none;\n","      fill: #1967D2;\n","      height: 32px;\n","      padding: 0 0 0 0;\n","      width: 32px;\n","    }\n","\n","    .colab-df-convert:hover {\n","      background-color: #E2EBFA;\n","      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n","      fill: #174EA6;\n","    }\n","\n","    [theme=dark] .colab-df-convert {\n","      background-color: #3B4455;\n","      fill: #D2E3FC;\n","    }\n","\n","    [theme=dark] .colab-df-convert:hover {\n","      background-color: #434B5C;\n","      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n","      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n","      fill: #FFFFFF;\n","    }\n","  </style>\n","\n","      <script>\n","        const buttonEl =\n","          document.querySelector('#df-e3ca105c-2704-4b75-87c3-2eac2e0e898f button.colab-df-convert');\n","        buttonEl.style.display =\n","          google.colab.kernel.accessAllowed ? 'block' : 'none';\n","\n","        async function convertToInteractive(key) {\n","          const element = document.querySelector('#df-e3ca105c-2704-4b75-87c3-2eac2e0e898f');\n","          const dataTable =\n","            await google.colab.kernel.invokeFunction('convertToInteractive',\n","                                                     [key], {});\n","          if (!dataTable) return;\n","\n","          const docLinkHtml = 'Like what you see? Visit the ' +\n","            '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n","            + ' to learn more about interactive tables.';\n","          element.innerHTML = '';\n","          dataTable['output_type'] = 'display_data';\n","          await google.colab.output.renderOutput(dataTable, element);\n","          const docLink = document.createElement('div');\n","          docLink.innerHTML = docLinkHtml;\n","          element.appendChild(docLink);\n","        }\n","      </script>\n","    </div>\n","  </div>\n","  "]},"metadata":{},"execution_count":5}]},{"cell_type":"code","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"LrpHzaGpp5dQ","executionInfo":{"status":"ok","timestamp":1653200161043,"user_tz":-330,"elapsed":27,"user":{"displayName":"siddhardh selvam","userId":"13966379820454708749"}},"outputId":"5da75a35-5065-4c08-abb1-13bc921dec5a"},"source":["diabetes_dataset['Outcome'].value_counts()"],"execution_count":6,"outputs":[{"output_type":"execute_result","data":{"text/plain":["0    500\n","1    268\n","Name: Outcome, dtype: int64"]},"metadata":{},"execution_count":6}]},{"cell_type":"markdown","metadata":{"id":"cB1qRaNcqeh5"},"source":["0 --> Non-Diabetic\n","\n","1 --> Diabetic"]},{"cell_type":"code","metadata":{"colab":{"base_uri":"https://localhost:8080/","height":143},"id":"I6MWR0k_qSCK","executionInfo":{"status":"ok","timestamp":1653200161045,"user_tz":-330,"elapsed":27,"user":{"displayName":"siddhardh selvam","userId":"13966379820454708749"}},"outputId":"1e817bc0-c41e-4181-a8e5-37885e765862"},"source":["diabetes_dataset.groupby('Outcome').mean()"],"execution_count":7,"outputs":[{"output_type":"execute_result","data":{"text/plain":["         Pregnancies     Glucose  BloodPressure  SkinThickness     Insulin  \\\n","Outcome                                                                      \n","0           3.298000  109.980000      68.184000      19.664000   68.792000   \n","1           4.865672  141.257463      70.824627      22.164179  100.335821   \n","\n","               BMI  DiabetesPedigreeFunction        Age  \n","Outcome                                                  \n","0        30.304200                  0.429734  31.190000  \n","1        35.142537                  0.550500  37.067164  "],"text/html":["\n","  <div id=\"df-d6444b5f-72b8-4e7e-b7a2-6fc0efdc7816\">\n","    <div class=\"colab-df-container\">\n","      <div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>Pregnancies</th>\n","      <th>Glucose</th>\n","      <th>BloodPressure</th>\n","      <th>SkinThickness</th>\n","      <th>Insulin</th>\n","      <th>BMI</th>\n","      <th>DiabetesPedigreeFunction</th>\n","      <th>Age</th>\n","    </tr>\n","    <tr>\n","      <th>Outcome</th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","      <th></th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>0</th>\n","      <td>3.298000</td>\n","      <td>109.980000</td>\n","      <td>68.184000</td>\n","      <td>19.664000</td>\n","      <td>68.792000</td>\n","      <td>30.304200</td>\n","      <td>0.429734</td>\n","      <td>31.190000</td>\n","    </tr>\n","    <tr>\n","      <th>1</th>\n","      <td>4.865672</td>\n","      <td>141.257463</td>\n","      <td>70.824627</td>\n","      <td>22.164179</td>\n","      <td>100.335821</td>\n","      <td>35.142537</td>\n","      <td>0.550500</td>\n","      <td>37.067164</td>\n","    </tr>\n","  </tbody>\n","</table>\n","</div>\n","      <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-d6444b5f-72b8-4e7e-b7a2-6fc0efdc7816')\"\n","              title=\"Convert this dataframe to an interactive table.\"\n","              style=\"display:none;\">\n","        \n","  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n","       width=\"24px\">\n","    <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n","    <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n","  </svg>\n","      </button>\n","      \n","  <style>\n","    .colab-df-container {\n","      display:flex;\n","      flex-wrap:wrap;\n","      gap: 12px;\n","    }\n","\n","    .colab-df-convert {\n","      background-color: #E8F0FE;\n","      border: none;\n","      border-radius: 50%;\n","      cursor: pointer;\n","      display: none;\n","      fill: #1967D2;\n","      height: 32px;\n","      padding: 0 0 0 0;\n","      width: 32px;\n","    }\n","\n","    .colab-df-convert:hover {\n","      background-color: #E2EBFA;\n","      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n","      fill: #174EA6;\n","    }\n","\n","    [theme=dark] .colab-df-convert {\n","      background-color: #3B4455;\n","      fill: #D2E3FC;\n","    }\n","\n","    [theme=dark] .colab-df-convert:hover {\n","      background-color: #434B5C;\n","      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n","      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n","      fill: #FFFFFF;\n","    }\n","  </style>\n","\n","      <script>\n","        const buttonEl =\n","          document.querySelector('#df-d6444b5f-72b8-4e7e-b7a2-6fc0efdc7816 button.colab-df-convert');\n","        buttonEl.style.display =\n","          google.colab.kernel.accessAllowed ? 'block' : 'none';\n","\n","        async function convertToInteractive(key) {\n","          const element = document.querySelector('#df-d6444b5f-72b8-4e7e-b7a2-6fc0efdc7816');\n","          const dataTable =\n","            await google.colab.kernel.invokeFunction('convertToInteractive',\n","                                                     [key], {});\n","          if (!dataTable) return;\n","\n","          const docLinkHtml = 'Like what you see? Visit the ' +\n","            '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n","            + ' to learn more about interactive tables.';\n","          element.innerHTML = '';\n","          dataTable['output_type'] = 'display_data';\n","          await google.colab.output.renderOutput(dataTable, element);\n","          const docLink = document.createElement('div');\n","          docLink.innerHTML = docLinkHtml;\n","          element.appendChild(docLink);\n","        }\n","      </script>\n","    </div>\n","  </div>\n","  "]},"metadata":{},"execution_count":7}]},{"cell_type":"code","metadata":{"id":"RoDW7l9mqqHZ","executionInfo":{"status":"ok","timestamp":1653200161046,"user_tz":-330,"elapsed":27,"user":{"displayName":"siddhardh selvam","userId":"13966379820454708749"}}},"source":["# separating the data and labels\n","X = diabetes_dataset.drop(columns = 'Outcome', axis=1)\n","Y = diabetes_dataset['Outcome']"],"execution_count":8,"outputs":[]},{"cell_type":"code","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"3eiRW9M9raMm","executionInfo":{"status":"ok","timestamp":1653200161046,"user_tz":-330,"elapsed":26,"user":{"displayName":"siddhardh selvam","userId":"13966379820454708749"}},"outputId":"107aefe8-a40e-4a8c-efa4-e6a4929b8343"},"source":["print(X)"],"execution_count":9,"outputs":[{"output_type":"stream","name":"stdout","text":["     Pregnancies  Glucose  BloodPressure  SkinThickness  Insulin   BMI  \\\n","0              6      148             72             35        0  33.6   \n","1              1       85             66             29        0  26.6   \n","2              8      183             64              0        0  23.3   \n","3              1       89             66             23       94  28.1   \n","4              0      137             40             35      168  43.1   \n","..           ...      ...            ...            ...      ...   ...   \n","763           10      101             76             48      180  32.9   \n","764            2      122             70             27        0  36.8   \n","765            5      121             72             23      112  26.2   \n","766            1      126             60              0        0  30.1   \n","767            1       93             70             31        0  30.4   \n","\n","     DiabetesPedigreeFunction  Age  \n","0                       0.627   50  \n","1                       0.351   31  \n","2                       0.672   32  \n","3                       0.167   21  \n","4                       2.288   33  \n","..                        ...  ...  \n","763                     0.171   63  \n","764                     0.340   27  \n","765                     0.245   30  \n","766                     0.349   47  \n","767                     0.315   23  \n","\n","[768 rows x 8 columns]\n"]}]},{"cell_type":"code","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"AoxgTJAMrcCl","executionInfo":{"status":"ok","timestamp":1653200161047,"user_tz":-330,"elapsed":25,"user":{"displayName":"siddhardh selvam","userId":"13966379820454708749"}},"outputId":"afb40f51-fd9c-43ff-c51f-7b49a7f9b152"},"source":["print(Y)"],"execution_count":10,"outputs":[{"output_type":"stream","name":"stdout","text":["0      1\n","1      0\n","2      1\n","3      0\n","4      1\n","      ..\n","763    0\n","764    0\n","765    0\n","766    1\n","767    0\n","Name: Outcome, Length: 768, dtype: int64\n"]}]},{"cell_type":"markdown","metadata":{"id":"gHciEFkxsoQP"},"source":["Train Test Split"]},{"cell_type":"code","metadata":{"id":"AEfKGj_yslvD","executionInfo":{"status":"ok","timestamp":1653200161047,"user_tz":-330,"elapsed":21,"user":{"displayName":"siddhardh selvam","userId":"13966379820454708749"}}},"source":["X_train, X_test, Y_train, Y_test = train_test_split(X,Y, test_size = 0.2, stratify=Y, random_state=2)"],"execution_count":11,"outputs":[]},{"cell_type":"code","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"DR05T-o0t3FQ","executionInfo":{"status":"ok","timestamp":1653200161048,"user_tz":-330,"elapsed":21,"user":{"displayName":"siddhardh selvam","userId":"13966379820454708749"}},"outputId":"1e35e84b-b1ac-4cf3-c2af-31eb3bf2e71c"},"source":["print(X.shape, X_train.shape, X_test.shape)"],"execution_count":12,"outputs":[{"output_type":"stream","name":"stdout","text":["(768, 8) (614, 8) (154, 8)\n"]}]},{"cell_type":"markdown","metadata":{"id":"ElJ3tkOtuC_n"},"source":["Training the Model"]},{"cell_type":"code","metadata":{"id":"5szLWHlNt9xc","executionInfo":{"status":"ok","timestamp":1653200161048,"user_tz":-330,"elapsed":19,"user":{"displayName":"siddhardh selvam","userId":"13966379820454708749"}}},"source":["classifier = svm.SVC(kernel='linear')"],"execution_count":13,"outputs":[]},{"cell_type":"code","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"ncJWY_7suPAb","executionInfo":{"status":"ok","timestamp":1653200163540,"user_tz":-330,"elapsed":2510,"user":{"displayName":"siddhardh selvam","userId":"13966379820454708749"}},"outputId":"00260e64-02fd-426f-d274-717bbf9318d6"},"source":["#training the support vector Machine Classifier\n","classifier.fit(X_train, Y_train)"],"execution_count":14,"outputs":[{"output_type":"execute_result","data":{"text/plain":["SVC(kernel='linear')"]},"metadata":{},"execution_count":14}]},{"cell_type":"markdown","metadata":{"id":"UV4-CAfquiyP"},"source":["Model Evaluation"]},{"cell_type":"markdown","metadata":{"id":"yhAjGPJWunXa"},"source":["Accuracy Score"]},{"cell_type":"code","metadata":{"id":"fJLEPQK7ueXp","executionInfo":{"status":"ok","timestamp":1653200163541,"user_tz":-330,"elapsed":27,"user":{"displayName":"siddhardh selvam","userId":"13966379820454708749"}}},"source":["# accuracy score on the training data\n","X_train_prediction = classifier.predict(X_train)\n","training_data_accuracy = accuracy_score(X_train_prediction, Y_train)"],"execution_count":15,"outputs":[]},{"cell_type":"code","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"mmJ22qhVvNwj","executionInfo":{"status":"ok","timestamp":1653200163541,"user_tz":-330,"elapsed":25,"user":{"displayName":"siddhardh selvam","userId":"13966379820454708749"}},"outputId":"ec01e94f-dbed-4286-9413-a05dab7eb7bc"},"source":["print('Accuracy score of the training data : ', training_data_accuracy)"],"execution_count":16,"outputs":[{"output_type":"stream","name":"stdout","text":["Accuracy score of the training data :  0.7833876221498371\n"]}]},{"cell_type":"code","metadata":{"id":"G2CICFMEvcCl","executionInfo":{"status":"ok","timestamp":1653200163542,"user_tz":-330,"elapsed":24,"user":{"displayName":"siddhardh selvam","userId":"13966379820454708749"}}},"source":["# accuracy score on the test data\n","X_test_prediction = classifier.predict(X_test)\n","test_data_accuracy = accuracy_score(X_test_prediction, Y_test)"],"execution_count":17,"outputs":[]},{"cell_type":"code","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"i2GcW_t_vz7C","executionInfo":{"status":"ok","timestamp":1653200163542,"user_tz":-330,"elapsed":23,"user":{"displayName":"siddhardh selvam","userId":"13966379820454708749"}},"outputId":"638e2f46-36ec-471a-b9f7-ac7e319e5fea"},"source":["print('Accuracy score of the test data : ', test_data_accuracy)"],"execution_count":18,"outputs":[{"output_type":"stream","name":"stdout","text":["Accuracy score of the test data :  0.7727272727272727\n"]}]},{"cell_type":"markdown","metadata":{"id":"gq8ZX1xpwPF5"},"source":["Making a Predictive System"]},{"cell_type":"code","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"U-ULRe4yv5tH","executionInfo":{"status":"ok","timestamp":1653200163543,"user_tz":-330,"elapsed":21,"user":{"displayName":"siddhardh selvam","userId":"13966379820454708749"}},"outputId":"6d829789-0c86-469d-ec6a-f20276f0a3ed"},"source":["input_data = (5,166,72,19,175,25.8,0.587,51)\n","\n","# changing the input_data to numpy array\n","input_data_as_numpy_array = np.asarray(input_data)\n","\n","# reshape the array as we are predicting for one instance\n","input_data_reshaped = input_data_as_numpy_array.reshape(1,-1)\n","\n","prediction = classifier.predict(input_data_reshaped)\n","print(prediction)\n","\n","if (prediction[0] == 0):\n","  print('The person is not diabetic')\n","else:\n","  print('The person is diabetic')"],"execution_count":19,"outputs":[{"output_type":"stream","name":"stdout","text":["[1]\n","The person is diabetic\n"]},{"output_type":"stream","name":"stderr","text":["/usr/local/lib/python3.7/dist-packages/sklearn/base.py:451: UserWarning: X does not have valid feature names, but SVC was fitted with feature names\n","  \"X does not have valid feature names, but\"\n"]}]},{"cell_type":"markdown","metadata":{"id":"FCHCMHpshHU4"},"source":["Saving the trained model"]},{"cell_type":"code","metadata":{"id":"cdmTOR4MhHCB","executionInfo":{"status":"ok","timestamp":1653200163543,"user_tz":-330,"elapsed":18,"user":{"displayName":"siddhardh selvam","userId":"13966379820454708749"}}},"source":["import pickle"],"execution_count":20,"outputs":[]},{"cell_type":"code","metadata":{"id":"4gN09lokhKuZ","executionInfo":{"status":"ok","timestamp":1653200163543,"user_tz":-330,"elapsed":17,"user":{"displayName":"siddhardh selvam","userId":"13966379820454708749"}}},"source":["filename = 'diabetes_model.sav'\n","pickle.dump(classifier, open(filename, 'wb'))"],"execution_count":21,"outputs":[]},{"cell_type":"code","metadata":{"id":"IKW4D5CqhP5X","executionInfo":{"status":"ok","timestamp":1653200163544,"user_tz":-330,"elapsed":18,"user":{"displayName":"siddhardh selvam","userId":"13966379820454708749"}}},"source":["# loading the saved model\n","loaded_model = pickle.load(open('diabetes_model.sav', 'rb'))"],"execution_count":22,"outputs":[]},{"cell_type":"code","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"exbg9-VWiHRx","executionInfo":{"status":"ok","timestamp":1653200163544,"user_tz":-330,"elapsed":17,"user":{"displayName":"siddhardh selvam","userId":"13966379820454708749"}},"outputId":"e9d0e88b-67b8-457a-a252-22633cdc382e"},"source":["input_data = (5,166,72,19,175,25.8,0.587,51)\n","\n","# changing the input_data to numpy array\n","input_data_as_numpy_array = np.asarray(input_data)\n","\n","# reshape the array as we are predicting for one instance\n","input_data_reshaped = input_data_as_numpy_array.reshape(1,-1)\n","\n","prediction = loaded_model.predict(input_data_reshaped)\n","print(prediction)\n","\n","if (prediction[0] == 0):\n","  print('The person is not diabetic')\n","else:\n","  print('The person is diabetic')"],"execution_count":23,"outputs":[{"output_type":"stream","name":"stdout","text":["[1]\n","The person is diabetic\n"]},{"output_type":"stream","name":"stderr","text":["/usr/local/lib/python3.7/dist-packages/sklearn/base.py:451: UserWarning: X does not have valid feature names, but SVC was fitted with feature names\n","  \"X does not have valid feature names, but\"\n"]}]},{"cell_type":"code","source":["for column in X.columns:\n","  print(column)"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"IP-TYuEFOTF4","executionInfo":{"status":"ok","timestamp":1653200163545,"user_tz":-330,"elapsed":15,"user":{"displayName":"siddhardh selvam","userId":"13966379820454708749"}},"outputId":"508fa3ac-ee67-4361-e558-d6b22b9c2c2c"},"execution_count":24,"outputs":[{"output_type":"stream","name":"stdout","text":["Pregnancies\n","Glucose\n","BloodPressure\n","SkinThickness\n","Insulin\n","BMI\n","DiabetesPedigreeFunction\n","Age\n"]}]}]}