{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "provenance": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "oKnyyIujGia-",
        "outputId": "5355ff38-d6e4-4ecc-f3ce-b6a2aef16db4"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "\n",
            "Decision Tree\n",
            "----------------------------------------\n",
            "Training Accuracy: 1.0\n",
            "Test Accuracy: 0.7467532467532467\n",
            "\n",
            "Classification Report:\n",
            "              precision    recall  f1-score   support\n",
            "\n",
            "           0       0.81      0.79      0.80        99\n",
            "           1       0.64      0.67      0.65        55\n",
            "\n",
            "    accuracy                           0.75       154\n",
            "   macro avg       0.73      0.73      0.73       154\n",
            "weighted avg       0.75      0.75      0.75       154\n",
            "\n",
            "Confusion Matrix:\n",
            "[[78 21]\n",
            " [18 37]]\n",
            "\n",
            "Random Forest\n",
            "----------------------------------------\n",
            "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",
            "Confusion Matrix:\n",
            "[[78 21]\n",
            " [17 38]]\n",
            "\n",
            "Naive Bayes\n",
            "----------------------------------------\n",
            "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",
            "Confusion Matrix:\n",
            "[[78 21]\n",
            " [16 39]]\n",
            "\n",
            "SVM (Linear)\n",
            "----------------------------------------\n",
            "Training Accuracy: 0.7736156351791531\n",
            "Test Accuracy: 0.7662337662337663\n",
            "\n",
            "Classification Report:\n",
            "              precision    recall  f1-score   support\n",
            "\n",
            "           0       0.82      0.82      0.82        99\n",
            "           1       0.67      0.67      0.67        55\n",
            "\n",
            "    accuracy                           0.77       154\n",
            "   macro avg       0.75      0.75      0.75       154\n",
            "weighted avg       0.77      0.77      0.77       154\n",
            "\n",
            "Confusion Matrix:\n",
            "[[81 18]\n",
            " [18 37]]\n",
            "\n",
            "SVM (RBF)\n",
            "----------------------------------------\n",
            "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",
            "Confusion Matrix:\n",
            "[[91  8]\n",
            " [31 24]]\n"
          ]
        }
      ],
      "source": [
        "\n",
        "import pandas as pd\n",
        "import numpy as np\n",
        "\n",
        "from sklearn.model_selection import train_test_split\n",
        "from sklearn.metrics import accuracy_score, classification_report, confusion_matrix\n",
        "\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\n",
        "\n",
        "\n",
        "df = pd.read_csv(\"/content/diabetes.csv\")\n",
        "\n",
        "\n",
        "X = df.drop(\"Outcome\", axis=1)\n",
        "y = df[\"Outcome\"]\n",
        "\n",
        "\n",
        "X_train, X_test, y_train, y_test = train_test_split(\n",
        "    X, y, test_size=0.2, random_state=42\n",
        ")\n",
        "\n",
        "def evaluate_model(model, model_name):\n",
        "    model.fit(X_train, y_train)\n",
        "\n",
        "    y_train_pred = model.predict(X_train)\n",
        "    y_test_pred = model.predict(X_test)\n",
        "\n",
        "    print(f\"\\n{model_name}\")\n",
        "    print(\"-\" * 40)\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(\"Confusion Matrix:\")\n",
        "    print(confusion_matrix(y_test, y_test_pred))\n",
        "\n",
        "\n",
        "# Decision Tree\n",
        "dt = DecisionTreeClassifier(random_state=42)\n",
        "evaluate_model(dt, \"Decision Tree\")\n",
        "\n",
        "# Random Forest\n",
        "rf = RandomForestClassifier(n_estimators=100, random_state=42)\n",
        "evaluate_model(rf, \"Random Forest\")\n",
        "\n",
        "# Naive Bayes\n",
        "nb = GaussianNB()\n",
        "evaluate_model(nb, \"Naive Bayes\")\n",
        "\n",
        "# SVM (Linear)\n",
        "svm_linear = SVC(kernel='linear')\n",
        "evaluate_model(svm_linear, \"SVM (Linear)\")\n",
        "\n",
        "# SVM (RBF)\n",
        "svm_rbf = SVC(kernel='rbf')\n",
        "evaluate_model(svm_rbf, \"SVM (RBF)\")\n"
      ]
    }
  ]
}