{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "af8f6ab9-9164-4e15-9335-be58cc5764b7",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "from sklearn.model_selection import train_test_split\n",
    "from sklearn.metrics import ( \n",
    "    accuracy_score,\n",
    "    classification_report,\n",
    "    confusion_matrix,\n",
    "    precision_score,\n",
    "    recall_score,f1_score )\n",
    "from sklearn.tree import DecisionTreeClassifier\n",
    "from sklearn.ensemble import RandomForestClassifier\n",
    "from sklearn.naive_bayes import GaussianNB\n",
    "from sklearn.svm import SVC"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "649016af-e94c-4317-8ef0-a8fa3e335c21",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<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>PatientId</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>1</td>\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>2</td>\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>3</td>\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>4</td>\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>5</td>\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>"
      ],
      "text/plain": [
       "   PatientId  Pregnancies  Glucose  BloodPressure  SkinThickness  Insulin  \\\n",
       "0          1            6      148             72             35        0   \n",
       "1          2            1       85             66             29        0   \n",
       "2          3            8      183             64              0        0   \n",
       "3          4            1       89             66             23       94   \n",
       "4          5            0      137             40             35      168   \n",
       "\n",
       "    BMI  DiabetesPedigreeFunction  Age  Outcome  \n",
       "0  33.6                     0.627   50        1  \n",
       "1  26.6                     0.351   31        0  \n",
       "2  23.3                     0.672   32        1  \n",
       "3  28.1                     0.167   21        0  \n",
       "4  43.1                     2.288   33        1  "
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.read_csv(\"diabetes.csv\")\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "700c3ec4-bbb9-422d-9d3b-7e9c83a0be6f",
   "metadata": {},
   "outputs": [],
   "source": [
    "x = df.drop('Outcome', axis = 1)\n",
    "y = df['Outcome']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "267f1ab0-3cd7-4810-9cbf-1d911cc42411",
   "metadata": {},
   "outputs": [],
   "source": [
    "x_train, x_test , y_train, y_test = train_test_split (\n",
    "    x,y, test_size = 0.2, random_state = 42 \n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "b111ed3f-e558-438a-bca4-6ce4d5df3db9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Training Accuracy: 1.0\n",
      "Test Accuracy: 0.7402597402597403\n",
      "\n",
      "Classification Report:\n",
      "              precision    recall  f1-score   support\n",
      "\n",
      "           0       0.80      0.79      0.80        99\n",
      "           1       0.63      0.65      0.64        55\n",
      "\n",
      "    accuracy                           0.74       154\n",
      "   macro avg       0.72      0.72      0.72       154\n",
      "weighted avg       0.74      0.74      0.74       154\n",
      "\n",
      "\n",
      "Confusion Matrix:\n",
      "[[78 21]\n",
      " [19 36]]\n"
     ]
    }
   ],
   "source": [
    "# function to Decision Tree\n",
    "dt = DecisionTreeClassifier()\n",
    "dt.fit(x_train, y_train)\n",
    "\n",
    "y_train_pred = dt.predict(x_train)/\n",
    "y_test_pred = dt.predict(x_test)\n",
    "\n",
    "print(\"Training Accuracy:\", accuracy_score(y_train, y_train_pred))\n",
    "print(\"Test Accuracy:\", accuracy_score(y_test, y_test_pred))\n",
    "\n",
    "print(\"\\nClassification Report:\")\n",
    "print(classification_report(y_test, y_test_pred))\n",
    "\n",
    "print(\"\\nConfusion Matrix:\")\n",
    "print(confusion_matrix(y_test, y_test_pred))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "4047de72-8459-45bf-a015-64295abbf42a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Training Accuracy: 1.0\n",
      "Test Accuracy: 0.7532467532467533\n",
      "\n",
      "Classification Report:\n",
      "              precision    recall  f1-score   support\n",
      "\n",
      "           0       0.82      0.79      0.80        99\n",
      "           1       0.64      0.69      0.67        55\n",
      "\n",
      "    accuracy                           0.75       154\n",
      "   macro avg       0.73      0.74      0.74       154\n",
      "weighted avg       0.76      0.75      0.76       154\n",
      "\n",
      "\n",
      "Confusion Matrix:\n",
      "[[78 21]\n",
      " [17 38]]\n"
     ]
    }
   ],
   "source": [
    "# function to Random forest\n",
    "dt = RandomForestClassifier(n_estimators=100,\n",
    "                            random_state=42)\n",
    "dt.fit(x_train, y_train)\n",
    "\n",
    "y_train_pred = dt.predict(x_train)\n",
    "y_test_pred = dt.predict(x_test)\n",
    "\n",
    "print(\"Training Accuracy:\", accuracy_score(y_train, y_train_pred))\n",
    "print(\"Test Accuracy:\", accuracy_score(y_test, y_test_pred))\n",
    "\n",
    "print(\"\\nClassification Report:\")\n",
    "print(classification_report(y_test, y_test_pred))\n",
    "\n",
    "print(\"\\nConfusion Matrix:\")\n",
    "print(confusion_matrix(y_test, y_test_pred))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "20cc8194-aad7-4f07-8213-98ad39ce607e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Training Accuracy: 0.752442996742671\n",
      "Test Accuracy: 0.7597402597402597\n",
      "\n",
      "Classification Report:\n",
      "              precision    recall  f1-score   support\n",
      "\n",
      "           0       0.83      0.79      0.81        99\n",
      "           1       0.65      0.71      0.68        55\n",
      "\n",
      "    accuracy                           0.76       154\n",
      "   macro avg       0.74      0.75      0.74       154\n",
      "weighted avg       0.77      0.76      0.76       154\n",
      "\n",
      "\n",
      "Confusion Matrix:\n",
      "[[78 21]\n",
      " [16 39]]\n"
     ]
    }
   ],
   "source": [
    "# function to Gaussian \n",
    "dt = GaussianNB()\n",
    "dt.fit(x_train, y_train)\n",
    "\n",
    "y_train_pred = dt.predict(x_train)\n",
    "y_test_pred = dt.predict(x_test)\n",
    "\n",
    "print(\"Training Accuracy:\", accuracy_score(y_train, y_train_pred))\n",
    "print(\"Test Accuracy:\", accuracy_score(y_test, y_test_pred))\n",
    "\n",
    "print(\"\\nClassification Report:\")\n",
    "print(classification_report(y_test, y_test_pred))\n",
    "\n",
    "print(\"\\nConfusion Matrix:\")\n",
    "print(confusion_matrix(y_test, y_test_pred))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "fcfba2af-a550-4b35-936b-5c0dbf48a27a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Training Accuracy: 0.7736156351791531\n",
      "Test Accuracy: 0.7597402597402597\n",
      "\n",
      "Classification Report:\n",
      "              precision    recall  f1-score   support\n",
      "\n",
      "           0       0.81      0.82      0.81        99\n",
      "           1       0.67      0.65      0.66        55\n",
      "\n",
      "    accuracy                           0.76       154\n",
      "   macro avg       0.74      0.74      0.74       154\n",
      "weighted avg       0.76      0.76      0.76       154\n",
      "\n",
      "\n",
      "Confusion Matrix:\n",
      "[[81 18]\n",
      " [19 36]]\n"
     ]
    }
   ],
   "source": [
    "# function to SVC Linear\n",
    "dt = SVC(kernel='linear')\n",
    "dt.fit(x_train, y_train)\n",
    "\n",
    "y_train_pred = dt.predict(x_train)\n",
    "y_test_pred = dt.predict(x_test)\n",
    "\n",
    "print(\"Training Accuracy:\", accuracy_score(y_train, y_train_pred))\n",
    "print(\"Test Accuracy:\", accuracy_score(y_test, y_test_pred))\n",
    "\n",
    "print(\"\\nClassification Report:\")\n",
    "print(classification_report(y_test, y_test_pred))\n",
    "\n",
    "print(\"\\nConfusion Matrix:\")\n",
    "print(confusion_matrix(y_test, y_test_pred))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "42b70672-f4d9-4fde-b16b-1476446f4890",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Training Accuracy: 0.744299674267101\n",
      "Test Accuracy: 0.7467532467532467\n",
      "\n",
      "Classification Report:\n",
      "              precision    recall  f1-score   support\n",
      "\n",
      "           0       0.75      0.92      0.82        99\n",
      "           1       0.75      0.44      0.55        55\n",
      "\n",
      "    accuracy                           0.75       154\n",
      "   macro avg       0.75      0.68      0.69       154\n",
      "weighted avg       0.75      0.75      0.73       154\n",
      "\n",
      "\n",
      "Confusion Matrix:\n",
      "[[91  8]\n",
      " [31 24]]\n"
     ]
    }
   ],
   "source": [
    "# function to SVC Rbf\n",
    "dt = SVC(kernel='rbf')\n",
    "dt.fit(x_train, y_train)\n",
    "\n",
    "y_train_pred = dt.predict(x_train)\n",
    "y_test_pred = dt.predict(x_test)\n",
    "\n",
    "print(\"Training Accuracy:\", accuracy_score(y_train, y_train_pred))\n",
    "print(\"Test Accuracy:\", accuracy_score(y_test, y_test_pred))\n",
    "\n",
    "print(\"\\nClassification Report:\")\n",
    "print(classification_report(y_test, y_test_pred))\n",
    "\n",
    "print(\"\\nConfusion Matrix:\")\n",
    "print(confusion_matrix(y_test, y_test_pred))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "73a171e0-fbc3-4951-8d65-58fa67b2220f",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8d49d827-83e6-4df2-97d5-6d562b6b3556",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "anaconda-2025.12-py312",
   "language": "python",
   "name": "conda-env-anaconda-2025.12-py312-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
