{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "a10cd722",
   "metadata": {},
   "source": [
    "# Preprocessing"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "59819858",
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib\n",
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "import seaborn as sns\n",
    "import sklearn\n",
    "import time\n",
    "import openpyxl as xls\n",
    "\n",
    "from sklearn.preprocessing import MinMaxScaler\n",
    "from sklearn.preprocessing import label_binarize\n",
    "from sklearn.model_selection import train_test_split\n",
    "from sklearn.naive_bayes import GaussianNB\n",
    "from sklearn.neighbors import KNeighborsClassifier\n",
    "from sklearn.metrics import classification_report\n",
    "from sklearn.metrics import confusion_matrix\n",
    "from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score\n",
    "from sklearn.metrics import roc_curve,auc\n",
    "from sklearn.metrics import roc_auc_score"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "bb54cf3f",
   "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>jenis_kelamin</th>\n",
       "      <th>umur</th>\n",
       "      <th>tinggi_badan_meter</th>\n",
       "      <th>berat_badan_kilogram</th>\n",
       "      <th>histori_keluarga_kelebihan_BB</th>\n",
       "      <th>konsumsi_tinggi_kalori</th>\n",
       "      <th>konsumsi_sayuran</th>\n",
       "      <th>makan_berat</th>\n",
       "      <th>ngemil</th>\n",
       "      <th>merokok</th>\n",
       "      <th>konsumsi_air_liter</th>\n",
       "      <th>pemantauan_kalori</th>\n",
       "      <th>aktifitas_fisik</th>\n",
       "      <th>penggunaan_perangkat_teknologi</th>\n",
       "      <th>konsumsi_alkohol</th>\n",
       "      <th>transporasi_biasa_digunakan</th>\n",
       "      <th>kelas_obesitas</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>21</td>\n",
       "      <td>1.62</td>\n",
       "      <td>64</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>3x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>Sepeda motor</td>\n",
       "      <td>kelebihan_berat_badan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>21</td>\n",
       "      <td>1.52</td>\n",
       "      <td>56</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Selalu</td>\n",
       "      <td>3x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Lebih 2 liter</td>\n",
       "      <td>Ya</td>\n",
       "      <td>4-5 hari</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Sepeda motor</td>\n",
       "      <td>kelebihan_berat_badan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Laki-laki</td>\n",
       "      <td>29</td>\n",
       "      <td>1.62</td>\n",
       "      <td>53</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>3x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Jalan kaki</td>\n",
       "      <td>normal</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>23</td>\n",
       "      <td>1.50</td>\n",
       "      <td>55</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Selalu</td>\n",
       "      <td>3x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 hari</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Transportasi umum</td>\n",
       "      <td>kelebihan_berat_badan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Laki-laki</td>\n",
       "      <td>22</td>\n",
       "      <td>1.64</td>\n",
       "      <td>53</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>3x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>4-5 hari</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Sepeda motor</td>\n",
       "      <td>normal</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>443</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>37</td>\n",
       "      <td>1.55</td>\n",
       "      <td>76</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>3x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 hari</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Jalan kaki</td>\n",
       "      <td>obesitas_II</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>444</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>39</td>\n",
       "      <td>1.56</td>\n",
       "      <td>76</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>3x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Jalan kaki</td>\n",
       "      <td>obesitas_II</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>445</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>37</td>\n",
       "      <td>1.50</td>\n",
       "      <td>75</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>3x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Jalan kaki</td>\n",
       "      <td>obesitas_II</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>446</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>41</td>\n",
       "      <td>1.54</td>\n",
       "      <td>77</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>3x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Lebih 2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Jalan kaki</td>\n",
       "      <td>obesitas_II</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>447</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>43</td>\n",
       "      <td>1.59</td>\n",
       "      <td>77</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>3x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Lebih 2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Jalan kaki</td>\n",
       "      <td>obesitas_II</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>448 rows × 17 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    jenis_kelamin  umur  tinggi_badan_meter  berat_badan_kilogram  \\\n",
       "0       Perempuan    21                1.62                    64   \n",
       "1       Perempuan    21                1.52                    56   \n",
       "2       Laki-laki    29                1.62                    53   \n",
       "3       Perempuan    23                1.50                    55   \n",
       "4       Laki-laki    22                1.64                    53   \n",
       "..            ...   ...                 ...                   ...   \n",
       "443     Perempuan    37                1.55                    76   \n",
       "444     Perempuan    39                1.56                    76   \n",
       "445     Perempuan    37                1.50                    75   \n",
       "446     Perempuan    41                1.54                    77   \n",
       "447     Perempuan    43                1.59                    77   \n",
       "\n",
       "    histori_keluarga_kelebihan_BB konsumsi_tinggi_kalori konsumsi_sayuran  \\\n",
       "0                              Ya                  Tidak    Kadang-kadang   \n",
       "1                              Ya                  Tidak           Selalu   \n",
       "2                           Tidak                     Ya    Kadang-kadang   \n",
       "3                              Ya                     Ya           Selalu   \n",
       "4                           Tidak                  Tidak    Kadang-kadang   \n",
       "..                            ...                    ...              ...   \n",
       "443                            Ya                     Ya    Kadang-kadang   \n",
       "444                            Ya                     Ya    Kadang-kadang   \n",
       "445                            Ya                     Ya    Kadang-kadang   \n",
       "446                            Ya                     Ya    Kadang-kadang   \n",
       "447                            Ya                     Ya    Kadang-kadang   \n",
       "\n",
       "    makan_berat         ngemil merokok konsumsi_air_liter pemantauan_kalori  \\\n",
       "0            3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "1            3x  Kadang-kadang      Ya      Lebih 2 liter                Ya   \n",
       "2            3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "3            3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "4            3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "..          ...            ...     ...                ...               ...   \n",
       "443          3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "444          3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "445          3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "446          3x  Kadang-kadang   Tidak      Lebih 2 liter             Tidak   \n",
       "447          3x  Kadang-kadang   Tidak      Lebih 2 liter             Tidak   \n",
       "\n",
       "    aktifitas_fisik penggunaan_perangkat_teknologi konsumsi_alkohol  \\\n",
       "0      Tidak pernah                        0-2 jam     Tidak pernah   \n",
       "1          4-5 hari                        0-2 jam    Kadang-kadang   \n",
       "2      Tidak pernah                        0-2 jam    Kadang-kadang   \n",
       "3          1-2 hari                        0-2 jam    Kadang-kadang   \n",
       "4          4-5 hari                        0-2 jam    Kadang-kadang   \n",
       "..              ...                            ...              ...   \n",
       "443        1-2 hari                        0-2 jam    Kadang-kadang   \n",
       "444    Tidak pernah                        0-2 jam    Kadang-kadang   \n",
       "445    Tidak pernah                        0-2 jam    Kadang-kadang   \n",
       "446    Tidak pernah                        0-2 jam    Kadang-kadang   \n",
       "447    Tidak pernah                        0-2 jam    Kadang-kadang   \n",
       "\n",
       "    transporasi_biasa_digunakan         kelas_obesitas  \n",
       "0                  Sepeda motor  kelebihan_berat_badan  \n",
       "1                  Sepeda motor  kelebihan_berat_badan  \n",
       "2                    Jalan kaki                 normal  \n",
       "3             Transportasi umum  kelebihan_berat_badan  \n",
       "4                  Sepeda motor                 normal  \n",
       "..                          ...                    ...  \n",
       "443                  Jalan kaki            obesitas_II  \n",
       "444                  Jalan kaki            obesitas_II  \n",
       "445                  Jalan kaki            obesitas_II  \n",
       "446                  Jalan kaki            obesitas_II  \n",
       "447                  Jalan kaki            obesitas_II  \n",
       "\n",
       "[448 rows x 17 columns]"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = pd.read_csv('dataset/data_obesitas.csv')\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "42396def",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 448 entries, 0 to 447\n",
      "Data columns (total 17 columns):\n",
      " #   Column                          Non-Null Count  Dtype  \n",
      "---  ------                          --------------  -----  \n",
      " 0   jenis_kelamin                   448 non-null    object \n",
      " 1   umur                            448 non-null    int64  \n",
      " 2   tinggi_badan_meter              448 non-null    float64\n",
      " 3   berat_badan_kilogram            448 non-null    int64  \n",
      " 4   histori_keluarga_kelebihan_BB   448 non-null    object \n",
      " 5   konsumsi_tinggi_kalori          448 non-null    object \n",
      " 6   konsumsi_sayuran                448 non-null    object \n",
      " 7   makan_berat                     448 non-null    object \n",
      " 8   ngemil                          448 non-null    object \n",
      " 9   merokok                         448 non-null    object \n",
      " 10  konsumsi_air_liter              448 non-null    object \n",
      " 11  pemantauan_kalori               448 non-null    object \n",
      " 12  aktifitas_fisik                 448 non-null    object \n",
      " 13  penggunaan_perangkat_teknologi  448 non-null    object \n",
      " 14  konsumsi_alkohol                448 non-null    object \n",
      " 15  transporasi_biasa_digunakan     448 non-null    object \n",
      " 16  kelas_obesitas                  448 non-null    object \n",
      "dtypes: float64(1), int64(2), object(14)\n",
      "memory usage: 59.6+ KB\n"
     ]
    }
   ],
   "source": [
    "data.info()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f8d9da3c",
   "metadata": {},
   "source": [
    "### distribusi kelas "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "c90d7b2b",
   "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>kelas_obesitas</th>\n",
       "      <th>jumlah</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>berat_badan_kurang</td>\n",
       "      <td>85</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>normal</td>\n",
       "      <td>141</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>kelebihan_berat_badan</td>\n",
       "      <td>71</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>obesitas_I</td>\n",
       "      <td>85</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>obesitas_II</td>\n",
       "      <td>66</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          kelas_obesitas  jumlah\n",
       "2     berat_badan_kurang      85\n",
       "0                 normal     141\n",
       "3  kelebihan_berat_badan      71\n",
       "1             obesitas_I      85\n",
       "4            obesitas_II      66"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "kelas_obesitas = data['kelas_obesitas'].value_counts().rename_axis('kelas_obesitas').reset_index(name='jumlah')\n",
    "urutan_obesitas = ['berat_badan_kurang',\n",
    "                'normal',\n",
    "                'kelebihan_berat_badan',\n",
    "                'obesitas_I',\n",
    "                'obesitas_II']\n",
    "kelas_obesitas['kelas_obesitas'] = pd.Categorical(kelas_obesitas['kelas_obesitas'], categories=urutan_obesitas, ordered=True)\n",
    "kelas_obesitas = kelas_obesitas.sort_values(by='kelas_obesitas')\n",
    "kelas_obesitas"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "626df08e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 41016 characters]",
      "text/plain": [
       "<Figure size 500x500 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.figure(figsize=(5, 5))\n",
    "colors = sns.color_palette('pastel')\n",
    "\n",
    "plt.pie(kelas_obesitas['jumlah'], labels=kelas_obesitas['kelas_obesitas'], autopct='%1.1f%%', colors=colors)\n",
    "\n",
    "plt.title('Perbandingan Persentase Kelas Obesitas')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "aa77f287",
   "metadata": {},
   "source": [
    "### cek outlier"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "a6bde44e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 20924 characters]",
      "text/plain": [
       "<Figure size 1500x1000 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.figure(figsize = (15,10))\n",
    "sns.boxplot(data = data, orient='h')\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "1e29416d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 448 entries, 0 to 447\n",
      "Data columns (total 17 columns):\n",
      " #   Column                          Non-Null Count  Dtype  \n",
      "---  ------                          --------------  -----  \n",
      " 0   jenis_kelamin                   448 non-null    object \n",
      " 1   umur                            448 non-null    int64  \n",
      " 2   tinggi_badan_meter              448 non-null    float64\n",
      " 3   berat_badan_kilogram            448 non-null    int64  \n",
      " 4   histori_keluarga_kelebihan_BB   448 non-null    object \n",
      " 5   konsumsi_tinggi_kalori          448 non-null    object \n",
      " 6   konsumsi_sayuran                448 non-null    object \n",
      " 7   makan_berat                     448 non-null    object \n",
      " 8   ngemil                          448 non-null    object \n",
      " 9   merokok                         448 non-null    object \n",
      " 10  konsumsi_air_liter              448 non-null    object \n",
      " 11  pemantauan_kalori               448 non-null    object \n",
      " 12  aktifitas_fisik                 448 non-null    object \n",
      " 13  penggunaan_perangkat_teknologi  448 non-null    object \n",
      " 14  konsumsi_alkohol                448 non-null    object \n",
      " 15  transporasi_biasa_digunakan     448 non-null    object \n",
      " 16  kelas_obesitas                  448 non-null    object \n",
      "dtypes: float64(1), int64(2), object(14)\n",
      "memory usage: 59.6+ KB\n"
     ]
    }
   ],
   "source": [
    "data.info()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "20c810b7",
   "metadata": {},
   "source": [
    "### transformasi"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "d412e9f6",
   "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>jenis_kelamin</th>\n",
       "      <th>umur</th>\n",
       "      <th>tinggi_badan_meter</th>\n",
       "      <th>berat_badan_kilogram</th>\n",
       "      <th>histori_keluarga_kelebihan_BB</th>\n",
       "      <th>konsumsi_tinggi_kalori</th>\n",
       "      <th>konsumsi_sayuran</th>\n",
       "      <th>makan_berat</th>\n",
       "      <th>ngemil</th>\n",
       "      <th>merokok</th>\n",
       "      <th>konsumsi_air_liter</th>\n",
       "      <th>pemantauan_kalori</th>\n",
       "      <th>aktifitas_fisik</th>\n",
       "      <th>penggunaan_perangkat_teknologi</th>\n",
       "      <th>konsumsi_alkohol</th>\n",
       "      <th>transporasi_biasa_digunakan</th>\n",
       "      <th>kelas_obesitas</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>21</td>\n",
       "      <td>1.62</td>\n",
       "      <td>64</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>kelebihan_berat_badan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0</td>\n",
       "      <td>21</td>\n",
       "      <td>1.52</td>\n",
       "      <td>56</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>kelebihan_berat_badan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>29</td>\n",
       "      <td>1.62</td>\n",
       "      <td>53</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>normal</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0</td>\n",
       "      <td>23</td>\n",
       "      <td>1.50</td>\n",
       "      <td>55</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>kelebihan_berat_badan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1</td>\n",
       "      <td>22</td>\n",
       "      <td>1.64</td>\n",
       "      <td>53</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>normal</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>443</th>\n",
       "      <td>0</td>\n",
       "      <td>37</td>\n",
       "      <td>1.55</td>\n",
       "      <td>76</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>obesitas_II</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>444</th>\n",
       "      <td>0</td>\n",
       "      <td>39</td>\n",
       "      <td>1.56</td>\n",
       "      <td>76</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>obesitas_II</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>445</th>\n",
       "      <td>0</td>\n",
       "      <td>37</td>\n",
       "      <td>1.50</td>\n",
       "      <td>75</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>obesitas_II</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>446</th>\n",
       "      <td>0</td>\n",
       "      <td>41</td>\n",
       "      <td>1.54</td>\n",
       "      <td>77</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>obesitas_II</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>447</th>\n",
       "      <td>0</td>\n",
       "      <td>43</td>\n",
       "      <td>1.59</td>\n",
       "      <td>77</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>obesitas_II</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>448 rows × 17 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     jenis_kelamin  umur  tinggi_badan_meter  berat_badan_kilogram  \\\n",
       "0                0    21                1.62                    64   \n",
       "1                0    21                1.52                    56   \n",
       "2                1    29                1.62                    53   \n",
       "3                0    23                1.50                    55   \n",
       "4                1    22                1.64                    53   \n",
       "..             ...   ...                 ...                   ...   \n",
       "443              0    37                1.55                    76   \n",
       "444              0    39                1.56                    76   \n",
       "445              0    37                1.50                    75   \n",
       "446              0    41                1.54                    77   \n",
       "447              0    43                1.59                    77   \n",
       "\n",
       "     histori_keluarga_kelebihan_BB  konsumsi_tinggi_kalori  konsumsi_sayuran  \\\n",
       "0                                1                       0                 1   \n",
       "1                                1                       0                 2   \n",
       "2                                0                       1                 1   \n",
       "3                                1                       1                 2   \n",
       "4                                0                       0                 1   \n",
       "..                             ...                     ...               ...   \n",
       "443                              1                       1                 1   \n",
       "444                              1                       1                 1   \n",
       "445                              1                       1                 1   \n",
       "446                              1                       1                 1   \n",
       "447                              1                       1                 1   \n",
       "\n",
       "     makan_berat  ngemil  merokok  konsumsi_air_liter  pemantauan_kalori  \\\n",
       "0              2       1        0                   2                  0   \n",
       "1              2       1        1                   3                  1   \n",
       "2              2       1        0                   2                  0   \n",
       "3              2       1        0                   2                  0   \n",
       "4              2       1        0                   2                  0   \n",
       "..           ...     ...      ...                 ...                ...   \n",
       "443            2       1        0                   2                  0   \n",
       "444            2       1        0                   2                  0   \n",
       "445            2       1        0                   2                  0   \n",
       "446            2       1        0                   3                  0   \n",
       "447            2       1        0                   3                  0   \n",
       "\n",
       "     aktifitas_fisik  penggunaan_perangkat_teknologi  konsumsi_alkohol  \\\n",
       "0                  0                               1                 0   \n",
       "1                  3                               1                 1   \n",
       "2                  0                               1                 1   \n",
       "3                  1                               1                 1   \n",
       "4                  3                               1                 1   \n",
       "..               ...                             ...               ...   \n",
       "443                1                               1                 1   \n",
       "444                0                               1                 1   \n",
       "445                0                               1                 1   \n",
       "446                0                               1                 1   \n",
       "447                0                               1                 1   \n",
       "\n",
       "     transporasi_biasa_digunakan         kelas_obesitas  \n",
       "0                              1  kelebihan_berat_badan  \n",
       "1                              1  kelebihan_berat_badan  \n",
       "2                              4                 normal  \n",
       "3                              3  kelebihan_berat_badan  \n",
       "4                              1                 normal  \n",
       "..                           ...                    ...  \n",
       "443                            4            obesitas_II  \n",
       "444                            4            obesitas_II  \n",
       "445                            4            obesitas_II  \n",
       "446                            4            obesitas_II  \n",
       "447                            4            obesitas_II  \n",
       "\n",
       "[448 rows x 17 columns]"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data['jenis_kelamin'] = data['jenis_kelamin'].replace('Laki-laki', 1)\n",
    "data['jenis_kelamin'] = data['jenis_kelamin'].replace('Perempuan', 0)\n",
    "\n",
    "data['histori_keluarga_kelebihan_BB'] = data['histori_keluarga_kelebihan_BB'].replace('Ya', 1)\n",
    "data['histori_keluarga_kelebihan_BB'] = data['histori_keluarga_kelebihan_BB'].replace('Tidak', 0)\n",
    "\n",
    "data['konsumsi_tinggi_kalori'] = data['konsumsi_tinggi_kalori'].replace('Ya', 1)\n",
    "data['konsumsi_tinggi_kalori'] = data['konsumsi_tinggi_kalori'].replace('Tidak', 0)\n",
    "\n",
    "data['konsumsi_sayuran'] = data['konsumsi_sayuran'].replace('Selalu', 2)\n",
    "data['konsumsi_sayuran'] = data['konsumsi_sayuran'].replace('Kadang-kadang', 1)\n",
    "data['konsumsi_sayuran'] = data['konsumsi_sayuran'].replace('Tidak pernah', 0)\n",
    "\n",
    "data['makan_berat'] = data['makan_berat'].replace('Lebih 3x', 3)\n",
    "data['makan_berat'] = data['makan_berat'].replace('3x', 2)\n",
    "data['makan_berat'] = data['makan_berat'].replace('1-2x', 1)\n",
    "\n",
    "data['ngemil'] = data['ngemil'].replace('Selalu', 3)\n",
    "data['ngemil'] = data['ngemil'].replace('Sering', 2)\n",
    "data['ngemil'] = data['ngemil'].replace('Kadang-kadang', 1)\n",
    "data['ngemil'] = data['ngemil'].replace('Tidak pernah', 0)\n",
    "\n",
    "data['merokok'] = data['merokok'].replace('Ya', 1)\n",
    "data['merokok'] = data['merokok'].replace('Tidak', 0)\n",
    "\n",
    "data['konsumsi_air_liter'] = data['konsumsi_air_liter'].replace('Lebih 2 liter', 3)\n",
    "data['konsumsi_air_liter'] = data['konsumsi_air_liter'].replace('1-2 liter', 2)\n",
    "data['konsumsi_air_liter'] = data['konsumsi_air_liter'].replace('Kurang 1 liter', 1)\n",
    "\n",
    "data['pemantauan_kalori'] = data['pemantauan_kalori'].replace('Ya', 1)\n",
    "data['pemantauan_kalori'] = data['pemantauan_kalori'].replace('Tidak', 0)\n",
    "\n",
    "data['aktifitas_fisik'] = data['aktifitas_fisik'].replace('4-5 hari', 3)\n",
    "data['aktifitas_fisik'] = data['aktifitas_fisik'].replace('2-4 hari', 2)\n",
    "data['aktifitas_fisik'] = data['aktifitas_fisik'].replace('1-2 hari', 1)\n",
    "data['aktifitas_fisik'] = data['aktifitas_fisik'].replace('Tidak pernah', 0)\n",
    "\n",
    "data['penggunaan_perangkat_teknologi'] = data['penggunaan_perangkat_teknologi'].replace('Lebih 5 jam', 3)\n",
    "data['penggunaan_perangkat_teknologi'] = data['penggunaan_perangkat_teknologi'].replace('3-5 jam', 2)\n",
    "data['penggunaan_perangkat_teknologi'] = data['penggunaan_perangkat_teknologi'].replace('0-2 jam', 1)\n",
    "\n",
    "data['konsumsi_alkohol'] = data['konsumsi_alkohol'].replace('Selalu', 3)\n",
    "data['konsumsi_alkohol'] = data['konsumsi_alkohol'].replace('Sering', 2)\n",
    "data['konsumsi_alkohol'] = data['konsumsi_alkohol'].replace('Kadang-kadang', 1)\n",
    "data['konsumsi_alkohol'] = data['konsumsi_alkohol'].replace('Tidak pernah', 0)\n",
    "\n",
    "data['transporasi_biasa_digunakan'] = data['transporasi_biasa_digunakan'].replace('Mobil', 0)\n",
    "data['transporasi_biasa_digunakan'] = data['transporasi_biasa_digunakan'].replace('Sepeda motor', 1)\n",
    "data['transporasi_biasa_digunakan'] = data['transporasi_biasa_digunakan'].replace('Sepeda', 2)\n",
    "data['transporasi_biasa_digunakan'] = data['transporasi_biasa_digunakan'].replace('Transportasi umum', 3)\n",
    "data['transporasi_biasa_digunakan'] = data['transporasi_biasa_digunakan'].replace('Jalan kaki', 4)\n",
    "\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "1175a8b6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 448 entries, 0 to 447\n",
      "Data columns (total 17 columns):\n",
      " #   Column                          Non-Null Count  Dtype  \n",
      "---  ------                          --------------  -----  \n",
      " 0   jenis_kelamin                   448 non-null    int64  \n",
      " 1   umur                            448 non-null    int64  \n",
      " 2   tinggi_badan_meter              448 non-null    float64\n",
      " 3   berat_badan_kilogram            448 non-null    int64  \n",
      " 4   histori_keluarga_kelebihan_BB   448 non-null    int64  \n",
      " 5   konsumsi_tinggi_kalori          448 non-null    int64  \n",
      " 6   konsumsi_sayuran                448 non-null    int64  \n",
      " 7   makan_berat                     448 non-null    int64  \n",
      " 8   ngemil                          448 non-null    int64  \n",
      " 9   merokok                         448 non-null    int64  \n",
      " 10  konsumsi_air_liter              448 non-null    int64  \n",
      " 11  pemantauan_kalori               448 non-null    int64  \n",
      " 12  aktifitas_fisik                 448 non-null    int64  \n",
      " 13  penggunaan_perangkat_teknologi  448 non-null    int64  \n",
      " 14  konsumsi_alkohol                448 non-null    int64  \n",
      " 15  transporasi_biasa_digunakan     448 non-null    int64  \n",
      " 16  kelas_obesitas                  448 non-null    object \n",
      "dtypes: float64(1), int64(15), object(1)\n",
      "memory usage: 59.6+ KB\n"
     ]
    }
   ],
   "source": [
    "data.info()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "61a35a3b",
   "metadata": {},
   "source": [
    "## Menyeimbangkan kelas"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "6029b2b1",
   "metadata": {},
   "outputs": [],
   "source": [
    "X = data.drop(columns='kelas_obesitas', axis = 1)\n",
    "Y = data['kelas_obesitas']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "560df6fa",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "kelebihan_berat_badan    141\n",
      "normal                   141\n",
      "obesitas_I               141\n",
      "obesitas_II              141\n",
      "berat_badan_kurang       141\n",
      "Name: kelas_obesitas, dtype: int64\n"
     ]
    },
    {
     "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>jenis_kelamin</th>\n",
       "      <th>umur</th>\n",
       "      <th>tinggi_badan_meter</th>\n",
       "      <th>berat_badan_kilogram</th>\n",
       "      <th>histori_keluarga_kelebihan_BB</th>\n",
       "      <th>konsumsi_tinggi_kalori</th>\n",
       "      <th>konsumsi_sayuran</th>\n",
       "      <th>makan_berat</th>\n",
       "      <th>ngemil</th>\n",
       "      <th>merokok</th>\n",
       "      <th>konsumsi_air_liter</th>\n",
       "      <th>pemantauan_kalori</th>\n",
       "      <th>aktifitas_fisik</th>\n",
       "      <th>penggunaan_perangkat_teknologi</th>\n",
       "      <th>konsumsi_alkohol</th>\n",
       "      <th>transporasi_biasa_digunakan</th>\n",
       "      <th>kelas_obesitas</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>21</td>\n",
       "      <td>1.620000</td>\n",
       "      <td>64</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>kelebihan_berat_badan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0</td>\n",
       "      <td>21</td>\n",
       "      <td>1.520000</td>\n",
       "      <td>56</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>kelebihan_berat_badan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>29</td>\n",
       "      <td>1.620000</td>\n",
       "      <td>53</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>normal</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0</td>\n",
       "      <td>23</td>\n",
       "      <td>1.500000</td>\n",
       "      <td>55</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>kelebihan_berat_badan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1</td>\n",
       "      <td>22</td>\n",
       "      <td>1.640000</td>\n",
       "      <td>53</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>normal</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>700</th>\n",
       "      <td>0</td>\n",
       "      <td>37</td>\n",
       "      <td>1.560000</td>\n",
       "      <td>80</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>obesitas_II</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>701</th>\n",
       "      <td>0</td>\n",
       "      <td>34</td>\n",
       "      <td>1.606212</td>\n",
       "      <td>79</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>obesitas_II</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>702</th>\n",
       "      <td>0</td>\n",
       "      <td>38</td>\n",
       "      <td>1.545496</td>\n",
       "      <td>79</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>obesitas_II</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>703</th>\n",
       "      <td>0</td>\n",
       "      <td>37</td>\n",
       "      <td>1.566180</td>\n",
       "      <td>80</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>obesitas_II</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>704</th>\n",
       "      <td>1</td>\n",
       "      <td>30</td>\n",
       "      <td>1.681425</td>\n",
       "      <td>90</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>obesitas_II</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>705 rows × 17 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     jenis_kelamin  umur  tinggi_badan_meter  berat_badan_kilogram  \\\n",
       "0                0    21            1.620000                    64   \n",
       "1                0    21            1.520000                    56   \n",
       "2                1    29            1.620000                    53   \n",
       "3                0    23            1.500000                    55   \n",
       "4                1    22            1.640000                    53   \n",
       "..             ...   ...                 ...                   ...   \n",
       "700              0    37            1.560000                    80   \n",
       "701              0    34            1.606212                    79   \n",
       "702              0    38            1.545496                    79   \n",
       "703              0    37            1.566180                    80   \n",
       "704              1    30            1.681425                    90   \n",
       "\n",
       "     histori_keluarga_kelebihan_BB  konsumsi_tinggi_kalori  konsumsi_sayuran  \\\n",
       "0                                1                       0                 1   \n",
       "1                                1                       0                 2   \n",
       "2                                0                       1                 1   \n",
       "3                                1                       1                 2   \n",
       "4                                0                       0                 1   \n",
       "..                             ...                     ...               ...   \n",
       "700                              1                       1                 2   \n",
       "701                              1                       0                 2   \n",
       "702                              1                       1                 1   \n",
       "703                              1                       1                 2   \n",
       "704                              1                       1                 2   \n",
       "\n",
       "     makan_berat  ngemil  merokok  konsumsi_air_liter  pemantauan_kalori  \\\n",
       "0              2       1        0                   2                  0   \n",
       "1              2       1        1                   3                  1   \n",
       "2              2       1        0                   2                  0   \n",
       "3              2       1        0                   2                  0   \n",
       "4              2       1        0                   2                  0   \n",
       "..           ...     ...      ...                 ...                ...   \n",
       "700            1       1        0                   2                  0   \n",
       "701            2       1        0                   2                  0   \n",
       "702            2       1        0                   2                  0   \n",
       "703            1       1        0                   2                  0   \n",
       "704            2       1        0                   3                  0   \n",
       "\n",
       "     aktifitas_fisik  penggunaan_perangkat_teknologi  konsumsi_alkohol  \\\n",
       "0                  0                               1                 0   \n",
       "1                  3                               1                 1   \n",
       "2                  0                               1                 1   \n",
       "3                  1                               1                 1   \n",
       "4                  3                               1                 1   \n",
       "..               ...                             ...               ...   \n",
       "700                0                               1                 1   \n",
       "701                0                               1                 1   \n",
       "702                0                               1                 1   \n",
       "703                1                               1                 1   \n",
       "704                1                               1                 1   \n",
       "\n",
       "     transporasi_biasa_digunakan         kelas_obesitas  \n",
       "0                              1  kelebihan_berat_badan  \n",
       "1                              1  kelebihan_berat_badan  \n",
       "2                              4                 normal  \n",
       "3                              3  kelebihan_berat_badan  \n",
       "4                              1                 normal  \n",
       "..                           ...                    ...  \n",
       "700                            4            obesitas_II  \n",
       "701                            2            obesitas_II  \n",
       "702                            4            obesitas_II  \n",
       "703                            4            obesitas_II  \n",
       "704                            4            obesitas_II  \n",
       "\n",
       "[705 rows x 17 columns]"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from imblearn.over_sampling import SMOTE\n",
    "\n",
    "smote = SMOTE(sampling_strategy='auto', random_state=0)\n",
    "\n",
    "X_res, y_res = smote.fit_resample(X, Y)\n",
    "\n",
    "data = pd.concat([X_res, y_res], axis=1)\n",
    "\n",
    "print(data['kelas_obesitas'].value_counts())\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "72453471",
   "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>kelas_obesitas</th>\n",
       "      <th>jumlah</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>berat_badan_kurang</td>\n",
       "      <td>141</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>normal</td>\n",
       "      <td>141</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>kelebihan_berat_badan</td>\n",
       "      <td>141</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>obesitas_I</td>\n",
       "      <td>141</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>obesitas_II</td>\n",
       "      <td>141</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          kelas_obesitas  jumlah\n",
       "4     berat_badan_kurang     141\n",
       "1                 normal     141\n",
       "0  kelebihan_berat_badan     141\n",
       "2             obesitas_I     141\n",
       "3            obesitas_II     141"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "kelas_obesitas = data['kelas_obesitas'].value_counts().rename_axis('kelas_obesitas').reset_index(name='jumlah')\n",
    "urutan_obesitas = ['berat_badan_kurang',\n",
    "                'normal',\n",
    "                'kelebihan_berat_badan',\n",
    "                'obesitas_I',\n",
    "                'obesitas_II']\n",
    "kelas_obesitas['kelas_obesitas'] = pd.Categorical(kelas_obesitas['kelas_obesitas'], categories=urutan_obesitas, ordered=True)\n",
    "kelas_obesitas = kelas_obesitas.sort_values(by='kelas_obesitas')\n",
    "kelas_obesitas"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "fd5717da",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 42968 characters]",
      "text/plain": [
       "<Figure size 500x500 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.figure(figsize=(5, 5))\n",
    "colors = sns.color_palette('pastel')\n",
    "\n",
    "plt.pie(kelas_obesitas['jumlah'], labels=kelas_obesitas['kelas_obesitas'], autopct='%1.1f%%', colors=colors)\n",
    "\n",
    "plt.title('Perbandingan Persentase Kelas Obesitas')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "64996edd",
   "metadata": {},
   "source": [
    "### download data yang telah di-SMOTE"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "7a6b3dea",
   "metadata": {},
   "outputs": [],
   "source": [
    "# excel_file = pd.ExcelWriter(\"smote_full_data_obesitas.xlsx\")\n",
    "# data.to_excel(excel_file, index=False)\n",
    "# excel_file.save()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bae7ae5a",
   "metadata": {},
   "source": [
    "### rasio"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "13ca1902",
   "metadata": {},
   "outputs": [],
   "source": [
    "test_size = 0.02"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4afc40d8",
   "metadata": {},
   "source": [
    "### Siap kan data untuk ditampilkan pada sistem"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "8f5ef97b",
   "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>jenis_kelamin</th>\n",
       "      <th>umur</th>\n",
       "      <th>tinggi_badan_meter</th>\n",
       "      <th>berat_badan_kilogram</th>\n",
       "      <th>histori_keluarga_kelebihan_BB</th>\n",
       "      <th>konsumsi_tinggi_kalori</th>\n",
       "      <th>konsumsi_sayuran</th>\n",
       "      <th>makan_berat</th>\n",
       "      <th>ngemil</th>\n",
       "      <th>merokok</th>\n",
       "      <th>konsumsi_air_liter</th>\n",
       "      <th>pemantauan_kalori</th>\n",
       "      <th>aktifitas_fisik</th>\n",
       "      <th>penggunaan_perangkat_teknologi</th>\n",
       "      <th>konsumsi_alkohol</th>\n",
       "      <th>transporasi_biasa_digunakan</th>\n",
       "      <th>kelas_obesitas</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>21</td>\n",
       "      <td>1.620000</td>\n",
       "      <td>64</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>kelebihan_berat_badan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0</td>\n",
       "      <td>21</td>\n",
       "      <td>1.520000</td>\n",
       "      <td>56</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>kelebihan_berat_badan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>29</td>\n",
       "      <td>1.620000</td>\n",
       "      <td>53</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>normal</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0</td>\n",
       "      <td>23</td>\n",
       "      <td>1.500000</td>\n",
       "      <td>55</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>kelebihan_berat_badan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1</td>\n",
       "      <td>22</td>\n",
       "      <td>1.640000</td>\n",
       "      <td>53</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>normal</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>700</th>\n",
       "      <td>0</td>\n",
       "      <td>37</td>\n",
       "      <td>1.560000</td>\n",
       "      <td>80</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>obesitas_II</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>701</th>\n",
       "      <td>0</td>\n",
       "      <td>34</td>\n",
       "      <td>1.606212</td>\n",
       "      <td>79</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>obesitas_II</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>702</th>\n",
       "      <td>0</td>\n",
       "      <td>38</td>\n",
       "      <td>1.545496</td>\n",
       "      <td>79</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>obesitas_II</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>703</th>\n",
       "      <td>0</td>\n",
       "      <td>37</td>\n",
       "      <td>1.566180</td>\n",
       "      <td>80</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>obesitas_II</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>704</th>\n",
       "      <td>1</td>\n",
       "      <td>30</td>\n",
       "      <td>1.681425</td>\n",
       "      <td>90</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>obesitas_II</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>705 rows × 17 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     jenis_kelamin  umur  tinggi_badan_meter  berat_badan_kilogram  \\\n",
       "0                0    21            1.620000                    64   \n",
       "1                0    21            1.520000                    56   \n",
       "2                1    29            1.620000                    53   \n",
       "3                0    23            1.500000                    55   \n",
       "4                1    22            1.640000                    53   \n",
       "..             ...   ...                 ...                   ...   \n",
       "700              0    37            1.560000                    80   \n",
       "701              0    34            1.606212                    79   \n",
       "702              0    38            1.545496                    79   \n",
       "703              0    37            1.566180                    80   \n",
       "704              1    30            1.681425                    90   \n",
       "\n",
       "     histori_keluarga_kelebihan_BB  konsumsi_tinggi_kalori  konsumsi_sayuran  \\\n",
       "0                                1                       0                 1   \n",
       "1                                1                       0                 2   \n",
       "2                                0                       1                 1   \n",
       "3                                1                       1                 2   \n",
       "4                                0                       0                 1   \n",
       "..                             ...                     ...               ...   \n",
       "700                              1                       1                 2   \n",
       "701                              1                       0                 2   \n",
       "702                              1                       1                 1   \n",
       "703                              1                       1                 2   \n",
       "704                              1                       1                 2   \n",
       "\n",
       "     makan_berat  ngemil  merokok  konsumsi_air_liter  pemantauan_kalori  \\\n",
       "0              2       1        0                   2                  0   \n",
       "1              2       1        1                   3                  1   \n",
       "2              2       1        0                   2                  0   \n",
       "3              2       1        0                   2                  0   \n",
       "4              2       1        0                   2                  0   \n",
       "..           ...     ...      ...                 ...                ...   \n",
       "700            1       1        0                   2                  0   \n",
       "701            2       1        0                   2                  0   \n",
       "702            2       1        0                   2                  0   \n",
       "703            1       1        0                   2                  0   \n",
       "704            2       1        0                   3                  0   \n",
       "\n",
       "     aktifitas_fisik  penggunaan_perangkat_teknologi  konsumsi_alkohol  \\\n",
       "0                  0                               1                 0   \n",
       "1                  3                               1                 1   \n",
       "2                  0                               1                 1   \n",
       "3                  1                               1                 1   \n",
       "4                  3                               1                 1   \n",
       "..               ...                             ...               ...   \n",
       "700                0                               1                 1   \n",
       "701                0                               1                 1   \n",
       "702                0                               1                 1   \n",
       "703                1                               1                 1   \n",
       "704                1                               1                 1   \n",
       "\n",
       "     transporasi_biasa_digunakan         kelas_obesitas  \n",
       "0                              1  kelebihan_berat_badan  \n",
       "1                              1  kelebihan_berat_badan  \n",
       "2                              4                 normal  \n",
       "3                              3  kelebihan_berat_badan  \n",
       "4                              1                 normal  \n",
       "..                           ...                    ...  \n",
       "700                            4            obesitas_II  \n",
       "701                            2            obesitas_II  \n",
       "702                            4            obesitas_II  \n",
       "703                            4            obesitas_II  \n",
       "704                            4            obesitas_II  \n",
       "\n",
       "[705 rows x 17 columns]"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_baru = data.copy()\n",
    "data_baru"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "e5fffcfe",
   "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>jenis_kelamin</th>\n",
       "      <th>umur</th>\n",
       "      <th>tinggi_badan_meter</th>\n",
       "      <th>berat_badan_kilogram</th>\n",
       "      <th>histori_keluarga_kelebihan_BB</th>\n",
       "      <th>konsumsi_tinggi_kalori</th>\n",
       "      <th>konsumsi_sayuran</th>\n",
       "      <th>makan_berat</th>\n",
       "      <th>ngemil</th>\n",
       "      <th>merokok</th>\n",
       "      <th>konsumsi_air_liter</th>\n",
       "      <th>pemantauan_kalori</th>\n",
       "      <th>aktifitas_fisik</th>\n",
       "      <th>penggunaan_perangkat_teknologi</th>\n",
       "      <th>konsumsi_alkohol</th>\n",
       "      <th>transporasi_biasa_digunakan</th>\n",
       "      <th>kelas_obesitas</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>21</td>\n",
       "      <td>1.620000</td>\n",
       "      <td>64</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>3x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>Sepeda motor</td>\n",
       "      <td>kelebihan_berat_badan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>21</td>\n",
       "      <td>1.520000</td>\n",
       "      <td>56</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Selalu</td>\n",
       "      <td>3x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Lebih 2 liter</td>\n",
       "      <td>Ya</td>\n",
       "      <td>4-5 hari</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Sepeda motor</td>\n",
       "      <td>kelebihan_berat_badan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Laki-laki</td>\n",
       "      <td>29</td>\n",
       "      <td>1.620000</td>\n",
       "      <td>53</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>3x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Jalan kaki</td>\n",
       "      <td>normal</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>23</td>\n",
       "      <td>1.500000</td>\n",
       "      <td>55</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Selalu</td>\n",
       "      <td>3x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 hari</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Transportasi umum</td>\n",
       "      <td>kelebihan_berat_badan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Laki-laki</td>\n",
       "      <td>22</td>\n",
       "      <td>1.640000</td>\n",
       "      <td>53</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>3x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>4-5 hari</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Sepeda motor</td>\n",
       "      <td>normal</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>700</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>37</td>\n",
       "      <td>1.560000</td>\n",
       "      <td>80</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Selalu</td>\n",
       "      <td>1-2x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Jalan kaki</td>\n",
       "      <td>obesitas_II</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>701</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>34</td>\n",
       "      <td>1.606212</td>\n",
       "      <td>79</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Selalu</td>\n",
       "      <td>3x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Sepeda</td>\n",
       "      <td>obesitas_II</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>702</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>38</td>\n",
       "      <td>1.545496</td>\n",
       "      <td>79</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>3x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Jalan kaki</td>\n",
       "      <td>obesitas_II</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>703</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>37</td>\n",
       "      <td>1.566180</td>\n",
       "      <td>80</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Selalu</td>\n",
       "      <td>1-2x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 hari</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Jalan kaki</td>\n",
       "      <td>obesitas_II</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>704</th>\n",
       "      <td>Laki-laki</td>\n",
       "      <td>30</td>\n",
       "      <td>1.681425</td>\n",
       "      <td>90</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Selalu</td>\n",
       "      <td>3x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Lebih 2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 hari</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Jalan kaki</td>\n",
       "      <td>obesitas_II</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>705 rows × 17 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    jenis_kelamin  umur  tinggi_badan_meter  berat_badan_kilogram  \\\n",
       "0       Perempuan    21            1.620000                    64   \n",
       "1       Perempuan    21            1.520000                    56   \n",
       "2       Laki-laki    29            1.620000                    53   \n",
       "3       Perempuan    23            1.500000                    55   \n",
       "4       Laki-laki    22            1.640000                    53   \n",
       "..            ...   ...                 ...                   ...   \n",
       "700     Perempuan    37            1.560000                    80   \n",
       "701     Perempuan    34            1.606212                    79   \n",
       "702     Perempuan    38            1.545496                    79   \n",
       "703     Perempuan    37            1.566180                    80   \n",
       "704     Laki-laki    30            1.681425                    90   \n",
       "\n",
       "    histori_keluarga_kelebihan_BB konsumsi_tinggi_kalori konsumsi_sayuran  \\\n",
       "0                              Ya                  Tidak    Kadang-kadang   \n",
       "1                              Ya                  Tidak           Selalu   \n",
       "2                           Tidak                     Ya    Kadang-kadang   \n",
       "3                              Ya                     Ya           Selalu   \n",
       "4                           Tidak                  Tidak    Kadang-kadang   \n",
       "..                            ...                    ...              ...   \n",
       "700                            Ya                     Ya           Selalu   \n",
       "701                            Ya                  Tidak           Selalu   \n",
       "702                            Ya                     Ya    Kadang-kadang   \n",
       "703                            Ya                     Ya           Selalu   \n",
       "704                            Ya                     Ya           Selalu   \n",
       "\n",
       "    makan_berat         ngemil merokok konsumsi_air_liter pemantauan_kalori  \\\n",
       "0            3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "1            3x  Kadang-kadang      Ya      Lebih 2 liter                Ya   \n",
       "2            3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "3            3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "4            3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "..          ...            ...     ...                ...               ...   \n",
       "700        1-2x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "701          3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "702          3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "703        1-2x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "704          3x  Kadang-kadang   Tidak      Lebih 2 liter             Tidak   \n",
       "\n",
       "    aktifitas_fisik penggunaan_perangkat_teknologi konsumsi_alkohol  \\\n",
       "0      Tidak pernah                        0-2 jam     Tidak pernah   \n",
       "1          4-5 hari                        0-2 jam    Kadang-kadang   \n",
       "2      Tidak pernah                        0-2 jam    Kadang-kadang   \n",
       "3          1-2 hari                        0-2 jam    Kadang-kadang   \n",
       "4          4-5 hari                        0-2 jam    Kadang-kadang   \n",
       "..              ...                            ...              ...   \n",
       "700    Tidak pernah                        0-2 jam    Kadang-kadang   \n",
       "701    Tidak pernah                        0-2 jam    Kadang-kadang   \n",
       "702    Tidak pernah                        0-2 jam    Kadang-kadang   \n",
       "703        1-2 hari                        0-2 jam    Kadang-kadang   \n",
       "704        1-2 hari                        0-2 jam    Kadang-kadang   \n",
       "\n",
       "    transporasi_biasa_digunakan         kelas_obesitas  \n",
       "0                  Sepeda motor  kelebihan_berat_badan  \n",
       "1                  Sepeda motor  kelebihan_berat_badan  \n",
       "2                    Jalan kaki                 normal  \n",
       "3             Transportasi umum  kelebihan_berat_badan  \n",
       "4                  Sepeda motor                 normal  \n",
       "..                          ...                    ...  \n",
       "700                  Jalan kaki            obesitas_II  \n",
       "701                      Sepeda            obesitas_II  \n",
       "702                  Jalan kaki            obesitas_II  \n",
       "703                  Jalan kaki            obesitas_II  \n",
       "704                  Jalan kaki            obesitas_II  \n",
       "\n",
       "[705 rows x 17 columns]"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_baru['jenis_kelamin'] = data_baru['jenis_kelamin'].replace(1, 'Laki-laki')\n",
    "data_baru['jenis_kelamin'] = data_baru['jenis_kelamin'].replace(0, 'Perempuan')\n",
    "\n",
    "data_baru['histori_keluarga_kelebihan_BB'] = data_baru['histori_keluarga_kelebihan_BB'].replace(1, 'Ya')\n",
    "data_baru['histori_keluarga_kelebihan_BB'] = data_baru['histori_keluarga_kelebihan_BB'].replace(0, 'Tidak')\n",
    "\n",
    "data_baru['konsumsi_tinggi_kalori'] = data_baru['konsumsi_tinggi_kalori'].replace(1, 'Ya')\n",
    "data_baru['konsumsi_tinggi_kalori'] = data_baru['konsumsi_tinggi_kalori'].replace(0, 'Tidak')\n",
    "\n",
    "data_baru['konsumsi_sayuran'] = data_baru['konsumsi_sayuran'].replace(2, 'Selalu')\n",
    "data_baru['konsumsi_sayuran'] = data_baru['konsumsi_sayuran'].replace(1, 'Kadang-kadang')\n",
    "data_baru['konsumsi_sayuran'] = data_baru['konsumsi_sayuran'].replace(0, 'Tidak pernah')\n",
    "\n",
    "data_baru['makan_berat'] = data_baru['makan_berat'].replace(3, 'Lebih 3x')\n",
    "data_baru['makan_berat'] = data_baru['makan_berat'].replace(2, '3x')\n",
    "data_baru['makan_berat'] = data_baru['makan_berat'].replace(1, '1-2x')\n",
    "\n",
    "data_baru['ngemil'] = data_baru['ngemil'].replace(3, 'Selalu')\n",
    "data_baru['ngemil'] = data_baru['ngemil'].replace(2, 'Sering')\n",
    "data_baru['ngemil'] = data_baru['ngemil'].replace(1, 'Kadang-kadang')\n",
    "data_baru['ngemil'] = data_baru['ngemil'].replace(0, 'Tidak pernah')\n",
    "\n",
    "data_baru['merokok'] = data_baru['merokok'].replace(1, 'Ya')\n",
    "data_baru['merokok'] = data_baru['merokok'].replace(0, 'Tidak')\n",
    "\n",
    "data_baru['konsumsi_air_liter'] = data_baru['konsumsi_air_liter'].replace(3, 'Lebih 2 liter')\n",
    "data_baru['konsumsi_air_liter'] = data_baru['konsumsi_air_liter'].replace(2, '1-2 liter')\n",
    "data_baru['konsumsi_air_liter'] = data_baru['konsumsi_air_liter'].replace(1, 'Kurang 1 liter')\n",
    "\n",
    "data_baru['pemantauan_kalori'] = data_baru['pemantauan_kalori'].replace(1, 'Ya')\n",
    "data_baru['pemantauan_kalori'] = data_baru['pemantauan_kalori'].replace(0, 'Tidak')\n",
    "\n",
    "data_baru['aktifitas_fisik'] = data_baru['aktifitas_fisik'].replace(3, '4-5 hari')\n",
    "data_baru['aktifitas_fisik'] = data_baru['aktifitas_fisik'].replace(2, '2-4 hari')\n",
    "data_baru['aktifitas_fisik'] = data_baru['aktifitas_fisik'].replace(1, '1-2 hari')\n",
    "data_baru['aktifitas_fisik'] = data_baru['aktifitas_fisik'].replace(0, 'Tidak pernah')\n",
    "\n",
    "data_baru['penggunaan_perangkat_teknologi'] = data_baru['penggunaan_perangkat_teknologi'].replace(3, 'Lebih 5 jam')\n",
    "data_baru['penggunaan_perangkat_teknologi'] = data_baru['penggunaan_perangkat_teknologi'].replace(2, '3-5 jam')\n",
    "data_baru['penggunaan_perangkat_teknologi'] = data_baru['penggunaan_perangkat_teknologi'].replace(1, '0-2 jam')\n",
    "\n",
    "data_baru['konsumsi_alkohol'] = data_baru['konsumsi_alkohol'].replace(3, 'Selalu')\n",
    "data_baru['konsumsi_alkohol'] = data_baru['konsumsi_alkohol'].replace(2, 'Sering')\n",
    "data_baru['konsumsi_alkohol'] = data_baru['konsumsi_alkohol'].replace(1, 'Kadang-kadang')\n",
    "data_baru['konsumsi_alkohol'] = data_baru['konsumsi_alkohol'].replace(0, 'Tidak pernah')\n",
    "\n",
    "data_baru['transporasi_biasa_digunakan'] = data_baru['transporasi_biasa_digunakan'].replace(0, 'Mobil')\n",
    "data_baru['transporasi_biasa_digunakan'] = data_baru['transporasi_biasa_digunakan'].replace(1, 'Sepeda motor')\n",
    "data_baru['transporasi_biasa_digunakan'] = data_baru['transporasi_biasa_digunakan'].replace(2, 'Sepeda')\n",
    "data_baru['transporasi_biasa_digunakan'] = data_baru['transporasi_biasa_digunakan'].replace(3, 'Transportasi umum')\n",
    "data_baru['transporasi_biasa_digunakan'] = data_baru['transporasi_biasa_digunakan'].replace(4, 'Jalan kaki')\n",
    "\n",
    "data_baru"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "618d2003",
   "metadata": {},
   "outputs": [],
   "source": [
    "Xbaru = data_baru.drop(columns='kelas_obesitas', axis = 1)\n",
    "Ybaru = data_baru['kelas_obesitas']\n",
    "X_trainbaru, X_testbaru, Y_trainbaru, Y_testbaru  = train_test_split(data_baru, data_baru, test_size = test_size, stratify = Ybaru, random_state = 0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "545515bd",
   "metadata": {
    "scrolled": true
   },
   "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>jenis_kelamin</th>\n",
       "      <th>umur</th>\n",
       "      <th>tinggi_badan_meter</th>\n",
       "      <th>berat_badan_kilogram</th>\n",
       "      <th>histori_keluarga_kelebihan_BB</th>\n",
       "      <th>konsumsi_tinggi_kalori</th>\n",
       "      <th>konsumsi_sayuran</th>\n",
       "      <th>makan_berat</th>\n",
       "      <th>ngemil</th>\n",
       "      <th>merokok</th>\n",
       "      <th>konsumsi_air_liter</th>\n",
       "      <th>pemantauan_kalori</th>\n",
       "      <th>aktifitas_fisik</th>\n",
       "      <th>penggunaan_perangkat_teknologi</th>\n",
       "      <th>konsumsi_alkohol</th>\n",
       "      <th>transporasi_biasa_digunakan</th>\n",
       "      <th>kelas_obesitas</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>167</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>23</td>\n",
       "      <td>1.700000</td>\n",
       "      <td>56</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Selalu</td>\n",
       "      <td>Lebih 3x</td>\n",
       "      <td>Selalu</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Lebih 2 liter</td>\n",
       "      <td>Ya</td>\n",
       "      <td>4-5 hari</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>Jalan kaki</td>\n",
       "      <td>normal</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>101</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>41</td>\n",
       "      <td>1.540000</td>\n",
       "      <td>80</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>3x</td>\n",
       "      <td>Selalu</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Jalan kaki</td>\n",
       "      <td>obesitas_II</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>680</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>37</td>\n",
       "      <td>1.500000</td>\n",
       "      <td>75</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>3x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Transportasi umum</td>\n",
       "      <td>obesitas_II</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>271</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>19</td>\n",
       "      <td>1.540000</td>\n",
       "      <td>42</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Selalu</td>\n",
       "      <td>1-2x</td>\n",
       "      <td>Sering</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 hari</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Sepeda motor</td>\n",
       "      <td>berat_badan_kurang</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>529</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>20</td>\n",
       "      <td>1.572607</td>\n",
       "      <td>59</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>1-2x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>Sepeda motor</td>\n",
       "      <td>kelebihan_berat_badan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>285</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>20</td>\n",
       "      <td>1.670000</td>\n",
       "      <td>49</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Selalu</td>\n",
       "      <td>Lebih 3x</td>\n",
       "      <td>Sering</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Lebih 2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>2-4 hari</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>Sepeda motor</td>\n",
       "      <td>berat_badan_kurang</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>151</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>21</td>\n",
       "      <td>1.530000</td>\n",
       "      <td>53</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Selalu</td>\n",
       "      <td>3x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>2-4 hari</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Sepeda motor</td>\n",
       "      <td>normal</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>Laki-laki</td>\n",
       "      <td>22</td>\n",
       "      <td>1.650000</td>\n",
       "      <td>62</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Lebih 3x</td>\n",
       "      <td>Sering</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>2-4 hari</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Sepeda motor</td>\n",
       "      <td>normal</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>21</td>\n",
       "      <td>1.620000</td>\n",
       "      <td>64</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>3x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>Sepeda motor</td>\n",
       "      <td>kelebihan_berat_badan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>585</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>33</td>\n",
       "      <td>1.680000</td>\n",
       "      <td>77</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Selalu</td>\n",
       "      <td>1-2x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>Jalan kaki</td>\n",
       "      <td>obesitas_I</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>690 rows × 17 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    jenis_kelamin  umur  tinggi_badan_meter  berat_badan_kilogram  \\\n",
       "167     Perempuan    23            1.700000                    56   \n",
       "101     Perempuan    41            1.540000                    80   \n",
       "680     Perempuan    37            1.500000                    75   \n",
       "271     Perempuan    19            1.540000                    42   \n",
       "529     Perempuan    20            1.572607                    59   \n",
       "..            ...   ...                 ...                   ...   \n",
       "285     Perempuan    20            1.670000                    49   \n",
       "151     Perempuan    21            1.530000                    53   \n",
       "15      Laki-laki    22            1.650000                    62   \n",
       "0       Perempuan    21            1.620000                    64   \n",
       "585     Perempuan    33            1.680000                    77   \n",
       "\n",
       "    histori_keluarga_kelebihan_BB konsumsi_tinggi_kalori konsumsi_sayuran  \\\n",
       "167                         Tidak                  Tidak           Selalu   \n",
       "101                            Ya                     Ya    Kadang-kadang   \n",
       "680                            Ya                     Ya    Kadang-kadang   \n",
       "271                         Tidak                     Ya           Selalu   \n",
       "529                         Tidak                     Ya    Kadang-kadang   \n",
       "..                            ...                    ...              ...   \n",
       "285                            Ya                     Ya           Selalu   \n",
       "151                         Tidak                     Ya           Selalu   \n",
       "15                          Tidak                     Ya    Kadang-kadang   \n",
       "0                              Ya                  Tidak    Kadang-kadang   \n",
       "585                            Ya                     Ya           Selalu   \n",
       "\n",
       "    makan_berat         ngemil merokok konsumsi_air_liter pemantauan_kalori  \\\n",
       "167    Lebih 3x         Selalu   Tidak      Lebih 2 liter                Ya   \n",
       "101          3x         Selalu   Tidak          1-2 liter             Tidak   \n",
       "680          3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "271        1-2x         Sering   Tidak          1-2 liter             Tidak   \n",
       "529        1-2x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "..          ...            ...     ...                ...               ...   \n",
       "285    Lebih 3x         Sering   Tidak      Lebih 2 liter             Tidak   \n",
       "151          3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "15     Lebih 3x         Sering   Tidak          1-2 liter             Tidak   \n",
       "0            3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "585        1-2x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "\n",
       "    aktifitas_fisik penggunaan_perangkat_teknologi konsumsi_alkohol  \\\n",
       "167        4-5 hari                        0-2 jam     Tidak pernah   \n",
       "101    Tidak pernah                        0-2 jam    Kadang-kadang   \n",
       "680    Tidak pernah                        0-2 jam    Kadang-kadang   \n",
       "271        1-2 hari                        0-2 jam    Kadang-kadang   \n",
       "529    Tidak pernah                        0-2 jam     Tidak pernah   \n",
       "..              ...                            ...              ...   \n",
       "285        2-4 hari                        0-2 jam     Tidak pernah   \n",
       "151        2-4 hari                        0-2 jam    Kadang-kadang   \n",
       "15         2-4 hari                        0-2 jam    Kadang-kadang   \n",
       "0      Tidak pernah                        0-2 jam     Tidak pernah   \n",
       "585    Tidak pernah                        0-2 jam     Tidak pernah   \n",
       "\n",
       "    transporasi_biasa_digunakan         kelas_obesitas  \n",
       "167                  Jalan kaki                 normal  \n",
       "101                  Jalan kaki            obesitas_II  \n",
       "680           Transportasi umum            obesitas_II  \n",
       "271                Sepeda motor     berat_badan_kurang  \n",
       "529                Sepeda motor  kelebihan_berat_badan  \n",
       "..                          ...                    ...  \n",
       "285                Sepeda motor     berat_badan_kurang  \n",
       "151                Sepeda motor                 normal  \n",
       "15                 Sepeda motor                 normal  \n",
       "0                  Sepeda motor  kelebihan_berat_badan  \n",
       "585                  Jalan kaki             obesitas_I  \n",
       "\n",
       "[690 rows x 17 columns]"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X_trainbaru"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "e7332fae",
   "metadata": {
    "scrolled": true
   },
   "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>jenis_kelamin</th>\n",
       "      <th>umur</th>\n",
       "      <th>tinggi_badan_meter</th>\n",
       "      <th>berat_badan_kilogram</th>\n",
       "      <th>histori_keluarga_kelebihan_BB</th>\n",
       "      <th>konsumsi_tinggi_kalori</th>\n",
       "      <th>konsumsi_sayuran</th>\n",
       "      <th>makan_berat</th>\n",
       "      <th>ngemil</th>\n",
       "      <th>merokok</th>\n",
       "      <th>konsumsi_air_liter</th>\n",
       "      <th>pemantauan_kalori</th>\n",
       "      <th>aktifitas_fisik</th>\n",
       "      <th>penggunaan_perangkat_teknologi</th>\n",
       "      <th>konsumsi_alkohol</th>\n",
       "      <th>transporasi_biasa_digunakan</th>\n",
       "      <th>kelas_obesitas</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>606</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>31</td>\n",
       "      <td>1.672625</td>\n",
       "      <td>71</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>3x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Jalan kaki</td>\n",
       "      <td>obesitas_I</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>71</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>19</td>\n",
       "      <td>1.650000</td>\n",
       "      <td>56</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Selalu</td>\n",
       "      <td>3x</td>\n",
       "      <td>Sering</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Lebih 2 liter</td>\n",
       "      <td>Ya</td>\n",
       "      <td>1-2 hari</td>\n",
       "      <td>3-5 jam</td>\n",
       "      <td>Sering</td>\n",
       "      <td>Sepeda motor</td>\n",
       "      <td>normal</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>609</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>39</td>\n",
       "      <td>1.711621</td>\n",
       "      <td>84</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Selalu</td>\n",
       "      <td>1-2x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Lebih 2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>Jalan kaki</td>\n",
       "      <td>obesitas_I</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>678</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>37</td>\n",
       "      <td>1.560000</td>\n",
       "      <td>79</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>3x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Jalan kaki</td>\n",
       "      <td>obesitas_II</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>644</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>39</td>\n",
       "      <td>1.528746</td>\n",
       "      <td>79</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>3x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Jalan kaki</td>\n",
       "      <td>obesitas_II</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>275</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>20</td>\n",
       "      <td>1.550000</td>\n",
       "      <td>41</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Selalu</td>\n",
       "      <td>1-2x</td>\n",
       "      <td>Sering</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Sepeda motor</td>\n",
       "      <td>berat_badan_kurang</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>173</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>21</td>\n",
       "      <td>1.540000</td>\n",
       "      <td>47</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Selalu</td>\n",
       "      <td>3x</td>\n",
       "      <td>Selalu</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>2-4 hari</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>Sepeda motor</td>\n",
       "      <td>normal</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>510</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>25</td>\n",
       "      <td>1.643548</td>\n",
       "      <td>62</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>3x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 hari</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>Mobil</td>\n",
       "      <td>kelebihan_berat_badan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>548</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>21</td>\n",
       "      <td>1.641347</td>\n",
       "      <td>66</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Selalu</td>\n",
       "      <td>1-2x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>Sepeda motor</td>\n",
       "      <td>kelebihan_berat_badan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>389</th>\n",
       "      <td>Laki-laki</td>\n",
       "      <td>39</td>\n",
       "      <td>1.720000</td>\n",
       "      <td>86</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Selalu</td>\n",
       "      <td>1-2x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>Jalan kaki</td>\n",
       "      <td>obesitas_I</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>394</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>37</td>\n",
       "      <td>1.560000</td>\n",
       "      <td>77</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>3x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Jalan kaki</td>\n",
       "      <td>obesitas_II</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>206</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>18</td>\n",
       "      <td>1.640000</td>\n",
       "      <td>59</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>3x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 hari</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Sepeda motor</td>\n",
       "      <td>normal</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>295</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>19</td>\n",
       "      <td>1.680000</td>\n",
       "      <td>49</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Selalu</td>\n",
       "      <td>3x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 hari</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Sepeda motor</td>\n",
       "      <td>berat_badan_kurang</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>480</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>21</td>\n",
       "      <td>1.694749</td>\n",
       "      <td>49</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Selalu</td>\n",
       "      <td>3x</td>\n",
       "      <td>Sering</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>Sepeda motor</td>\n",
       "      <td>berat_badan_kurang</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>124</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>20</td>\n",
       "      <td>1.630000</td>\n",
       "      <td>64</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>3x</td>\n",
       "      <td>Selalu</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>3-5 jam</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>Jalan kaki</td>\n",
       "      <td>kelebihan_berat_badan</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    jenis_kelamin  umur  tinggi_badan_meter  berat_badan_kilogram  \\\n",
       "606     Perempuan    31            1.672625                    71   \n",
       "71      Perempuan    19            1.650000                    56   \n",
       "609     Perempuan    39            1.711621                    84   \n",
       "678     Perempuan    37            1.560000                    79   \n",
       "644     Perempuan    39            1.528746                    79   \n",
       "275     Perempuan    20            1.550000                    41   \n",
       "173     Perempuan    21            1.540000                    47   \n",
       "510     Perempuan    25            1.643548                    62   \n",
       "548     Perempuan    21            1.641347                    66   \n",
       "389     Laki-laki    39            1.720000                    86   \n",
       "394     Perempuan    37            1.560000                    77   \n",
       "206     Perempuan    18            1.640000                    59   \n",
       "295     Perempuan    19            1.680000                    49   \n",
       "480     Perempuan    21            1.694749                    49   \n",
       "124     Perempuan    20            1.630000                    64   \n",
       "\n",
       "    histori_keluarga_kelebihan_BB konsumsi_tinggi_kalori konsumsi_sayuran  \\\n",
       "606                            Ya                     Ya    Kadang-kadang   \n",
       "71                             Ya                     Ya           Selalu   \n",
       "609                         Tidak                     Ya           Selalu   \n",
       "678                            Ya                     Ya    Kadang-kadang   \n",
       "644                            Ya                     Ya    Kadang-kadang   \n",
       "275                         Tidak                     Ya           Selalu   \n",
       "173                            Ya                  Tidak           Selalu   \n",
       "510                         Tidak                  Tidak    Kadang-kadang   \n",
       "548                            Ya                     Ya           Selalu   \n",
       "389                            Ya                     Ya           Selalu   \n",
       "394                            Ya                     Ya    Kadang-kadang   \n",
       "206                            Ya                     Ya    Kadang-kadang   \n",
       "295                         Tidak                  Tidak           Selalu   \n",
       "480                            Ya                     Ya           Selalu   \n",
       "124                            Ya                     Ya     Tidak pernah   \n",
       "\n",
       "    makan_berat         ngemil merokok konsumsi_air_liter pemantauan_kalori  \\\n",
       "606          3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "71           3x         Sering      Ya      Lebih 2 liter                Ya   \n",
       "609        1-2x  Kadang-kadang   Tidak      Lebih 2 liter             Tidak   \n",
       "678          3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "644          3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "275        1-2x         Sering   Tidak          1-2 liter             Tidak   \n",
       "173          3x         Selalu   Tidak          1-2 liter             Tidak   \n",
       "510          3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "548        1-2x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "389        1-2x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "394          3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "206          3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "295          3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "480          3x         Sering   Tidak          1-2 liter             Tidak   \n",
       "124          3x         Selalu   Tidak          1-2 liter             Tidak   \n",
       "\n",
       "    aktifitas_fisik penggunaan_perangkat_teknologi konsumsi_alkohol  \\\n",
       "606    Tidak pernah                        0-2 jam    Kadang-kadang   \n",
       "71         1-2 hari                        3-5 jam           Sering   \n",
       "609    Tidak pernah                        0-2 jam     Tidak pernah   \n",
       "678    Tidak pernah                        0-2 jam    Kadang-kadang   \n",
       "644    Tidak pernah                        0-2 jam    Kadang-kadang   \n",
       "275    Tidak pernah                        0-2 jam    Kadang-kadang   \n",
       "173        2-4 hari                        0-2 jam     Tidak pernah   \n",
       "510        1-2 hari                        0-2 jam     Tidak pernah   \n",
       "548    Tidak pernah                        0-2 jam     Tidak pernah   \n",
       "389    Tidak pernah                        0-2 jam     Tidak pernah   \n",
       "394    Tidak pernah                        0-2 jam    Kadang-kadang   \n",
       "206        1-2 hari                        0-2 jam    Kadang-kadang   \n",
       "295        1-2 hari                        0-2 jam    Kadang-kadang   \n",
       "480    Tidak pernah                        0-2 jam     Tidak pernah   \n",
       "124    Tidak pernah                        3-5 jam     Tidak pernah   \n",
       "\n",
       "    transporasi_biasa_digunakan         kelas_obesitas  \n",
       "606                  Jalan kaki             obesitas_I  \n",
       "71                 Sepeda motor                 normal  \n",
       "609                  Jalan kaki             obesitas_I  \n",
       "678                  Jalan kaki            obesitas_II  \n",
       "644                  Jalan kaki            obesitas_II  \n",
       "275                Sepeda motor     berat_badan_kurang  \n",
       "173                Sepeda motor                 normal  \n",
       "510                       Mobil  kelebihan_berat_badan  \n",
       "548                Sepeda motor  kelebihan_berat_badan  \n",
       "389                  Jalan kaki             obesitas_I  \n",
       "394                  Jalan kaki            obesitas_II  \n",
       "206                Sepeda motor                 normal  \n",
       "295                Sepeda motor     berat_badan_kurang  \n",
       "480                Sepeda motor     berat_badan_kurang  \n",
       "124                  Jalan kaki  kelebihan_berat_badan  "
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X_testbaru"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "a5fe3aac",
   "metadata": {},
   "outputs": [],
   "source": [
    "# excel_file = pd.ExcelWriter(\"smote_training_data_obesitas_baru.xlsx\")\n",
    "# X_trainbaru.to_excel(excel_file)\n",
    "# excel_file.save()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "9d273e8a",
   "metadata": {},
   "outputs": [],
   "source": [
    "# excel_file = pd.ExcelWriter(\"smote_testing_data_obesitas_baru.xlsx\")\n",
    "# X_testbaru.to_excel(excel_file)\n",
    "# excel_file.save()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c13fd6bc",
   "metadata": {},
   "source": [
    "### Siap kan data untuk perhitungan manual"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "5e1f265f",
   "metadata": {},
   "outputs": [],
   "source": [
    "Y = data['kelas_obesitas']\n",
    "X_trainhitung, X_testhitung, Y_trainhitung, Y_testhitung  = train_test_split(data, data, test_size = test_size, stratify = Y, random_state = 0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "31943e9b",
   "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>jenis_kelamin</th>\n",
       "      <th>umur</th>\n",
       "      <th>tinggi_badan_meter</th>\n",
       "      <th>berat_badan_kilogram</th>\n",
       "      <th>histori_keluarga_kelebihan_BB</th>\n",
       "      <th>konsumsi_tinggi_kalori</th>\n",
       "      <th>konsumsi_sayuran</th>\n",
       "      <th>makan_berat</th>\n",
       "      <th>ngemil</th>\n",
       "      <th>merokok</th>\n",
       "      <th>konsumsi_air_liter</th>\n",
       "      <th>pemantauan_kalori</th>\n",
       "      <th>aktifitas_fisik</th>\n",
       "      <th>penggunaan_perangkat_teknologi</th>\n",
       "      <th>konsumsi_alkohol</th>\n",
       "      <th>transporasi_biasa_digunakan</th>\n",
       "      <th>kelas_obesitas</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>271</th>\n",
       "      <td>0</td>\n",
       "      <td>19</td>\n",
       "      <td>1.540000</td>\n",
       "      <td>42</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>berat_badan_kurang</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>309</th>\n",
       "      <td>0</td>\n",
       "      <td>19</td>\n",
       "      <td>1.580000</td>\n",
       "      <td>44</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>berat_badan_kurang</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>266</th>\n",
       "      <td>0</td>\n",
       "      <td>19</td>\n",
       "      <td>1.530000</td>\n",
       "      <td>42</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>berat_badan_kurang</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>303</th>\n",
       "      <td>0</td>\n",
       "      <td>20</td>\n",
       "      <td>1.520000</td>\n",
       "      <td>42</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>berat_badan_kurang</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>291</th>\n",
       "      <td>0</td>\n",
       "      <td>20</td>\n",
       "      <td>1.520000</td>\n",
       "      <td>42</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>berat_badan_kurang</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>496</th>\n",
       "      <td>0</td>\n",
       "      <td>36</td>\n",
       "      <td>1.645857</td>\n",
       "      <td>48</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>berat_badan_kurang</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>454</th>\n",
       "      <td>0</td>\n",
       "      <td>21</td>\n",
       "      <td>1.673182</td>\n",
       "      <td>49</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>berat_badan_kurang</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>227</th>\n",
       "      <td>0</td>\n",
       "      <td>19</td>\n",
       "      <td>1.540000</td>\n",
       "      <td>42</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>berat_badan_kurang</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>273</th>\n",
       "      <td>0</td>\n",
       "      <td>21</td>\n",
       "      <td>1.670000</td>\n",
       "      <td>49</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>berat_badan_kurang</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>285</th>\n",
       "      <td>0</td>\n",
       "      <td>20</td>\n",
       "      <td>1.670000</td>\n",
       "      <td>49</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>berat_badan_kurang</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>138 rows × 17 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     jenis_kelamin  umur  tinggi_badan_meter  berat_badan_kilogram  \\\n",
       "271              0    19            1.540000                    42   \n",
       "309              0    19            1.580000                    44   \n",
       "266              0    19            1.530000                    42   \n",
       "303              0    20            1.520000                    42   \n",
       "291              0    20            1.520000                    42   \n",
       "..             ...   ...                 ...                   ...   \n",
       "496              0    36            1.645857                    48   \n",
       "454              0    21            1.673182                    49   \n",
       "227              0    19            1.540000                    42   \n",
       "273              0    21            1.670000                    49   \n",
       "285              0    20            1.670000                    49   \n",
       "\n",
       "     histori_keluarga_kelebihan_BB  konsumsi_tinggi_kalori  konsumsi_sayuran  \\\n",
       "271                              0                       1                 2   \n",
       "309                              0                       0                 2   \n",
       "266                              0                       0                 2   \n",
       "303                              0                       1                 2   \n",
       "291                              0                       1                 2   \n",
       "..                             ...                     ...               ...   \n",
       "496                              0                       1                 2   \n",
       "454                              1                       1                 2   \n",
       "227                              0                       1                 2   \n",
       "273                              1                       1                 2   \n",
       "285                              1                       1                 2   \n",
       "\n",
       "     makan_berat  ngemil  merokok  konsumsi_air_liter  pemantauan_kalori  \\\n",
       "271            1       2        0                   2                  0   \n",
       "309            2       2        0                   2                  1   \n",
       "266            1       2        0                   2                  0   \n",
       "303            1       2        0                   2                  0   \n",
       "291            1       2        0                   2                  0   \n",
       "..           ...     ...      ...                 ...                ...   \n",
       "496            3       2        0                   2                  0   \n",
       "454            2       2        0                   3                  0   \n",
       "227            1       1        0                   2                  0   \n",
       "273            2       2        0                   3                  0   \n",
       "285            3       2        0                   3                  0   \n",
       "\n",
       "     aktifitas_fisik  penggunaan_perangkat_teknologi  konsumsi_alkohol  \\\n",
       "271                1                               1                 1   \n",
       "309                0                               1                 1   \n",
       "266                1                               1                 1   \n",
       "303                0                               1                 1   \n",
       "291                0                               1                 1   \n",
       "..               ...                             ...               ...   \n",
       "496                0                               1                 0   \n",
       "454                0                               1                 0   \n",
       "227                0                               1                 0   \n",
       "273                0                               1                 0   \n",
       "285                2                               1                 0   \n",
       "\n",
       "     transporasi_biasa_digunakan      kelas_obesitas  \n",
       "271                            1  berat_badan_kurang  \n",
       "309                            1  berat_badan_kurang  \n",
       "266                            1  berat_badan_kurang  \n",
       "303                            1  berat_badan_kurang  \n",
       "291                            1  berat_badan_kurang  \n",
       "..                           ...                 ...  \n",
       "496                            1  berat_badan_kurang  \n",
       "454                            1  berat_badan_kurang  \n",
       "227                            1  berat_badan_kurang  \n",
       "273                            1  berat_badan_kurang  \n",
       "285                            1  berat_badan_kurang  \n",
       "\n",
       "[138 rows x 17 columns]"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_pilih_kelas = X_trainhitung[X_trainhitung['kelas_obesitas'] == 'berat_badan_kurang']\n",
    "data_pilih_kelas"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "048039cd",
   "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>jenis_kelamin</th>\n",
       "      <th>umur</th>\n",
       "      <th>tinggi_badan_meter</th>\n",
       "      <th>berat_badan_kilogram</th>\n",
       "      <th>histori_keluarga_kelebihan_BB</th>\n",
       "      <th>konsumsi_tinggi_kalori</th>\n",
       "      <th>konsumsi_sayuran</th>\n",
       "      <th>makan_berat</th>\n",
       "      <th>ngemil</th>\n",
       "      <th>merokok</th>\n",
       "      <th>konsumsi_air_liter</th>\n",
       "      <th>pemantauan_kalori</th>\n",
       "      <th>aktifitas_fisik</th>\n",
       "      <th>penggunaan_perangkat_teknologi</th>\n",
       "      <th>konsumsi_alkohol</th>\n",
       "      <th>transporasi_biasa_digunakan</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>138.000000</td>\n",
       "      <td>138.000000</td>\n",
       "      <td>138.000000</td>\n",
       "      <td>138.000000</td>\n",
       "      <td>138.000000</td>\n",
       "      <td>138.000000</td>\n",
       "      <td>138.000000</td>\n",
       "      <td>138.000000</td>\n",
       "      <td>138.000000</td>\n",
       "      <td>138.000000</td>\n",
       "      <td>138.000000</td>\n",
       "      <td>138.000000</td>\n",
       "      <td>138.000000</td>\n",
       "      <td>138.000000</td>\n",
       "      <td>138.000000</td>\n",
       "      <td>138.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>0.130435</td>\n",
       "      <td>20.115942</td>\n",
       "      <td>1.621892</td>\n",
       "      <td>46.065217</td>\n",
       "      <td>0.224638</td>\n",
       "      <td>0.644928</td>\n",
       "      <td>1.753623</td>\n",
       "      <td>1.891304</td>\n",
       "      <td>1.601449</td>\n",
       "      <td>0.007246</td>\n",
       "      <td>2.297101</td>\n",
       "      <td>0.072464</td>\n",
       "      <td>0.572464</td>\n",
       "      <td>1.021739</td>\n",
       "      <td>0.666667</td>\n",
       "      <td>1.021739</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>0.338008</td>\n",
       "      <td>3.582342</td>\n",
       "      <td>0.068071</td>\n",
       "      <td>3.765395</td>\n",
       "      <td>0.418864</td>\n",
       "      <td>0.480279</td>\n",
       "      <td>0.480444</td>\n",
       "      <td>0.751493</td>\n",
       "      <td>0.534091</td>\n",
       "      <td>0.085126</td>\n",
       "      <td>0.458646</td>\n",
       "      <td>0.260199</td>\n",
       "      <td>0.763087</td>\n",
       "      <td>0.146362</td>\n",
       "      <td>0.473122</td>\n",
       "      <td>0.307269</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>16.000000</td>\n",
       "      <td>1.520000</td>\n",
       "      <td>39.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>19.000000</td>\n",
       "      <td>1.560000</td>\n",
       "      <td>42.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>20.000000</td>\n",
       "      <td>1.627689</td>\n",
       "      <td>45.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>21.000000</td>\n",
       "      <td>1.690000</td>\n",
       "      <td>49.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>1.000000</td>\n",
       "      <td>39.000000</td>\n",
       "      <td>1.720000</td>\n",
       "      <td>53.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>4.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       jenis_kelamin        umur  tinggi_badan_meter  berat_badan_kilogram  \\\n",
       "count     138.000000  138.000000          138.000000            138.000000   \n",
       "mean        0.130435   20.115942            1.621892             46.065217   \n",
       "std         0.338008    3.582342            0.068071              3.765395   \n",
       "min         0.000000   16.000000            1.520000             39.000000   \n",
       "25%         0.000000   19.000000            1.560000             42.000000   \n",
       "50%         0.000000   20.000000            1.627689             45.000000   \n",
       "75%         0.000000   21.000000            1.690000             49.000000   \n",
       "max         1.000000   39.000000            1.720000             53.000000   \n",
       "\n",
       "       histori_keluarga_kelebihan_BB  konsumsi_tinggi_kalori  \\\n",
       "count                     138.000000              138.000000   \n",
       "mean                        0.224638                0.644928   \n",
       "std                         0.418864                0.480279   \n",
       "min                         0.000000                0.000000   \n",
       "25%                         0.000000                0.000000   \n",
       "50%                         0.000000                1.000000   \n",
       "75%                         0.000000                1.000000   \n",
       "max                         1.000000                1.000000   \n",
       "\n",
       "       konsumsi_sayuran  makan_berat      ngemil     merokok  \\\n",
       "count        138.000000   138.000000  138.000000  138.000000   \n",
       "mean           1.753623     1.891304    1.601449    0.007246   \n",
       "std            0.480444     0.751493    0.534091    0.085126   \n",
       "min            0.000000     1.000000    0.000000    0.000000   \n",
       "25%            2.000000     1.000000    1.000000    0.000000   \n",
       "50%            2.000000     2.000000    2.000000    0.000000   \n",
       "75%            2.000000     2.000000    2.000000    0.000000   \n",
       "max            2.000000     3.000000    2.000000    1.000000   \n",
       "\n",
       "       konsumsi_air_liter  pemantauan_kalori  aktifitas_fisik  \\\n",
       "count          138.000000         138.000000       138.000000   \n",
       "mean             2.297101           0.072464         0.572464   \n",
       "std              0.458646           0.260199         0.763087   \n",
       "min              2.000000           0.000000         0.000000   \n",
       "25%              2.000000           0.000000         0.000000   \n",
       "50%              2.000000           0.000000         0.000000   \n",
       "75%              3.000000           0.000000         1.000000   \n",
       "max              3.000000           1.000000         3.000000   \n",
       "\n",
       "       penggunaan_perangkat_teknologi  konsumsi_alkohol  \\\n",
       "count                      138.000000        138.000000   \n",
       "mean                         1.021739          0.666667   \n",
       "std                          0.146362          0.473122   \n",
       "min                          1.000000          0.000000   \n",
       "25%                          1.000000          0.000000   \n",
       "50%                          1.000000          1.000000   \n",
       "75%                          1.000000          1.000000   \n",
       "max                          2.000000          1.000000   \n",
       "\n",
       "       transporasi_biasa_digunakan  \n",
       "count                   138.000000  \n",
       "mean                      1.021739  \n",
       "std                       0.307269  \n",
       "min                       0.000000  \n",
       "25%                       1.000000  \n",
       "50%                       1.000000  \n",
       "75%                       1.000000  \n",
       "max                       4.000000  "
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_pilih_kelas.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "2ea6072d",
   "metadata": {},
   "outputs": [],
   "source": [
    "# excel_file = pd.ExcelWriter(\"smote_training_data_obesitas_hitung.xlsx\")\n",
    "# X_trainhitung.to_excel(excel_file)\n",
    "# excel_file.save()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "e65f7d5f",
   "metadata": {},
   "outputs": [],
   "source": [
    "# excel_file = pd.ExcelWriter(\"smote_testing_data_obesitas_hitung.xlsx\")\n",
    "# X_testhitung.to_excel(excel_file)\n",
    "# excel_file.save()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e0c29730",
   "metadata": {},
   "source": [
    "## Membagi atribut"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "717762ac",
   "metadata": {},
   "outputs": [],
   "source": [
    "X = data.drop(columns='kelas_obesitas', axis = 1)\n",
    "Y = data['kelas_obesitas']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "3bf47956",
   "metadata": {},
   "outputs": [],
   "source": [
    "X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size = test_size, stratify = Y, random_state = 0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "7249aede",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(baris,kolom)\n",
      "\n",
      "Jumlah data keseluruhan: (705, 16) \n",
      "Jumlah data training atau latih: (690, 16) \n",
      "Jumlah data test atau uji: (15, 16)\n"
     ]
    }
   ],
   "source": [
    "print('(baris,kolom)\\n')\n",
    "print('Jumlah data keseluruhan:', X.shape, '\\nJumlah data training atau latih:', X_train.shape, '\\nJumlah data test atau uji:', X_test.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "d91acd11",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "obesitas_I               3\n",
       "normal                   3\n",
       "obesitas_II              3\n",
       "berat_badan_kurang       3\n",
       "kelebihan_berat_badan    3\n",
       "Name: kelas_obesitas, dtype: int64"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Y_test.value_counts()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d217a77b",
   "metadata": {},
   "source": [
    "# Normalisasi"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "a2e28cc7",
   "metadata": {},
   "outputs": [],
   "source": [
    "minmax = MinMaxScaler()\n",
    "minmax.fit(X_train)\n",
    "X_train_nomalisasi = minmax.transform(X_train)\n",
    "X_test_nomalisasi = minmax.transform(X_test)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d149c423",
   "metadata": {},
   "source": [
    "# Model"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "18c55b9a",
   "metadata": {},
   "source": [
    "## naive bayes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "0a8d5b62",
   "metadata": {},
   "outputs": [],
   "source": [
    "klasifikasiNV = GaussianNB()\n",
    "start_time_NV = time.time()\n",
    "klasifikasiNV.fit(X_train_nomalisasi, Y_train)\n",
    "training_end_time_NV = time.time()\n",
    "Y_predictNV = klasifikasiNV.predict(X_test_nomalisasi)\n",
    "end_time_NV = time.time()\n",
    "prediction_end_time_NV = time.time()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "ec0a6b15",
   "metadata": {},
   "outputs": [],
   "source": [
    "training_execution_time_NV = training_end_time_NV - start_time_NV\n",
    "prediction_execution_time_NV = prediction_end_time_NV - training_end_time_NV\n",
    "execution_time_NV1 = prediction_end_time_NV - start_time_NV\n",
    "execution_time_NV2 = end_time_NV - start_time_NV"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "f26dc8fd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Waktu awal eksekusi Naive Bayes: 1716907414.27698 detik\n",
      "Waktu akhir eksekusi Naive Bayes: 1716907414.289759 detik\n",
      "Waktu pelatihan Naive Bayes: 0.010759830474853516 detik\n",
      "Waktu uji Naive Bayes: 0.002019166946411133 detik\n",
      "Total waktu eksekusi Naive Bayes: 0.012778997421264648 detik\n",
      "Total waktu eksekusi Naive Bayes: 0.012778997421264648 detik\n"
     ]
    }
   ],
   "source": [
    "print(f\"Waktu awal eksekusi Naive Bayes: {start_time_NV} detik\")\n",
    "print(f\"Waktu akhir eksekusi Naive Bayes: {end_time_NV} detik\")\n",
    "print(f\"Waktu pelatihan Naive Bayes: {training_execution_time_NV} detik\")\n",
    "print(f\"Waktu uji Naive Bayes: {prediction_execution_time_NV} detik\")\n",
    "print(f\"Total waktu eksekusi Naive Bayes: {execution_time_NV1} detik\")\n",
    "print(f\"Total waktu eksekusi Naive Bayes: {execution_time_NV2} detik\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "a262d7b6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                       precision    recall  f1-score   support\n",
      "\n",
      "   berat_badan_kurang       0.75      1.00      0.86         3\n",
      "kelebihan_berat_badan       0.50      0.33      0.40         3\n",
      "               normal       0.50      0.33      0.40         3\n",
      "           obesitas_I       1.00      0.33      0.50         3\n",
      "          obesitas_II       0.50      1.00      0.67         3\n",
      "\n",
      "             accuracy                           0.60        15\n",
      "            macro avg       0.65      0.60      0.56        15\n",
      "         weighted avg       0.65      0.60      0.56        15\n",
      "\n"
     ]
    }
   ],
   "source": [
    "evaluasiNV = classification_report(Y_test, Y_predictNV)\n",
    "print(evaluasiNV)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "b187e3f0",
   "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>berat_badan_kurang</th>\n",
       "      <th>normal</th>\n",
       "      <th>kelebihan_berat_badan</th>\n",
       "      <th>obesitas_I</th>\n",
       "      <th>obesitas_II</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>berat_badan_kurang</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>normal</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>kelebihan_berat_badan</th>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>obesitas_I</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>obesitas_II</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                       berat_badan_kurang  normal  kelebihan_berat_badan  \\\n",
       "berat_badan_kurang                      3       0                      0   \n",
       "normal                                  1       1                      1   \n",
       "kelebihan_berat_badan                   0       1                      1   \n",
       "obesitas_I                              0       0                      0   \n",
       "obesitas_II                             0       0                      0   \n",
       "\n",
       "                       obesitas_I  obesitas_II  \n",
       "berat_badan_kurang              0            0  \n",
       "normal                          0            0  \n",
       "kelebihan_berat_badan           0            1  \n",
       "obesitas_I                      1            2  \n",
       "obesitas_II                     0            3  "
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "label_unikNV = np.unique(np.concatenate((Y_test, Y_predictNV)))\n",
    "\n",
    "# Membuat matriks kebingungan dengan label\n",
    "matrixNV = confusion_matrix(Y_test, Y_predictNV, labels=label_unikNV)\n",
    "\n",
    "# Membuat DataFrame dari matriks kebingungan\n",
    "dataframe_CM_NV = pd.DataFrame(matrixNV, index=label_unikNV, columns=label_unikNV)\n",
    "\n",
    "# Mengatur urutan baru\n",
    "urutan_baru = ['berat_badan_kurang', 'normal', 'kelebihan_berat_badan', 'obesitas_I', 'obesitas_II']\n",
    "\n",
    "# Menyusun ulang matriks dan DataFrame sesuai urutan baru\n",
    "matrixNV_baru = dataframe_CM_NV.reindex(index=urutan_baru, columns=urutan_baru)\n",
    "matrixNV_baru"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "16c10f86",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 59200 characters]",
      "text/plain": [
       "<Figure size 800x600 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "sns.set(font_scale=1)\n",
    "plt.figure(figsize=(8, 6))\n",
    "heatmap = sns.heatmap(matrixNV_baru, annot=True, fmt=\"d\", cmap=\"Greens\", xticklabels=urutan_baru, yticklabels=urutan_baru)\n",
    "heatmap.set_xlabel(\"Predicted Label\")\n",
    "heatmap.set_ylabel(\"True Label\")\n",
    "plt.xticks(rotation=20, ha='right')\n",
    "heatmap.set_title(\"Confusion Matrix Heatmap\")\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "61576256",
   "metadata": {},
   "source": [
    "## KNN"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "id": "5a7945b4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "nilai K: 3 , memiliki akurasi 0.7814285714285714\n",
      "nilai K: 4 , memiliki akurasi 0.85\n",
      "nilai K: 5 , memiliki akurasi 0.85\n",
      "nilai K: 6 , memiliki akurasi 0.9314285714285715\n",
      "nilai K: 7 , memiliki akurasi 1.0\n",
      "nilai K: 8 , memiliki akurasi 0.85\n",
      "nilai K: 9 , memiliki akurasi 1.0\n",
      "nilai K: 10 , memiliki akurasi 1.0\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 93788 characters]",
      "text/plain": [
       "<Figure size 1200x600 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "k_values = []\n",
    "accuracy_values = []\n",
    "precision_values = []\n",
    "recall_values = []\n",
    "f1_score_values = []\n",
    "sns.set_style(\"whitegrid\")\n",
    "for k in range(3,11):\n",
    "    klasifikasiKNN = KNeighborsClassifier(n_neighbors = k)\n",
    "    klasifikasiKNN.fit(X_train_nomalisasi, Y_train)\n",
    "    Y_predictKNN = klasifikasiKNN.predict(X_test_nomalisasi)\n",
    "    akurasi = accuracy_score(Y_test, Y_predictKNN)\n",
    "    presisi = precision_score(Y_test, Y_predictKNN, average='macro')\n",
    "    recal = recall_score(Y_test, Y_predictKNN, average='macro')\n",
    "    F1 = f1_score(Y_test, Y_predictKNN, average='macro')\n",
    "    k =+ k\n",
    "    k_values.append(k)\n",
    "    accuracy_values.append(akurasi)\n",
    "    precision_values.append(presisi)\n",
    "    recall_values.append(recal)\n",
    "    f1_score_values.append(F1)\n",
    "    print('nilai K:',k, ', memiliki akurasi', F1)\n",
    "    \n",
    "plt.figure(figsize=(12, 6))\n",
    "plt.plot(k_values, accuracy_values, marker='o', markersize=4, linestyle='-', color='#E81416', label='Akurasi')\n",
    "plt.plot(k_values, precision_values, marker='o', markersize=4, linestyle='-', color='#FFA500', label='Presisi')\n",
    "plt.plot(k_values, recall_values, marker='o', markersize=4, linestyle='-', color='#FAEB36', label='Recal')\n",
    "plt.plot(k_values, f1_score_values, marker='o', markersize=4, linestyle='-', color='#79C314', label='Skor F1')\n",
    "\n",
    "plt.title('Hasil Kinerja K-Nearest Neighbor terhadap Nilai K untuk Rasio Data 690:15')\n",
    "plt.xlabel('Nilai K')\n",
    "plt.ylabel('Nilai Kinerja')\n",
    "plt.xticks(k_values)\n",
    "plt.grid(True, alpha=0.4)\n",
    "plt.legend()\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "id": "ac8fa753",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "nilai K: 3 , memiliki train 0.003000020980834961\n",
      "nilai K: 3 , memiliki test 0.003999233245849609\n",
      "nilai K: 4 , memiliki train 0.0010941028594970703\n",
      "nilai K: 4 , memiliki test 0.005003929138183594\n",
      "nilai K: 5 , memiliki train 0.0010006427764892578\n",
      "nilai K: 5 , memiliki test 0.004024028778076172\n",
      "nilai K: 6 , memiliki train 0.0010004043579101562\n",
      "nilai K: 6 , memiliki test 0.0045354366302490234\n",
      "nilai K: 7 , memiliki train 0.0009982585906982422\n",
      "nilai K: 7 , memiliki test 0.0049285888671875\n",
      "nilai K: 8 , memiliki train 0.0009999275207519531\n",
      "nilai K: 8 , memiliki test 0.006462812423706055\n",
      "nilai K: 9 , memiliki train 0.0009999275207519531\n",
      "nilai K: 9 , memiliki test 0.004084348678588867\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 62960 characters]",
      "text/plain": [
       "<Figure size 1200x600 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "k_values = []\n",
    "train_values = []\n",
    "test_values = []\n",
    "\n",
    "sns.set_style(\"whitegrid\")\n",
    "\n",
    "for k in range(3,10):\n",
    "    klasifikasiKNN = KNeighborsClassifier(n_neighbors = k)\n",
    "    start_time_KNN = time.time()\n",
    "    klasifikasiKNN.fit(X_train_nomalisasi, Y_train)\n",
    "    training_end_time_KNN = time.time()\n",
    "    Y_predictKNN = klasifikasiKNN.predict(X_test_nomalisasi)\n",
    "    prediction_end_time_KNN = time.time()\n",
    "\n",
    "    train = training_end_time_KNN - start_time_KNN\n",
    "    test = prediction_end_time_KNN - training_end_time_KNN\n",
    "    \n",
    "    k =+ k\n",
    "    k_values.append(k)\n",
    "    train_values.append(train)\n",
    "    test_values.append(test)\n",
    "    print('nilai K:',k, ', memiliki train', train)\n",
    "    print('nilai K:',k, ', memiliki test', test)\n",
    "    \n",
    "plt.figure(figsize=(12, 6))\n",
    "plt.plot(k_values, train_values, marker='o', markersize=4, linestyle='-', color='#487DE7', label='Waktu Pelatihan')\n",
    "plt.plot(k_values, test_values, marker='o', markersize=4, linestyle='-', color='#70369D', label='Waktu Pengujian')\n",
    "\n",
    "\n",
    "plt.title('Hasil Kinerja K-Nearest Neighbor terhadap Nilai K')\n",
    "plt.xlabel('Nilai K')\n",
    "plt.ylabel('Waktu')\n",
    "plt.xticks(k_values)\n",
    "plt.grid(True, alpha=0.4)\n",
    "plt.legend()\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "4bb61323",
   "metadata": {},
   "outputs": [],
   "source": [
    "klasifikasiKNN = KNeighborsClassifier(n_neighbors = 7)\n",
    "start_time_KNN = time.time()\n",
    "klasifikasiKNN.fit(X_train_nomalisasi, Y_train)\n",
    "training_end_time_KNN = time.time()\n",
    "Y_predictKNN = klasifikasiKNN.predict(X_test_nomalisasi)\n",
    "end_time_KNN = time.time()\n",
    "prediction_end_time_KNN = time.time()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "aeaf9149",
   "metadata": {},
   "outputs": [],
   "source": [
    "training_execution_time_KNN = training_end_time_KNN - start_time_KNN\n",
    "prediction_execution_time_KNN = prediction_end_time_KNN - training_end_time_KNN\n",
    "execution_time_KNN1 = prediction_end_time_KNN - start_time_KNN\n",
    "execution_time_KNN2 = end_time_KNN - start_time_KNN"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "b23d1b1e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Waktu awal eksekusi KNN: 1716907418.1831193 detik\n",
      "Waktu akhir eksekusi KNN: 1716907418.2024572 detik\n",
      "Waktu pelatihan KNN: 0.004010677337646484 detik\n",
      "Waktu uji KNN: 0.015327215194702148 detik\n",
      "Total waktu eksekusi KNN: 0.019337892532348633 detik\n",
      "Total waktu eksekusi KNN: 0.019337892532348633 detik\n"
     ]
    }
   ],
   "source": [
    "print(f\"Waktu awal eksekusi KNN: {start_time_KNN} detik\")\n",
    "print(f\"Waktu akhir eksekusi KNN: {end_time_KNN} detik\")\n",
    "print(f\"Waktu pelatihan KNN: {training_execution_time_KNN} detik\")\n",
    "print(f\"Waktu uji KNN: {prediction_execution_time_KNN} detik\")\n",
    "print(f\"Total waktu eksekusi KNN: {execution_time_KNN1} detik\")\n",
    "print(f\"Total waktu eksekusi KNN: {execution_time_KNN2} detik\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "1353c77e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                       precision    recall  f1-score   support\n",
      "\n",
      "   berat_badan_kurang       1.00      1.00      1.00         3\n",
      "kelebihan_berat_badan       1.00      1.00      1.00         3\n",
      "               normal       1.00      1.00      1.00         3\n",
      "           obesitas_I       1.00      1.00      1.00         3\n",
      "          obesitas_II       1.00      1.00      1.00         3\n",
      "\n",
      "             accuracy                           1.00        15\n",
      "            macro avg       1.00      1.00      1.00        15\n",
      "         weighted avg       1.00      1.00      1.00        15\n",
      "\n"
     ]
    }
   ],
   "source": [
    "evaluasiKNN = classification_report(Y_test, Y_predictKNN)\n",
    "print(evaluasiKNN)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "abdc93b9",
   "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>berat_badan_kurang</th>\n",
       "      <th>normal</th>\n",
       "      <th>kelebihan_berat_badan</th>\n",
       "      <th>obesitas_I</th>\n",
       "      <th>obesitas_II</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>berat_badan_kurang</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>normal</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>kelebihan_berat_badan</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>obesitas_I</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>obesitas_II</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                       berat_badan_kurang  normal  kelebihan_berat_badan  \\\n",
       "berat_badan_kurang                      3       0                      0   \n",
       "normal                                  0       3                      0   \n",
       "kelebihan_berat_badan                   0       0                      3   \n",
       "obesitas_I                              0       0                      0   \n",
       "obesitas_II                             0       0                      0   \n",
       "\n",
       "                       obesitas_I  obesitas_II  \n",
       "berat_badan_kurang              0            0  \n",
       "normal                          0            0  \n",
       "kelebihan_berat_badan           0            0  \n",
       "obesitas_I                      3            0  \n",
       "obesitas_II                     0            3  "
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "label_unikKNN = np.unique(np.concatenate((Y_test, Y_predictKNN)))\n",
    "\n",
    "# Membuat matriks kebingungan dengan label\n",
    "matrixKNN = confusion_matrix(Y_test, Y_predictKNN, labels=label_unikKNN)\n",
    "\n",
    "# Membuat DataFrame dari matriks kebingungan\n",
    "dataframe_CM_KNN = pd.DataFrame(matrixKNN, index=label_unikKNN, columns=label_unikKNN)\n",
    "\n",
    "# Menyusun ulang matriks dan DataFrame sesuai urutan baru\n",
    "matrixKNN_baru = dataframe_CM_KNN.reindex(index=urutan_baru, columns=urutan_baru)\n",
    "matrixKNN_baru"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "c72c9b04",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 59872 characters]",
      "text/plain": [
       "<Figure size 800x600 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "sns.set(font_scale=1)\n",
    "plt.figure(figsize=(8, 6))\n",
    "heatmap = sns.heatmap(matrixKNN_baru, annot=True, fmt=\"d\", cmap=\"Blues\", xticklabels=urutan_baru, yticklabels=urutan_baru)\n",
    "heatmap.set_xlabel(\"Predicted Label\")\n",
    "heatmap.set_ylabel(\"True Label\")\n",
    "plt.xticks(rotation=20, ha='right')\n",
    "heatmap.set_title(\"Confusion Matrix Heatmap\")\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d417353b",
   "metadata": {},
   "source": [
    "## Data hasil klasifikasi dari naive bayes dan knn"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "58c9135d",
   "metadata": {},
   "outputs": [],
   "source": [
    "dataNV = X_testbaru.copy()\n",
    "dataKNN = X_testbaru.copy()\n",
    "data_NV_KNN = X_testbaru.copy()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "fdf4e4a3",
   "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>jenis_kelamin</th>\n",
       "      <th>umur</th>\n",
       "      <th>tinggi_badan_meter</th>\n",
       "      <th>berat_badan_kilogram</th>\n",
       "      <th>histori_keluarga_kelebihan_BB</th>\n",
       "      <th>konsumsi_tinggi_kalori</th>\n",
       "      <th>konsumsi_sayuran</th>\n",
       "      <th>makan_berat</th>\n",
       "      <th>ngemil</th>\n",
       "      <th>merokok</th>\n",
       "      <th>konsumsi_air_liter</th>\n",
       "      <th>pemantauan_kalori</th>\n",
       "      <th>aktifitas_fisik</th>\n",
       "      <th>penggunaan_perangkat_teknologi</th>\n",
       "      <th>konsumsi_alkohol</th>\n",
       "      <th>transporasi_biasa_digunakan</th>\n",
       "      <th>kelas_obesitas</th>\n",
       "      <th>klasifikasi_naive_bayes</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>606</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>31</td>\n",
       "      <td>1.672625</td>\n",
       "      <td>71</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>3x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Jalan kaki</td>\n",
       "      <td>obesitas_I</td>\n",
       "      <td>obesitas_II</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>71</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>19</td>\n",
       "      <td>1.650000</td>\n",
       "      <td>56</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Selalu</td>\n",
       "      <td>3x</td>\n",
       "      <td>Sering</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Lebih 2 liter</td>\n",
       "      <td>Ya</td>\n",
       "      <td>1-2 hari</td>\n",
       "      <td>3-5 jam</td>\n",
       "      <td>Sering</td>\n",
       "      <td>Sepeda motor</td>\n",
       "      <td>normal</td>\n",
       "      <td>normal</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>609</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>39</td>\n",
       "      <td>1.711621</td>\n",
       "      <td>84</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Selalu</td>\n",
       "      <td>1-2x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Lebih 2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>Jalan kaki</td>\n",
       "      <td>obesitas_I</td>\n",
       "      <td>obesitas_I</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>678</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>37</td>\n",
       "      <td>1.560000</td>\n",
       "      <td>79</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>3x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Jalan kaki</td>\n",
       "      <td>obesitas_II</td>\n",
       "      <td>obesitas_II</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>644</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>39</td>\n",
       "      <td>1.528746</td>\n",
       "      <td>79</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>3x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Jalan kaki</td>\n",
       "      <td>obesitas_II</td>\n",
       "      <td>obesitas_II</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>275</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>20</td>\n",
       "      <td>1.550000</td>\n",
       "      <td>41</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Selalu</td>\n",
       "      <td>1-2x</td>\n",
       "      <td>Sering</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Sepeda motor</td>\n",
       "      <td>berat_badan_kurang</td>\n",
       "      <td>berat_badan_kurang</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>173</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>21</td>\n",
       "      <td>1.540000</td>\n",
       "      <td>47</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Selalu</td>\n",
       "      <td>3x</td>\n",
       "      <td>Selalu</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>2-4 hari</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>Sepeda motor</td>\n",
       "      <td>normal</td>\n",
       "      <td>berat_badan_kurang</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>510</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>25</td>\n",
       "      <td>1.643548</td>\n",
       "      <td>62</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>3x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 hari</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>Mobil</td>\n",
       "      <td>kelebihan_berat_badan</td>\n",
       "      <td>kelebihan_berat_badan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>548</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>21</td>\n",
       "      <td>1.641347</td>\n",
       "      <td>66</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Selalu</td>\n",
       "      <td>1-2x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>Sepeda motor</td>\n",
       "      <td>kelebihan_berat_badan</td>\n",
       "      <td>obesitas_II</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>389</th>\n",
       "      <td>Laki-laki</td>\n",
       "      <td>39</td>\n",
       "      <td>1.720000</td>\n",
       "      <td>86</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Selalu</td>\n",
       "      <td>1-2x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>Jalan kaki</td>\n",
       "      <td>obesitas_I</td>\n",
       "      <td>obesitas_II</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>394</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>37</td>\n",
       "      <td>1.560000</td>\n",
       "      <td>77</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>3x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Jalan kaki</td>\n",
       "      <td>obesitas_II</td>\n",
       "      <td>obesitas_II</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>206</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>18</td>\n",
       "      <td>1.640000</td>\n",
       "      <td>59</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>3x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 hari</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Sepeda motor</td>\n",
       "      <td>normal</td>\n",
       "      <td>kelebihan_berat_badan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>295</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>19</td>\n",
       "      <td>1.680000</td>\n",
       "      <td>49</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Selalu</td>\n",
       "      <td>3x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 hari</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Sepeda motor</td>\n",
       "      <td>berat_badan_kurang</td>\n",
       "      <td>berat_badan_kurang</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>480</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>21</td>\n",
       "      <td>1.694749</td>\n",
       "      <td>49</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Selalu</td>\n",
       "      <td>3x</td>\n",
       "      <td>Sering</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>Sepeda motor</td>\n",
       "      <td>berat_badan_kurang</td>\n",
       "      <td>berat_badan_kurang</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>124</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>20</td>\n",
       "      <td>1.630000</td>\n",
       "      <td>64</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>3x</td>\n",
       "      <td>Selalu</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>3-5 jam</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>Jalan kaki</td>\n",
       "      <td>kelebihan_berat_badan</td>\n",
       "      <td>normal</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    jenis_kelamin  umur  tinggi_badan_meter  berat_badan_kilogram  \\\n",
       "606     Perempuan    31            1.672625                    71   \n",
       "71      Perempuan    19            1.650000                    56   \n",
       "609     Perempuan    39            1.711621                    84   \n",
       "678     Perempuan    37            1.560000                    79   \n",
       "644     Perempuan    39            1.528746                    79   \n",
       "275     Perempuan    20            1.550000                    41   \n",
       "173     Perempuan    21            1.540000                    47   \n",
       "510     Perempuan    25            1.643548                    62   \n",
       "548     Perempuan    21            1.641347                    66   \n",
       "389     Laki-laki    39            1.720000                    86   \n",
       "394     Perempuan    37            1.560000                    77   \n",
       "206     Perempuan    18            1.640000                    59   \n",
       "295     Perempuan    19            1.680000                    49   \n",
       "480     Perempuan    21            1.694749                    49   \n",
       "124     Perempuan    20            1.630000                    64   \n",
       "\n",
       "    histori_keluarga_kelebihan_BB konsumsi_tinggi_kalori konsumsi_sayuran  \\\n",
       "606                            Ya                     Ya    Kadang-kadang   \n",
       "71                             Ya                     Ya           Selalu   \n",
       "609                         Tidak                     Ya           Selalu   \n",
       "678                            Ya                     Ya    Kadang-kadang   \n",
       "644                            Ya                     Ya    Kadang-kadang   \n",
       "275                         Tidak                     Ya           Selalu   \n",
       "173                            Ya                  Tidak           Selalu   \n",
       "510                         Tidak                  Tidak    Kadang-kadang   \n",
       "548                            Ya                     Ya           Selalu   \n",
       "389                            Ya                     Ya           Selalu   \n",
       "394                            Ya                     Ya    Kadang-kadang   \n",
       "206                            Ya                     Ya    Kadang-kadang   \n",
       "295                         Tidak                  Tidak           Selalu   \n",
       "480                            Ya                     Ya           Selalu   \n",
       "124                            Ya                     Ya     Tidak pernah   \n",
       "\n",
       "    makan_berat         ngemil merokok konsumsi_air_liter pemantauan_kalori  \\\n",
       "606          3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "71           3x         Sering      Ya      Lebih 2 liter                Ya   \n",
       "609        1-2x  Kadang-kadang   Tidak      Lebih 2 liter             Tidak   \n",
       "678          3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "644          3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "275        1-2x         Sering   Tidak          1-2 liter             Tidak   \n",
       "173          3x         Selalu   Tidak          1-2 liter             Tidak   \n",
       "510          3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "548        1-2x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "389        1-2x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "394          3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "206          3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "295          3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "480          3x         Sering   Tidak          1-2 liter             Tidak   \n",
       "124          3x         Selalu   Tidak          1-2 liter             Tidak   \n",
       "\n",
       "    aktifitas_fisik penggunaan_perangkat_teknologi konsumsi_alkohol  \\\n",
       "606    Tidak pernah                        0-2 jam    Kadang-kadang   \n",
       "71         1-2 hari                        3-5 jam           Sering   \n",
       "609    Tidak pernah                        0-2 jam     Tidak pernah   \n",
       "678    Tidak pernah                        0-2 jam    Kadang-kadang   \n",
       "644    Tidak pernah                        0-2 jam    Kadang-kadang   \n",
       "275    Tidak pernah                        0-2 jam    Kadang-kadang   \n",
       "173        2-4 hari                        0-2 jam     Tidak pernah   \n",
       "510        1-2 hari                        0-2 jam     Tidak pernah   \n",
       "548    Tidak pernah                        0-2 jam     Tidak pernah   \n",
       "389    Tidak pernah                        0-2 jam     Tidak pernah   \n",
       "394    Tidak pernah                        0-2 jam    Kadang-kadang   \n",
       "206        1-2 hari                        0-2 jam    Kadang-kadang   \n",
       "295        1-2 hari                        0-2 jam    Kadang-kadang   \n",
       "480    Tidak pernah                        0-2 jam     Tidak pernah   \n",
       "124    Tidak pernah                        3-5 jam     Tidak pernah   \n",
       "\n",
       "    transporasi_biasa_digunakan         kelas_obesitas klasifikasi_naive_bayes  \n",
       "606                  Jalan kaki             obesitas_I             obesitas_II  \n",
       "71                 Sepeda motor                 normal                  normal  \n",
       "609                  Jalan kaki             obesitas_I              obesitas_I  \n",
       "678                  Jalan kaki            obesitas_II             obesitas_II  \n",
       "644                  Jalan kaki            obesitas_II             obesitas_II  \n",
       "275                Sepeda motor     berat_badan_kurang      berat_badan_kurang  \n",
       "173                Sepeda motor                 normal      berat_badan_kurang  \n",
       "510                       Mobil  kelebihan_berat_badan   kelebihan_berat_badan  \n",
       "548                Sepeda motor  kelebihan_berat_badan             obesitas_II  \n",
       "389                  Jalan kaki             obesitas_I             obesitas_II  \n",
       "394                  Jalan kaki            obesitas_II             obesitas_II  \n",
       "206                Sepeda motor                 normal   kelebihan_berat_badan  \n",
       "295                Sepeda motor     berat_badan_kurang      berat_badan_kurang  \n",
       "480                Sepeda motor     berat_badan_kurang      berat_badan_kurang  \n",
       "124                  Jalan kaki  kelebihan_berat_badan                  normal  "
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dataNV['klasifikasi_naive_bayes'] = Y_predictNV\n",
    "dataNV"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "c37a4704",
   "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>jenis_kelamin</th>\n",
       "      <th>umur</th>\n",
       "      <th>tinggi_badan_meter</th>\n",
       "      <th>berat_badan_kilogram</th>\n",
       "      <th>histori_keluarga_kelebihan_BB</th>\n",
       "      <th>konsumsi_tinggi_kalori</th>\n",
       "      <th>konsumsi_sayuran</th>\n",
       "      <th>makan_berat</th>\n",
       "      <th>ngemil</th>\n",
       "      <th>merokok</th>\n",
       "      <th>konsumsi_air_liter</th>\n",
       "      <th>pemantauan_kalori</th>\n",
       "      <th>aktifitas_fisik</th>\n",
       "      <th>penggunaan_perangkat_teknologi</th>\n",
       "      <th>konsumsi_alkohol</th>\n",
       "      <th>transporasi_biasa_digunakan</th>\n",
       "      <th>kelas_obesitas</th>\n",
       "      <th>klasifikasi_k_nearest_neighbor</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>606</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>31</td>\n",
       "      <td>1.672625</td>\n",
       "      <td>71</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>3x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Jalan kaki</td>\n",
       "      <td>obesitas_I</td>\n",
       "      <td>obesitas_I</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>71</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>19</td>\n",
       "      <td>1.650000</td>\n",
       "      <td>56</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Selalu</td>\n",
       "      <td>3x</td>\n",
       "      <td>Sering</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Lebih 2 liter</td>\n",
       "      <td>Ya</td>\n",
       "      <td>1-2 hari</td>\n",
       "      <td>3-5 jam</td>\n",
       "      <td>Sering</td>\n",
       "      <td>Sepeda motor</td>\n",
       "      <td>normal</td>\n",
       "      <td>normal</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>609</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>39</td>\n",
       "      <td>1.711621</td>\n",
       "      <td>84</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Selalu</td>\n",
       "      <td>1-2x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Lebih 2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>Jalan kaki</td>\n",
       "      <td>obesitas_I</td>\n",
       "      <td>obesitas_I</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>678</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>37</td>\n",
       "      <td>1.560000</td>\n",
       "      <td>79</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>3x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Jalan kaki</td>\n",
       "      <td>obesitas_II</td>\n",
       "      <td>obesitas_II</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>644</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>39</td>\n",
       "      <td>1.528746</td>\n",
       "      <td>79</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>3x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Jalan kaki</td>\n",
       "      <td>obesitas_II</td>\n",
       "      <td>obesitas_II</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>275</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>20</td>\n",
       "      <td>1.550000</td>\n",
       "      <td>41</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Selalu</td>\n",
       "      <td>1-2x</td>\n",
       "      <td>Sering</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Sepeda motor</td>\n",
       "      <td>berat_badan_kurang</td>\n",
       "      <td>berat_badan_kurang</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>173</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>21</td>\n",
       "      <td>1.540000</td>\n",
       "      <td>47</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Selalu</td>\n",
       "      <td>3x</td>\n",
       "      <td>Selalu</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>2-4 hari</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>Sepeda motor</td>\n",
       "      <td>normal</td>\n",
       "      <td>normal</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>510</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>25</td>\n",
       "      <td>1.643548</td>\n",
       "      <td>62</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>3x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 hari</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>Mobil</td>\n",
       "      <td>kelebihan_berat_badan</td>\n",
       "      <td>kelebihan_berat_badan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>548</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>21</td>\n",
       "      <td>1.641347</td>\n",
       "      <td>66</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Selalu</td>\n",
       "      <td>1-2x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>Sepeda motor</td>\n",
       "      <td>kelebihan_berat_badan</td>\n",
       "      <td>kelebihan_berat_badan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>389</th>\n",
       "      <td>Laki-laki</td>\n",
       "      <td>39</td>\n",
       "      <td>1.720000</td>\n",
       "      <td>86</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Selalu</td>\n",
       "      <td>1-2x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>Jalan kaki</td>\n",
       "      <td>obesitas_I</td>\n",
       "      <td>obesitas_I</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>394</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>37</td>\n",
       "      <td>1.560000</td>\n",
       "      <td>77</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>3x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Jalan kaki</td>\n",
       "      <td>obesitas_II</td>\n",
       "      <td>obesitas_II</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>206</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>18</td>\n",
       "      <td>1.640000</td>\n",
       "      <td>59</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>3x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 hari</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Sepeda motor</td>\n",
       "      <td>normal</td>\n",
       "      <td>normal</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>295</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>19</td>\n",
       "      <td>1.680000</td>\n",
       "      <td>49</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Selalu</td>\n",
       "      <td>3x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 hari</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Sepeda motor</td>\n",
       "      <td>berat_badan_kurang</td>\n",
       "      <td>berat_badan_kurang</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>480</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>21</td>\n",
       "      <td>1.694749</td>\n",
       "      <td>49</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Selalu</td>\n",
       "      <td>3x</td>\n",
       "      <td>Sering</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>Sepeda motor</td>\n",
       "      <td>berat_badan_kurang</td>\n",
       "      <td>berat_badan_kurang</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>124</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>20</td>\n",
       "      <td>1.630000</td>\n",
       "      <td>64</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>3x</td>\n",
       "      <td>Selalu</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>3-5 jam</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>Jalan kaki</td>\n",
       "      <td>kelebihan_berat_badan</td>\n",
       "      <td>kelebihan_berat_badan</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    jenis_kelamin  umur  tinggi_badan_meter  berat_badan_kilogram  \\\n",
       "606     Perempuan    31            1.672625                    71   \n",
       "71      Perempuan    19            1.650000                    56   \n",
       "609     Perempuan    39            1.711621                    84   \n",
       "678     Perempuan    37            1.560000                    79   \n",
       "644     Perempuan    39            1.528746                    79   \n",
       "275     Perempuan    20            1.550000                    41   \n",
       "173     Perempuan    21            1.540000                    47   \n",
       "510     Perempuan    25            1.643548                    62   \n",
       "548     Perempuan    21            1.641347                    66   \n",
       "389     Laki-laki    39            1.720000                    86   \n",
       "394     Perempuan    37            1.560000                    77   \n",
       "206     Perempuan    18            1.640000                    59   \n",
       "295     Perempuan    19            1.680000                    49   \n",
       "480     Perempuan    21            1.694749                    49   \n",
       "124     Perempuan    20            1.630000                    64   \n",
       "\n",
       "    histori_keluarga_kelebihan_BB konsumsi_tinggi_kalori konsumsi_sayuran  \\\n",
       "606                            Ya                     Ya    Kadang-kadang   \n",
       "71                             Ya                     Ya           Selalu   \n",
       "609                         Tidak                     Ya           Selalu   \n",
       "678                            Ya                     Ya    Kadang-kadang   \n",
       "644                            Ya                     Ya    Kadang-kadang   \n",
       "275                         Tidak                     Ya           Selalu   \n",
       "173                            Ya                  Tidak           Selalu   \n",
       "510                         Tidak                  Tidak    Kadang-kadang   \n",
       "548                            Ya                     Ya           Selalu   \n",
       "389                            Ya                     Ya           Selalu   \n",
       "394                            Ya                     Ya    Kadang-kadang   \n",
       "206                            Ya                     Ya    Kadang-kadang   \n",
       "295                         Tidak                  Tidak           Selalu   \n",
       "480                            Ya                     Ya           Selalu   \n",
       "124                            Ya                     Ya     Tidak pernah   \n",
       "\n",
       "    makan_berat         ngemil merokok konsumsi_air_liter pemantauan_kalori  \\\n",
       "606          3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "71           3x         Sering      Ya      Lebih 2 liter                Ya   \n",
       "609        1-2x  Kadang-kadang   Tidak      Lebih 2 liter             Tidak   \n",
       "678          3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "644          3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "275        1-2x         Sering   Tidak          1-2 liter             Tidak   \n",
       "173          3x         Selalu   Tidak          1-2 liter             Tidak   \n",
       "510          3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "548        1-2x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "389        1-2x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "394          3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "206          3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "295          3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "480          3x         Sering   Tidak          1-2 liter             Tidak   \n",
       "124          3x         Selalu   Tidak          1-2 liter             Tidak   \n",
       "\n",
       "    aktifitas_fisik penggunaan_perangkat_teknologi konsumsi_alkohol  \\\n",
       "606    Tidak pernah                        0-2 jam    Kadang-kadang   \n",
       "71         1-2 hari                        3-5 jam           Sering   \n",
       "609    Tidak pernah                        0-2 jam     Tidak pernah   \n",
       "678    Tidak pernah                        0-2 jam    Kadang-kadang   \n",
       "644    Tidak pernah                        0-2 jam    Kadang-kadang   \n",
       "275    Tidak pernah                        0-2 jam    Kadang-kadang   \n",
       "173        2-4 hari                        0-2 jam     Tidak pernah   \n",
       "510        1-2 hari                        0-2 jam     Tidak pernah   \n",
       "548    Tidak pernah                        0-2 jam     Tidak pernah   \n",
       "389    Tidak pernah                        0-2 jam     Tidak pernah   \n",
       "394    Tidak pernah                        0-2 jam    Kadang-kadang   \n",
       "206        1-2 hari                        0-2 jam    Kadang-kadang   \n",
       "295        1-2 hari                        0-2 jam    Kadang-kadang   \n",
       "480    Tidak pernah                        0-2 jam     Tidak pernah   \n",
       "124    Tidak pernah                        3-5 jam     Tidak pernah   \n",
       "\n",
       "    transporasi_biasa_digunakan         kelas_obesitas  \\\n",
       "606                  Jalan kaki             obesitas_I   \n",
       "71                 Sepeda motor                 normal   \n",
       "609                  Jalan kaki             obesitas_I   \n",
       "678                  Jalan kaki            obesitas_II   \n",
       "644                  Jalan kaki            obesitas_II   \n",
       "275                Sepeda motor     berat_badan_kurang   \n",
       "173                Sepeda motor                 normal   \n",
       "510                       Mobil  kelebihan_berat_badan   \n",
       "548                Sepeda motor  kelebihan_berat_badan   \n",
       "389                  Jalan kaki             obesitas_I   \n",
       "394                  Jalan kaki            obesitas_II   \n",
       "206                Sepeda motor                 normal   \n",
       "295                Sepeda motor     berat_badan_kurang   \n",
       "480                Sepeda motor     berat_badan_kurang   \n",
       "124                  Jalan kaki  kelebihan_berat_badan   \n",
       "\n",
       "    klasifikasi_k_nearest_neighbor  \n",
       "606                     obesitas_I  \n",
       "71                          normal  \n",
       "609                     obesitas_I  \n",
       "678                    obesitas_II  \n",
       "644                    obesitas_II  \n",
       "275             berat_badan_kurang  \n",
       "173                         normal  \n",
       "510          kelebihan_berat_badan  \n",
       "548          kelebihan_berat_badan  \n",
       "389                     obesitas_I  \n",
       "394                    obesitas_II  \n",
       "206                         normal  \n",
       "295             berat_badan_kurang  \n",
       "480             berat_badan_kurang  \n",
       "124          kelebihan_berat_badan  "
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dataKNN['klasifikasi_k_nearest_neighbor'] = Y_predictKNN\n",
    "dataKNN"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "0c8ed05b",
   "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>jenis_kelamin</th>\n",
       "      <th>umur</th>\n",
       "      <th>tinggi_badan_meter</th>\n",
       "      <th>berat_badan_kilogram</th>\n",
       "      <th>histori_keluarga_kelebihan_BB</th>\n",
       "      <th>konsumsi_tinggi_kalori</th>\n",
       "      <th>konsumsi_sayuran</th>\n",
       "      <th>makan_berat</th>\n",
       "      <th>ngemil</th>\n",
       "      <th>merokok</th>\n",
       "      <th>konsumsi_air_liter</th>\n",
       "      <th>pemantauan_kalori</th>\n",
       "      <th>aktifitas_fisik</th>\n",
       "      <th>penggunaan_perangkat_teknologi</th>\n",
       "      <th>konsumsi_alkohol</th>\n",
       "      <th>transporasi_biasa_digunakan</th>\n",
       "      <th>kelas_obesitas</th>\n",
       "      <th>klasifikasi_naive_bayes</th>\n",
       "      <th>klasifikasi_k_nearest_neighbor</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>606</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>31</td>\n",
       "      <td>1.672625</td>\n",
       "      <td>71</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>3x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Jalan kaki</td>\n",
       "      <td>obesitas_I</td>\n",
       "      <td>obesitas_II</td>\n",
       "      <td>obesitas_I</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>71</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>19</td>\n",
       "      <td>1.650000</td>\n",
       "      <td>56</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Selalu</td>\n",
       "      <td>3x</td>\n",
       "      <td>Sering</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Lebih 2 liter</td>\n",
       "      <td>Ya</td>\n",
       "      <td>1-2 hari</td>\n",
       "      <td>3-5 jam</td>\n",
       "      <td>Sering</td>\n",
       "      <td>Sepeda motor</td>\n",
       "      <td>normal</td>\n",
       "      <td>normal</td>\n",
       "      <td>normal</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>609</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>39</td>\n",
       "      <td>1.711621</td>\n",
       "      <td>84</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Selalu</td>\n",
       "      <td>1-2x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Lebih 2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>Jalan kaki</td>\n",
       "      <td>obesitas_I</td>\n",
       "      <td>obesitas_I</td>\n",
       "      <td>obesitas_I</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>678</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>37</td>\n",
       "      <td>1.560000</td>\n",
       "      <td>79</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>3x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Jalan kaki</td>\n",
       "      <td>obesitas_II</td>\n",
       "      <td>obesitas_II</td>\n",
       "      <td>obesitas_II</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>644</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>39</td>\n",
       "      <td>1.528746</td>\n",
       "      <td>79</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>3x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Jalan kaki</td>\n",
       "      <td>obesitas_II</td>\n",
       "      <td>obesitas_II</td>\n",
       "      <td>obesitas_II</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>275</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>20</td>\n",
       "      <td>1.550000</td>\n",
       "      <td>41</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Selalu</td>\n",
       "      <td>1-2x</td>\n",
       "      <td>Sering</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Sepeda motor</td>\n",
       "      <td>berat_badan_kurang</td>\n",
       "      <td>berat_badan_kurang</td>\n",
       "      <td>berat_badan_kurang</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>173</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>21</td>\n",
       "      <td>1.540000</td>\n",
       "      <td>47</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Selalu</td>\n",
       "      <td>3x</td>\n",
       "      <td>Selalu</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>2-4 hari</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>Sepeda motor</td>\n",
       "      <td>normal</td>\n",
       "      <td>berat_badan_kurang</td>\n",
       "      <td>normal</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>510</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>25</td>\n",
       "      <td>1.643548</td>\n",
       "      <td>62</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>3x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 hari</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>Mobil</td>\n",
       "      <td>kelebihan_berat_badan</td>\n",
       "      <td>kelebihan_berat_badan</td>\n",
       "      <td>kelebihan_berat_badan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>548</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>21</td>\n",
       "      <td>1.641347</td>\n",
       "      <td>66</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Selalu</td>\n",
       "      <td>1-2x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>Sepeda motor</td>\n",
       "      <td>kelebihan_berat_badan</td>\n",
       "      <td>obesitas_II</td>\n",
       "      <td>kelebihan_berat_badan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>389</th>\n",
       "      <td>Laki-laki</td>\n",
       "      <td>39</td>\n",
       "      <td>1.720000</td>\n",
       "      <td>86</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Selalu</td>\n",
       "      <td>1-2x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>Jalan kaki</td>\n",
       "      <td>obesitas_I</td>\n",
       "      <td>obesitas_II</td>\n",
       "      <td>obesitas_I</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>394</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>37</td>\n",
       "      <td>1.560000</td>\n",
       "      <td>77</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>3x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Jalan kaki</td>\n",
       "      <td>obesitas_II</td>\n",
       "      <td>obesitas_II</td>\n",
       "      <td>obesitas_II</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>206</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>18</td>\n",
       "      <td>1.640000</td>\n",
       "      <td>59</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>3x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 hari</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Sepeda motor</td>\n",
       "      <td>normal</td>\n",
       "      <td>kelebihan_berat_badan</td>\n",
       "      <td>normal</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>295</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>19</td>\n",
       "      <td>1.680000</td>\n",
       "      <td>49</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Selalu</td>\n",
       "      <td>3x</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 hari</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Sepeda motor</td>\n",
       "      <td>berat_badan_kurang</td>\n",
       "      <td>berat_badan_kurang</td>\n",
       "      <td>berat_badan_kurang</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>480</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>21</td>\n",
       "      <td>1.694749</td>\n",
       "      <td>49</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Selalu</td>\n",
       "      <td>3x</td>\n",
       "      <td>Sering</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>Sepeda motor</td>\n",
       "      <td>berat_badan_kurang</td>\n",
       "      <td>berat_badan_kurang</td>\n",
       "      <td>berat_badan_kurang</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>124</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>20</td>\n",
       "      <td>1.630000</td>\n",
       "      <td>64</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>3x</td>\n",
       "      <td>Selalu</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>1-2 liter</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>3-5 jam</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>Jalan kaki</td>\n",
       "      <td>kelebihan_berat_badan</td>\n",
       "      <td>normal</td>\n",
       "      <td>kelebihan_berat_badan</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    jenis_kelamin  umur  tinggi_badan_meter  berat_badan_kilogram  \\\n",
       "606     Perempuan    31            1.672625                    71   \n",
       "71      Perempuan    19            1.650000                    56   \n",
       "609     Perempuan    39            1.711621                    84   \n",
       "678     Perempuan    37            1.560000                    79   \n",
       "644     Perempuan    39            1.528746                    79   \n",
       "275     Perempuan    20            1.550000                    41   \n",
       "173     Perempuan    21            1.540000                    47   \n",
       "510     Perempuan    25            1.643548                    62   \n",
       "548     Perempuan    21            1.641347                    66   \n",
       "389     Laki-laki    39            1.720000                    86   \n",
       "394     Perempuan    37            1.560000                    77   \n",
       "206     Perempuan    18            1.640000                    59   \n",
       "295     Perempuan    19            1.680000                    49   \n",
       "480     Perempuan    21            1.694749                    49   \n",
       "124     Perempuan    20            1.630000                    64   \n",
       "\n",
       "    histori_keluarga_kelebihan_BB konsumsi_tinggi_kalori konsumsi_sayuran  \\\n",
       "606                            Ya                     Ya    Kadang-kadang   \n",
       "71                             Ya                     Ya           Selalu   \n",
       "609                         Tidak                     Ya           Selalu   \n",
       "678                            Ya                     Ya    Kadang-kadang   \n",
       "644                            Ya                     Ya    Kadang-kadang   \n",
       "275                         Tidak                     Ya           Selalu   \n",
       "173                            Ya                  Tidak           Selalu   \n",
       "510                         Tidak                  Tidak    Kadang-kadang   \n",
       "548                            Ya                     Ya           Selalu   \n",
       "389                            Ya                     Ya           Selalu   \n",
       "394                            Ya                     Ya    Kadang-kadang   \n",
       "206                            Ya                     Ya    Kadang-kadang   \n",
       "295                         Tidak                  Tidak           Selalu   \n",
       "480                            Ya                     Ya           Selalu   \n",
       "124                            Ya                     Ya     Tidak pernah   \n",
       "\n",
       "    makan_berat         ngemil merokok konsumsi_air_liter pemantauan_kalori  \\\n",
       "606          3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "71           3x         Sering      Ya      Lebih 2 liter                Ya   \n",
       "609        1-2x  Kadang-kadang   Tidak      Lebih 2 liter             Tidak   \n",
       "678          3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "644          3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "275        1-2x         Sering   Tidak          1-2 liter             Tidak   \n",
       "173          3x         Selalu   Tidak          1-2 liter             Tidak   \n",
       "510          3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "548        1-2x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "389        1-2x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "394          3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "206          3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "295          3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "480          3x         Sering   Tidak          1-2 liter             Tidak   \n",
       "124          3x         Selalu   Tidak          1-2 liter             Tidak   \n",
       "\n",
       "    aktifitas_fisik penggunaan_perangkat_teknologi konsumsi_alkohol  \\\n",
       "606    Tidak pernah                        0-2 jam    Kadang-kadang   \n",
       "71         1-2 hari                        3-5 jam           Sering   \n",
       "609    Tidak pernah                        0-2 jam     Tidak pernah   \n",
       "678    Tidak pernah                        0-2 jam    Kadang-kadang   \n",
       "644    Tidak pernah                        0-2 jam    Kadang-kadang   \n",
       "275    Tidak pernah                        0-2 jam    Kadang-kadang   \n",
       "173        2-4 hari                        0-2 jam     Tidak pernah   \n",
       "510        1-2 hari                        0-2 jam     Tidak pernah   \n",
       "548    Tidak pernah                        0-2 jam     Tidak pernah   \n",
       "389    Tidak pernah                        0-2 jam     Tidak pernah   \n",
       "394    Tidak pernah                        0-2 jam    Kadang-kadang   \n",
       "206        1-2 hari                        0-2 jam    Kadang-kadang   \n",
       "295        1-2 hari                        0-2 jam    Kadang-kadang   \n",
       "480    Tidak pernah                        0-2 jam     Tidak pernah   \n",
       "124    Tidak pernah                        3-5 jam     Tidak pernah   \n",
       "\n",
       "    transporasi_biasa_digunakan         kelas_obesitas  \\\n",
       "606                  Jalan kaki             obesitas_I   \n",
       "71                 Sepeda motor                 normal   \n",
       "609                  Jalan kaki             obesitas_I   \n",
       "678                  Jalan kaki            obesitas_II   \n",
       "644                  Jalan kaki            obesitas_II   \n",
       "275                Sepeda motor     berat_badan_kurang   \n",
       "173                Sepeda motor                 normal   \n",
       "510                       Mobil  kelebihan_berat_badan   \n",
       "548                Sepeda motor  kelebihan_berat_badan   \n",
       "389                  Jalan kaki             obesitas_I   \n",
       "394                  Jalan kaki            obesitas_II   \n",
       "206                Sepeda motor                 normal   \n",
       "295                Sepeda motor     berat_badan_kurang   \n",
       "480                Sepeda motor     berat_badan_kurang   \n",
       "124                  Jalan kaki  kelebihan_berat_badan   \n",
       "\n",
       "    klasifikasi_naive_bayes klasifikasi_k_nearest_neighbor  \n",
       "606             obesitas_II                     obesitas_I  \n",
       "71                   normal                         normal  \n",
       "609              obesitas_I                     obesitas_I  \n",
       "678             obesitas_II                    obesitas_II  \n",
       "644             obesitas_II                    obesitas_II  \n",
       "275      berat_badan_kurang             berat_badan_kurang  \n",
       "173      berat_badan_kurang                         normal  \n",
       "510   kelebihan_berat_badan          kelebihan_berat_badan  \n",
       "548             obesitas_II          kelebihan_berat_badan  \n",
       "389             obesitas_II                     obesitas_I  \n",
       "394             obesitas_II                    obesitas_II  \n",
       "206   kelebihan_berat_badan                         normal  \n",
       "295      berat_badan_kurang             berat_badan_kurang  \n",
       "480      berat_badan_kurang             berat_badan_kurang  \n",
       "124                  normal          kelebihan_berat_badan  "
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_NV_KNN['klasifikasi_naive_bayes'] = Y_predictNV\n",
    "data_NV_KNN['klasifikasi_k_nearest_neighbor'] = Y_predictKNN\n",
    "data_NV_KNN"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6eb6c4ab",
   "metadata": {},
   "source": [
    "### download data hasil klasifikasi"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "caafc24e",
   "metadata": {},
   "outputs": [],
   "source": [
    "# excel_file = pd.ExcelWriter(\"smote_data_hasil_klasifikasi.xlsx\")\n",
    "# data_NV_KNN.to_excel(excel_file)\n",
    "# excel_file.save()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ddd2decc",
   "metadata": {},
   "source": [
    "## Visualisasi data hasil klasifikasi"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "01a3ab8e",
   "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>kelas_obesitas</th>\n",
       "      <th>keterangan</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>obesitas_I</td>\n",
       "      <td>kelas_sebenarnya</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>normal</td>\n",
       "      <td>kelas_sebenarnya</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>obesitas_I</td>\n",
       "      <td>kelas_sebenarnya</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>obesitas_II</td>\n",
       "      <td>kelas_sebenarnya</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>obesitas_II</td>\n",
       "      <td>kelas_sebenarnya</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>berat_badan_kurang</td>\n",
       "      <td>kelas_sebenarnya</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>normal</td>\n",
       "      <td>kelas_sebenarnya</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>kelebihan_berat_badan</td>\n",
       "      <td>kelas_sebenarnya</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>kelebihan_berat_badan</td>\n",
       "      <td>kelas_sebenarnya</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>obesitas_I</td>\n",
       "      <td>kelas_sebenarnya</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>obesitas_II</td>\n",
       "      <td>kelas_sebenarnya</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>normal</td>\n",
       "      <td>kelas_sebenarnya</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>berat_badan_kurang</td>\n",
       "      <td>kelas_sebenarnya</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>berat_badan_kurang</td>\n",
       "      <td>kelas_sebenarnya</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>kelebihan_berat_badan</td>\n",
       "      <td>kelas_sebenarnya</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>obesitas_II</td>\n",
       "      <td>klasifikasi_naive_bayes</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>normal</td>\n",
       "      <td>klasifikasi_naive_bayes</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>obesitas_I</td>\n",
       "      <td>klasifikasi_naive_bayes</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>obesitas_II</td>\n",
       "      <td>klasifikasi_naive_bayes</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>obesitas_II</td>\n",
       "      <td>klasifikasi_naive_bayes</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>berat_badan_kurang</td>\n",
       "      <td>klasifikasi_naive_bayes</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>berat_badan_kurang</td>\n",
       "      <td>klasifikasi_naive_bayes</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>kelebihan_berat_badan</td>\n",
       "      <td>klasifikasi_naive_bayes</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>obesitas_II</td>\n",
       "      <td>klasifikasi_naive_bayes</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>obesitas_II</td>\n",
       "      <td>klasifikasi_naive_bayes</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>obesitas_II</td>\n",
       "      <td>klasifikasi_naive_bayes</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>kelebihan_berat_badan</td>\n",
       "      <td>klasifikasi_naive_bayes</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>berat_badan_kurang</td>\n",
       "      <td>klasifikasi_naive_bayes</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>berat_badan_kurang</td>\n",
       "      <td>klasifikasi_naive_bayes</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>normal</td>\n",
       "      <td>klasifikasi_naive_bayes</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>obesitas_I</td>\n",
       "      <td>klasifikasi_k_nearest_neighbor</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>normal</td>\n",
       "      <td>klasifikasi_k_nearest_neighbor</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32</th>\n",
       "      <td>obesitas_I</td>\n",
       "      <td>klasifikasi_k_nearest_neighbor</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>33</th>\n",
       "      <td>obesitas_II</td>\n",
       "      <td>klasifikasi_k_nearest_neighbor</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>34</th>\n",
       "      <td>obesitas_II</td>\n",
       "      <td>klasifikasi_k_nearest_neighbor</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>35</th>\n",
       "      <td>berat_badan_kurang</td>\n",
       "      <td>klasifikasi_k_nearest_neighbor</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>36</th>\n",
       "      <td>normal</td>\n",
       "      <td>klasifikasi_k_nearest_neighbor</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>37</th>\n",
       "      <td>kelebihan_berat_badan</td>\n",
       "      <td>klasifikasi_k_nearest_neighbor</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>38</th>\n",
       "      <td>kelebihan_berat_badan</td>\n",
       "      <td>klasifikasi_k_nearest_neighbor</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>39</th>\n",
       "      <td>obesitas_I</td>\n",
       "      <td>klasifikasi_k_nearest_neighbor</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>40</th>\n",
       "      <td>obesitas_II</td>\n",
       "      <td>klasifikasi_k_nearest_neighbor</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>41</th>\n",
       "      <td>normal</td>\n",
       "      <td>klasifikasi_k_nearest_neighbor</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>42</th>\n",
       "      <td>berat_badan_kurang</td>\n",
       "      <td>klasifikasi_k_nearest_neighbor</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>43</th>\n",
       "      <td>berat_badan_kurang</td>\n",
       "      <td>klasifikasi_k_nearest_neighbor</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>44</th>\n",
       "      <td>kelebihan_berat_badan</td>\n",
       "      <td>klasifikasi_k_nearest_neighbor</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           kelas_obesitas                      keterangan\n",
       "0              obesitas_I                kelas_sebenarnya\n",
       "1                  normal                kelas_sebenarnya\n",
       "2              obesitas_I                kelas_sebenarnya\n",
       "3             obesitas_II                kelas_sebenarnya\n",
       "4             obesitas_II                kelas_sebenarnya\n",
       "5      berat_badan_kurang                kelas_sebenarnya\n",
       "6                  normal                kelas_sebenarnya\n",
       "7   kelebihan_berat_badan                kelas_sebenarnya\n",
       "8   kelebihan_berat_badan                kelas_sebenarnya\n",
       "9              obesitas_I                kelas_sebenarnya\n",
       "10            obesitas_II                kelas_sebenarnya\n",
       "11                 normal                kelas_sebenarnya\n",
       "12     berat_badan_kurang                kelas_sebenarnya\n",
       "13     berat_badan_kurang                kelas_sebenarnya\n",
       "14  kelebihan_berat_badan                kelas_sebenarnya\n",
       "15            obesitas_II         klasifikasi_naive_bayes\n",
       "16                 normal         klasifikasi_naive_bayes\n",
       "17             obesitas_I         klasifikasi_naive_bayes\n",
       "18            obesitas_II         klasifikasi_naive_bayes\n",
       "19            obesitas_II         klasifikasi_naive_bayes\n",
       "20     berat_badan_kurang         klasifikasi_naive_bayes\n",
       "21     berat_badan_kurang         klasifikasi_naive_bayes\n",
       "22  kelebihan_berat_badan         klasifikasi_naive_bayes\n",
       "23            obesitas_II         klasifikasi_naive_bayes\n",
       "24            obesitas_II         klasifikasi_naive_bayes\n",
       "25            obesitas_II         klasifikasi_naive_bayes\n",
       "26  kelebihan_berat_badan         klasifikasi_naive_bayes\n",
       "27     berat_badan_kurang         klasifikasi_naive_bayes\n",
       "28     berat_badan_kurang         klasifikasi_naive_bayes\n",
       "29                 normal         klasifikasi_naive_bayes\n",
       "30             obesitas_I  klasifikasi_k_nearest_neighbor\n",
       "31                 normal  klasifikasi_k_nearest_neighbor\n",
       "32             obesitas_I  klasifikasi_k_nearest_neighbor\n",
       "33            obesitas_II  klasifikasi_k_nearest_neighbor\n",
       "34            obesitas_II  klasifikasi_k_nearest_neighbor\n",
       "35     berat_badan_kurang  klasifikasi_k_nearest_neighbor\n",
       "36                 normal  klasifikasi_k_nearest_neighbor\n",
       "37  kelebihan_berat_badan  klasifikasi_k_nearest_neighbor\n",
       "38  kelebihan_berat_badan  klasifikasi_k_nearest_neighbor\n",
       "39             obesitas_I  klasifikasi_k_nearest_neighbor\n",
       "40            obesitas_II  klasifikasi_k_nearest_neighbor\n",
       "41                 normal  klasifikasi_k_nearest_neighbor\n",
       "42     berat_badan_kurang  klasifikasi_k_nearest_neighbor\n",
       "43     berat_badan_kurang  klasifikasi_k_nearest_neighbor\n",
       "44  kelebihan_berat_badan  klasifikasi_k_nearest_neighbor"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_ringkasan = pd.DataFrame(columns=['kelas_obesitas', 'keterangan'])\n",
    "\n",
    "# Menggabungkan nilai dari kolom obesity_class\n",
    "data_ringkasan = pd.concat([data_ringkasan, pd.DataFrame({'kelas_obesitas': data_NV_KNN['kelas_obesitas'], 'keterangan': 'kelas_sebenarnya'})], ignore_index=True)\n",
    "\n",
    "# Menggabungkan nilai dari kolom klasifikasi_naive_bayes\n",
    "data_ringkasan = pd.concat([data_ringkasan, pd.DataFrame({'kelas_obesitas': data_NV_KNN['klasifikasi_naive_bayes'], 'keterangan': 'klasifikasi_naive_bayes'})], ignore_index=True)\n",
    "\n",
    "# Menggabungkan nilai dari kolom klasifikasi_k_nearest_neighbor\n",
    "data_ringkasan = pd.concat([data_ringkasan, pd.DataFrame({'kelas_obesitas': data_NV_KNN['klasifikasi_k_nearest_neighbor'], 'keterangan': 'klasifikasi_k_nearest_neighbor'})], ignore_index=True)\n",
    "\n",
    "data_ringkasan"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "7383d81d",
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 37200 characters]",
      "text/plain": [
       "<Figure size 900x600 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.figure(figsize=(9,6))\n",
    "sns.countplot(x='kelas_obesitas', hue='keterangan', data=data_ringkasan, order=urutan_obesitas, palette='rocket_r')\n",
    "# plt.xticks(rotation=20, ha='right')\n",
    "# plt.tight_layout()\n",
    "plt.xlabel('kelas_obesitas', labelpad=6)  # Add padding to the x-axis label\n",
    "plt.ylabel('jumlah', labelpad=5)  # Add padding to the x-axis label\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9a25d803",
   "metadata": {},
   "source": [
    "### Pembuktian visualisasi data hasil klasifikasi"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "e1ab2eb5",
   "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>kelas_obesitas</th>\n",
       "      <th>jumlah</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>berat_badan_kurang</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>normal</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>kelebihan_berat_badan</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>obesitas_I</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>obesitas_II</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          kelas_obesitas  jumlah\n",
       "3     berat_badan_kurang       3\n",
       "1                 normal       3\n",
       "4  kelebihan_berat_badan       3\n",
       "0             obesitas_I       3\n",
       "2            obesitas_II       3"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "kelas_obesitashasil = data_NV_KNN['kelas_obesitas'].value_counts().rename_axis('kelas_obesitas').reset_index(name='jumlah')\n",
    "kelas_obesitashasil['kelas_obesitas'] = pd.Categorical(kelas_obesitashasil['kelas_obesitas'], categories=urutan_obesitas, ordered=True)\n",
    "kelas_obesitashasil = kelas_obesitashasil.sort_values(by='kelas_obesitas')\n",
    "kelas_obesitashasil"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "8bb32b20",
   "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>klasifikasi_naive_bayes</th>\n",
       "      <th>jumlah</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>berat_badan_kurang</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>normal</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>kelebihan_berat_badan</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>obesitas_I</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>obesitas_II</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  klasifikasi_naive_bayes  jumlah\n",
       "1      berat_badan_kurang       4\n",
       "2                  normal       2\n",
       "3   kelebihan_berat_badan       2\n",
       "4              obesitas_I       1\n",
       "0             obesitas_II       6"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "kelas_obesitashasilNV = data_NV_KNN['klasifikasi_naive_bayes'].value_counts().rename_axis('klasifikasi_naive_bayes').reset_index(name='jumlah')\n",
    "kelas_obesitashasilNV['klasifikasi_naive_bayes'] = pd.Categorical(kelas_obesitashasilNV['klasifikasi_naive_bayes'], categories=urutan_obesitas, ordered=True)\n",
    "kelas_obesitashasilNV = kelas_obesitashasilNV.sort_values(by='klasifikasi_naive_bayes')\n",
    "kelas_obesitashasilNV"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "4e14fdd9",
   "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>klasifikasi_k_nearest_neighbor</th>\n",
       "      <th>jumlah</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>berat_badan_kurang</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>normal</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>kelebihan_berat_badan</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>obesitas_I</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>obesitas_II</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  klasifikasi_k_nearest_neighbor  jumlah\n",
       "3             berat_badan_kurang       3\n",
       "1                         normal       3\n",
       "4          kelebihan_berat_badan       3\n",
       "0                     obesitas_I       3\n",
       "2                    obesitas_II       3"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "kelas_obesitashasilKNN = data_NV_KNN['klasifikasi_k_nearest_neighbor'].value_counts().rename_axis('klasifikasi_k_nearest_neighbor').reset_index(name='jumlah')\n",
    "kelas_obesitashasilKNN['klasifikasi_k_nearest_neighbor'] = pd.Categorical(kelas_obesitashasilKNN['klasifikasi_k_nearest_neighbor'], categories=urutan_obesitas, ordered=True)\n",
    "kelas_obesitashasilKNN = kelas_obesitashasilKNN.sort_values(by='klasifikasi_k_nearest_neighbor')\n",
    "kelas_obesitashasilKNN"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9e12d052",
   "metadata": {},
   "source": [
    "# Analisis perbandingan hasil"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "c50b3c45",
   "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>testing</th>\n",
       "      <th>data_latih</th>\n",
       "      <th>data_uji</th>\n",
       "      <th>latih_uji</th>\n",
       "      <th>model</th>\n",
       "      <th>akurasi</th>\n",
       "      <th>presisi</th>\n",
       "      <th>recal</th>\n",
       "      <th>F1</th>\n",
       "      <th>w_latih</th>\n",
       "      <th>w_uji</th>\n",
       "      <th>k_knn</th>\n",
       "      <th>roc_auc</th>\n",
       "      <th>Unnamed: 13</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.90</td>\n",
       "      <td>70.0</td>\n",
       "      <td>635.0</td>\n",
       "      <td>70:635</td>\n",
       "      <td>naive_bayes</td>\n",
       "      <td>0.47</td>\n",
       "      <td>0.44</td>\n",
       "      <td>0.47</td>\n",
       "      <td>0.41</td>\n",
       "      <td>0.004090</td>\n",
       "      <td>0.002630</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>70:635</td>\n",
       "      <td>k_nearest_neighbor</td>\n",
       "      <td>0.62</td>\n",
       "      <td>0.60</td>\n",
       "      <td>0.62</td>\n",
       "      <td>0.60</td>\n",
       "      <td>0.001189</td>\n",
       "      <td>0.105440</td>\n",
       "      <td>4.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.80</td>\n",
       "      <td>141.0</td>\n",
       "      <td>564.0</td>\n",
       "      <td>141:594</td>\n",
       "      <td>naive_bayes</td>\n",
       "      <td>0.51</td>\n",
       "      <td>0.51</td>\n",
       "      <td>0.51</td>\n",
       "      <td>0.45</td>\n",
       "      <td>0.008121</td>\n",
       "      <td>0.002256</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>141:594</td>\n",
       "      <td>k_nearest_neighbor</td>\n",
       "      <td>0.63</td>\n",
       "      <td>0.63</td>\n",
       "      <td>0.63</td>\n",
       "      <td>0.63</td>\n",
       "      <td>0.001047</td>\n",
       "      <td>0.093908</td>\n",
       "      <td>3.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0.70</td>\n",
       "      <td>211.0</td>\n",
       "      <td>494.0</td>\n",
       "      <td>211:494</td>\n",
       "      <td>naive_bayes</td>\n",
       "      <td>0.55</td>\n",
       "      <td>0.51</td>\n",
       "      <td>0.55</td>\n",
       "      <td>0.48</td>\n",
       "      <td>0.008355</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>211:494</td>\n",
       "      <td>k_nearest_neighbor</td>\n",
       "      <td>0.66</td>\n",
       "      <td>0.66</td>\n",
       "      <td>0.66</td>\n",
       "      <td>0.66</td>\n",
       "      <td>0.001281</td>\n",
       "      <td>0.070467</td>\n",
       "      <td>3.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>0.60</td>\n",
       "      <td>282.0</td>\n",
       "      <td>432.0</td>\n",
       "      <td>282:432</td>\n",
       "      <td>naive_bayes</td>\n",
       "      <td>0.51</td>\n",
       "      <td>0.53</td>\n",
       "      <td>0.51</td>\n",
       "      <td>0.46</td>\n",
       "      <td>0.008337</td>\n",
       "      <td>0.001994</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>282:432</td>\n",
       "      <td>k_nearest_neighbor</td>\n",
       "      <td>0.70</td>\n",
       "      <td>0.71</td>\n",
       "      <td>0.70</td>\n",
       "      <td>0.69</td>\n",
       "      <td>0.001401</td>\n",
       "      <td>0.072488</td>\n",
       "      <td>3.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>0.50</td>\n",
       "      <td>352.0</td>\n",
       "      <td>353.0</td>\n",
       "      <td>352:353</td>\n",
       "      <td>naive_bayes</td>\n",
       "      <td>0.54</td>\n",
       "      <td>0.54</td>\n",
       "      <td>0.54</td>\n",
       "      <td>0.54</td>\n",
       "      <td>0.008823</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>352:353</td>\n",
       "      <td>k_nearest_neighbor</td>\n",
       "      <td>0.71</td>\n",
       "      <td>0.72</td>\n",
       "      <td>0.71</td>\n",
       "      <td>0.70</td>\n",
       "      <td>0.001383</td>\n",
       "      <td>0.070567</td>\n",
       "      <td>4.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>0.40</td>\n",
       "      <td>423.0</td>\n",
       "      <td>282.0</td>\n",
       "      <td>423:282</td>\n",
       "      <td>naive_bayes</td>\n",
       "      <td>0.51</td>\n",
       "      <td>0.50</td>\n",
       "      <td>0.51</td>\n",
       "      <td>0.45</td>\n",
       "      <td>0.008008</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>423:282</td>\n",
       "      <td>k_nearest_neighbor</td>\n",
       "      <td>0.75</td>\n",
       "      <td>0.75</td>\n",
       "      <td>0.75</td>\n",
       "      <td>0.73</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.069703</td>\n",
       "      <td>4.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>0.30</td>\n",
       "      <td>493.0</td>\n",
       "      <td>212.0</td>\n",
       "      <td>493:212</td>\n",
       "      <td>naive_bayes</td>\n",
       "      <td>0.65</td>\n",
       "      <td>0.65</td>\n",
       "      <td>0.65</td>\n",
       "      <td>0.62</td>\n",
       "      <td>0.009819</td>\n",
       "      <td>0.001983</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>493:212</td>\n",
       "      <td>k_nearest_neighbor</td>\n",
       "      <td>0.77</td>\n",
       "      <td>0.77</td>\n",
       "      <td>0.77</td>\n",
       "      <td>0.77</td>\n",
       "      <td>0.001301</td>\n",
       "      <td>0.064058</td>\n",
       "      <td>4.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>0.20</td>\n",
       "      <td>564.0</td>\n",
       "      <td>141.0</td>\n",
       "      <td>564:141</td>\n",
       "      <td>naive_bayes</td>\n",
       "      <td>0.65</td>\n",
       "      <td>0.70</td>\n",
       "      <td>0.65</td>\n",
       "      <td>0.62</td>\n",
       "      <td>0.009426</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NV</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>564:141</td>\n",
       "      <td>k_nearest_neighbor</td>\n",
       "      <td>0.79</td>\n",
       "      <td>0.79</td>\n",
       "      <td>0.79</td>\n",
       "      <td>0.78</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.055702</td>\n",
       "      <td>4.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>0.10</td>\n",
       "      <td>634.0</td>\n",
       "      <td>71.0</td>\n",
       "      <td>634:71</td>\n",
       "      <td>naive_bayes</td>\n",
       "      <td>0.63</td>\n",
       "      <td>0.63</td>\n",
       "      <td>0.63</td>\n",
       "      <td>0.59</td>\n",
       "      <td>0.009813</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>634:71</td>\n",
       "      <td>k_nearest_neighbor</td>\n",
       "      <td>0.83</td>\n",
       "      <td>0.83</td>\n",
       "      <td>0.83</td>\n",
       "      <td>0.82</td>\n",
       "      <td>0.001507</td>\n",
       "      <td>0.044852</td>\n",
       "      <td>4.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>0.09</td>\n",
       "      <td>641.0</td>\n",
       "      <td>64.0</td>\n",
       "      <td>641:64</td>\n",
       "      <td>naive_bayes</td>\n",
       "      <td>0.62</td>\n",
       "      <td>0.71</td>\n",
       "      <td>0.62</td>\n",
       "      <td>0.59</td>\n",
       "      <td>0.009722</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>641:64</td>\n",
       "      <td>k_nearest_neighbor</td>\n",
       "      <td>0.80</td>\n",
       "      <td>0.79</td>\n",
       "      <td>0.79</td>\n",
       "      <td>0.79</td>\n",
       "      <td>0.002041</td>\n",
       "      <td>0.046776</td>\n",
       "      <td>6.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>0.08</td>\n",
       "      <td>648.0</td>\n",
       "      <td>57.0</td>\n",
       "      <td>648:57</td>\n",
       "      <td>naive_bayes</td>\n",
       "      <td>0.63</td>\n",
       "      <td>0.71</td>\n",
       "      <td>0.63</td>\n",
       "      <td>0.60</td>\n",
       "      <td>0.013452</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>648:57</td>\n",
       "      <td>k_nearest_neighbor</td>\n",
       "      <td>0.81</td>\n",
       "      <td>0.80</td>\n",
       "      <td>0.80</td>\n",
       "      <td>0.80</td>\n",
       "      <td>0.002641</td>\n",
       "      <td>0.037296</td>\n",
       "      <td>6.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>0.07</td>\n",
       "      <td>655.0</td>\n",
       "      <td>50.0</td>\n",
       "      <td>655:50</td>\n",
       "      <td>naive_bayes</td>\n",
       "      <td>0.60</td>\n",
       "      <td>0.69</td>\n",
       "      <td>0.60</td>\n",
       "      <td>0.55</td>\n",
       "      <td>0.012512</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>655:50</td>\n",
       "      <td>k_nearest_neighbor</td>\n",
       "      <td>0.84</td>\n",
       "      <td>0.84</td>\n",
       "      <td>0.84</td>\n",
       "      <td>0.84</td>\n",
       "      <td>0.002730</td>\n",
       "      <td>0.029474</td>\n",
       "      <td>6.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>0.06</td>\n",
       "      <td>662.0</td>\n",
       "      <td>43.0</td>\n",
       "      <td>662:43</td>\n",
       "      <td>naive_bayes</td>\n",
       "      <td>0.60</td>\n",
       "      <td>0.70</td>\n",
       "      <td>0.61</td>\n",
       "      <td>0.56</td>\n",
       "      <td>0.014257</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>662:43</td>\n",
       "      <td>k_nearest_neighbor</td>\n",
       "      <td>0.84</td>\n",
       "      <td>0.84</td>\n",
       "      <td>0.83</td>\n",
       "      <td>0.83</td>\n",
       "      <td>0.002500</td>\n",
       "      <td>0.028498</td>\n",
       "      <td>6.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>0.05</td>\n",
       "      <td>669.0</td>\n",
       "      <td>36.0</td>\n",
       "      <td>669:36</td>\n",
       "      <td>naive_bayes</td>\n",
       "      <td>0.61</td>\n",
       "      <td>0.69</td>\n",
       "      <td>0.60</td>\n",
       "      <td>0.57</td>\n",
       "      <td>0.015503</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>669:36</td>\n",
       "      <td>k_nearest_neighbor</td>\n",
       "      <td>0.81</td>\n",
       "      <td>0.81</td>\n",
       "      <td>0.80</td>\n",
       "      <td>0.80</td>\n",
       "      <td>0.002558</td>\n",
       "      <td>0.025552</td>\n",
       "      <td>6.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>0.04</td>\n",
       "      <td>676.0</td>\n",
       "      <td>29.0</td>\n",
       "      <td>676:29</td>\n",
       "      <td>naive_bayes</td>\n",
       "      <td>0.55</td>\n",
       "      <td>0.62</td>\n",
       "      <td>0.55</td>\n",
       "      <td>0.51</td>\n",
       "      <td>0.016332</td>\n",
       "      <td>0.000171</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>676:29</td>\n",
       "      <td>k_nearest_neighbor</td>\n",
       "      <td>0.76</td>\n",
       "      <td>0.75</td>\n",
       "      <td>0.75</td>\n",
       "      <td>0.75</td>\n",
       "      <td>0.002468</td>\n",
       "      <td>0.025420</td>\n",
       "      <td>6.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>0.03</td>\n",
       "      <td>683.0</td>\n",
       "      <td>22.0</td>\n",
       "      <td>683:22</td>\n",
       "      <td>naive_bayes</td>\n",
       "      <td>0.50</td>\n",
       "      <td>0.54</td>\n",
       "      <td>0.49</td>\n",
       "      <td>0.45</td>\n",
       "      <td>0.017306</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>683:22</td>\n",
       "      <td>k_nearest_neighbor</td>\n",
       "      <td>0.77</td>\n",
       "      <td>0.81</td>\n",
       "      <td>0.76</td>\n",
       "      <td>0.76</td>\n",
       "      <td>0.002051</td>\n",
       "      <td>0.025016</td>\n",
       "      <td>7.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32</th>\n",
       "      <td>0.02</td>\n",
       "      <td>690.0</td>\n",
       "      <td>15.0</td>\n",
       "      <td>690:15</td>\n",
       "      <td>naive_bayes</td>\n",
       "      <td>0.60</td>\n",
       "      <td>0.65</td>\n",
       "      <td>0.60</td>\n",
       "      <td>0.56</td>\n",
       "      <td>0.018635</td>\n",
       "      <td>0.000251</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>KNN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>33</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>690:15</td>\n",
       "      <td>k_nearest_neighbor</td>\n",
       "      <td>1.00</td>\n",
       "      <td>1.00</td>\n",
       "      <td>1.00</td>\n",
       "      <td>1.00</td>\n",
       "      <td>0.002551</td>\n",
       "      <td>0.024966</td>\n",
       "      <td>7.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>34</th>\n",
       "      <td>0.01</td>\n",
       "      <td>697.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>697:8</td>\n",
       "      <td>naive_bayes</td>\n",
       "      <td>0.62</td>\n",
       "      <td>0.63</td>\n",
       "      <td>0.60</td>\n",
       "      <td>0.56</td>\n",
       "      <td>0.019062</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>35</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>697:8</td>\n",
       "      <td>k_nearest_neighbor</td>\n",
       "      <td>1.00</td>\n",
       "      <td>1.00</td>\n",
       "      <td>1.00</td>\n",
       "      <td>1.00</td>\n",
       "      <td>0.003400</td>\n",
       "      <td>0.018389</td>\n",
       "      <td>7.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    testing  data_latih  data_uji latih_uji               model  akurasi  \\\n",
       "0      0.90        70.0     635.0    70:635         naive_bayes     0.47   \n",
       "1       NaN         NaN       NaN    70:635  k_nearest_neighbor     0.62   \n",
       "2      0.80       141.0     564.0   141:594         naive_bayes     0.51   \n",
       "3       NaN         NaN       NaN   141:594  k_nearest_neighbor     0.63   \n",
       "4      0.70       211.0     494.0   211:494         naive_bayes     0.55   \n",
       "5       NaN         NaN       NaN   211:494  k_nearest_neighbor     0.66   \n",
       "6      0.60       282.0     432.0   282:432         naive_bayes     0.51   \n",
       "7       NaN         NaN       NaN   282:432  k_nearest_neighbor     0.70   \n",
       "8      0.50       352.0     353.0   352:353         naive_bayes     0.54   \n",
       "9       NaN         NaN       NaN   352:353  k_nearest_neighbor     0.71   \n",
       "10     0.40       423.0     282.0   423:282         naive_bayes     0.51   \n",
       "11      NaN         NaN       NaN   423:282  k_nearest_neighbor     0.75   \n",
       "12     0.30       493.0     212.0   493:212         naive_bayes     0.65   \n",
       "13      NaN         NaN       NaN   493:212  k_nearest_neighbor     0.77   \n",
       "14     0.20       564.0     141.0   564:141         naive_bayes     0.65   \n",
       "15      NaN         NaN       NaN   564:141  k_nearest_neighbor     0.79   \n",
       "16     0.10       634.0      71.0    634:71         naive_bayes     0.63   \n",
       "17      NaN         NaN       NaN    634:71  k_nearest_neighbor     0.83   \n",
       "18     0.09       641.0      64.0    641:64         naive_bayes     0.62   \n",
       "19      NaN         NaN       NaN    641:64  k_nearest_neighbor     0.80   \n",
       "20     0.08       648.0      57.0    648:57         naive_bayes     0.63   \n",
       "21      NaN         NaN       NaN    648:57  k_nearest_neighbor     0.81   \n",
       "22     0.07       655.0      50.0    655:50         naive_bayes     0.60   \n",
       "23      NaN         NaN       NaN    655:50  k_nearest_neighbor     0.84   \n",
       "24     0.06       662.0      43.0    662:43         naive_bayes     0.60   \n",
       "25      NaN         NaN       NaN    662:43  k_nearest_neighbor     0.84   \n",
       "26     0.05       669.0      36.0    669:36         naive_bayes     0.61   \n",
       "27      NaN         NaN       NaN    669:36  k_nearest_neighbor     0.81   \n",
       "28     0.04       676.0      29.0    676:29         naive_bayes     0.55   \n",
       "29      NaN         NaN       NaN    676:29  k_nearest_neighbor     0.76   \n",
       "30     0.03       683.0      22.0    683:22         naive_bayes     0.50   \n",
       "31      NaN         NaN       NaN    683:22  k_nearest_neighbor     0.77   \n",
       "32     0.02       690.0      15.0    690:15         naive_bayes     0.60   \n",
       "33      NaN         NaN       NaN    690:15  k_nearest_neighbor     1.00   \n",
       "34     0.01       697.0       8.0     697:8         naive_bayes     0.62   \n",
       "35      NaN         NaN       NaN     697:8  k_nearest_neighbor     1.00   \n",
       "\n",
       "    presisi  recal    F1   w_latih     w_uji  k_knn  roc_auc Unnamed: 13  \n",
       "0      0.44   0.47  0.41  0.004090  0.002630    NaN      NaN         NaN  \n",
       "1      0.60   0.62  0.60  0.001189  0.105440    4.0      NaN         NaN  \n",
       "2      0.51   0.51  0.45  0.008121  0.002256    NaN      NaN         NaN  \n",
       "3      0.63   0.63  0.63  0.001047  0.093908    3.0      NaN         NaN  \n",
       "4      0.51   0.55  0.48  0.008355  0.000000    NaN      NaN         NaN  \n",
       "5      0.66   0.66  0.66  0.001281  0.070467    3.0      NaN         NaN  \n",
       "6      0.53   0.51  0.46  0.008337  0.001994    NaN      NaN         NaN  \n",
       "7      0.71   0.70  0.69  0.001401  0.072488    3.0      NaN         NaN  \n",
       "8      0.54   0.54  0.54  0.008823  0.000000    NaN      NaN         NaN  \n",
       "9      0.72   0.71  0.70  0.001383  0.070567    4.0      NaN         NaN  \n",
       "10     0.50   0.51  0.45  0.008008  0.000000    NaN      NaN         NaN  \n",
       "11     0.75   0.75  0.73  0.000000  0.069703    4.0      NaN         NaN  \n",
       "12     0.65   0.65  0.62  0.009819  0.001983    NaN      NaN         NaN  \n",
       "13     0.77   0.77  0.77  0.001301  0.064058    4.0      NaN         NaN  \n",
       "14     0.70   0.65  0.62  0.009426  0.000000    NaN      NaN          NV  \n",
       "15     0.79   0.79  0.78  0.000000  0.055702    4.0      NaN         NaN  \n",
       "16     0.63   0.63  0.59  0.009813  0.000000    NaN      NaN         NaN  \n",
       "17     0.83   0.83  0.82  0.001507  0.044852    4.0      NaN         NaN  \n",
       "18     0.71   0.62  0.59  0.009722  0.000000    NaN      NaN         NaN  \n",
       "19     0.79   0.79  0.79  0.002041  0.046776    6.0      NaN         NaN  \n",
       "20     0.71   0.63  0.60  0.013452  0.000000    NaN      NaN         NaN  \n",
       "21     0.80   0.80  0.80  0.002641  0.037296    6.0      NaN         NaN  \n",
       "22     0.69   0.60  0.55  0.012512  0.000000    NaN      NaN         NaN  \n",
       "23     0.84   0.84  0.84  0.002730  0.029474    6.0      NaN         NaN  \n",
       "24     0.70   0.61  0.56  0.014257  0.000000    NaN      NaN         NaN  \n",
       "25     0.84   0.83  0.83  0.002500  0.028498    6.0      NaN         NaN  \n",
       "26     0.69   0.60  0.57  0.015503  0.000000    NaN      NaN         NaN  \n",
       "27     0.81   0.80  0.80  0.002558  0.025552    6.0      NaN         NaN  \n",
       "28     0.62   0.55  0.51  0.016332  0.000171    NaN      NaN         NaN  \n",
       "29     0.75   0.75  0.75  0.002468  0.025420    6.0      NaN         NaN  \n",
       "30     0.54   0.49  0.45  0.017306  0.000000    NaN      NaN         NaN  \n",
       "31     0.81   0.76  0.76  0.002051  0.025016    7.0      NaN         NaN  \n",
       "32     0.65   0.60  0.56  0.018635  0.000251    NaN      NaN         KNN  \n",
       "33     1.00   1.00  1.00  0.002551  0.024966    7.0      NaN         NaN  \n",
       "34     0.63   0.60  0.56  0.019062  0.000000    NaN      NaN         NaN  \n",
       "35     1.00   1.00  1.00  0.003400  0.018389    7.0      NaN         NaN  "
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dataperbandingan = pd.read_excel('dataset/smote_perbandingan.xlsx')\n",
    "dataperbandingan"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "53e49972",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 99820 characters]",
      "text/plain": [
       "<Figure size 1200x500 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "sns.set_style(\"whitegrid\")\n",
    "plt.figure(figsize=(12, 5))\n",
    "\n",
    "colors = {'naive_bayes': '#FF9800', 'k_nearest_neighbor': '#F7C566'}\n",
    "sns.lineplot(x='latih_uji', y='akurasi', hue='model', data=dataperbandingan, markers=True, palette=colors)\n",
    "sns.scatterplot(x='latih_uji', y='akurasi', hue='model', data=dataperbandingan, marker='o', s=40, legend=False, palette=colors)\n",
    "\n",
    "plt.grid(alpha=0.4)\n",
    "plt.title('Akurasi Berdasarkan Rasio Data Latih dan Data Uji Setiap Model Klasifikasi')\n",
    "plt.xlabel('Perbandingan Data Latih dan Data Uji')\n",
    "plt.xticks(rotation=30, ha='right')\n",
    "plt.ylabel('Akurasi')\n",
    "plt.legend(title='Model')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "id": "35ea8c4b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 101708 characters]",
      "text/plain": [
       "<Figure size 1200x500 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "sns.set_style(\"whitegrid\")\n",
    "plt.figure(figsize=(12, 5))\n",
    "\n",
    "colors = {'naive_bayes': '#FF9800', 'k_nearest_neighbor': '#F7C566'}\n",
    "sns.lineplot(x='latih_uji', y='presisi', hue='model', data=dataperbandingan, markers=True, palette=colors)\n",
    "sns.scatterplot(x='latih_uji', y='presisi', hue='model', data=dataperbandingan, marker='o', s=40, legend=False, palette=colors)\n",
    "\n",
    "plt.grid(alpha=0.4)\n",
    "plt.title('Presisi Berdasarkan Rasio Data Latih dan Data Uji Setiap Model Klasifikasi')\n",
    "plt.xlabel('Perbandingan Data Latih dan Data Uji')\n",
    "plt.xticks(rotation=30, ha='right')\n",
    "plt.ylabel('Presisi')\n",
    "plt.legend(title='Model')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "d95a268b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 100940 characters]",
      "text/plain": [
       "<Figure size 1200x500 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "sns.set_style(\"whitegrid\")\n",
    "plt.figure(figsize=(12, 5))\n",
    "\n",
    "colors = {'naive_bayes': '#FF9800', 'k_nearest_neighbor': '#F7C566'}\n",
    "sns.lineplot(x='latih_uji', y='recal', hue='model', data=dataperbandingan, markers=True, palette=colors)\n",
    "sns.scatterplot(x='latih_uji', y='recal', hue='model', data=dataperbandingan, marker='o', s=40, legend=False, palette=colors)\n",
    "\n",
    "plt.grid(alpha=0.4)\n",
    "plt.title('Recal Berdasarkan Rasio Data Latih dan Data Uji Setiap Model Klasifikasi')\n",
    "plt.xlabel('Perbandingan Data Latih dan Data Uji')\n",
    "plt.xticks(rotation=30, ha='right')\n",
    "plt.ylabel('Recal')\n",
    "plt.legend(title='Model')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "id": "da7fd90e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 101912 characters]",
      "text/plain": [
       "<Figure size 1200x500 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "sns.set_style(\"whitegrid\")\n",
    "plt.figure(figsize=(12, 5))\n",
    "\n",
    "colors = {'naive_bayes': '#FF9800', 'k_nearest_neighbor': '#F7C566'}\n",
    "sns.lineplot(x='latih_uji', y='F1', hue='model', data=dataperbandingan, markers=True, palette=colors)\n",
    "sns.scatterplot(x='latih_uji', y='F1', hue='model', data=dataperbandingan, marker='o', s=40, legend=False, palette=colors)\n",
    "\n",
    "plt.grid(alpha=0.4)\n",
    "plt.title('Skor F1 Berdasarkan Rasio Data Latih dan Data Uji Setiap Model Klasifikasi')\n",
    "plt.xlabel('Perbandingan Data Latih dan Data Uji')\n",
    "plt.xticks(rotation=30, ha='right')\n",
    "plt.ylabel('Skor F1')\n",
    "plt.legend(title='Model')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "id": "0de27e9b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 108428 characters]",
      "text/plain": [
       "<Figure size 1200x500 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "sns.set_style(\"whitegrid\")\n",
    "plt.figure(figsize=(12, 5))\n",
    "\n",
    "colors = {'naive_bayes': '#FF9800', 'k_nearest_neighbor': '#F7C566'}\n",
    "sns.lineplot(x='latih_uji', y='w_latih', hue='model', data=dataperbandingan, markers=True, palette=colors)\n",
    "sns.scatterplot(x='latih_uji', y='w_latih', hue='model', data=dataperbandingan, marker='o', s=40, legend=False, palette=colors)\n",
    "\n",
    "plt.grid(alpha=0.4)\n",
    "plt.title('Waktu Pelatihan Berdasarkan Rasio Data Latih dan Data Uji Setiap Model Klasifikasi')\n",
    "plt.xlabel('Perbandingan Data Latih dan Data Uji')\n",
    "plt.xticks(rotation=30, ha='right')\n",
    "plt.ylabel('Waktu Pelatihan')\n",
    "plt.legend(title='Model')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "id": "2472d6ad",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 97884 characters]",
      "text/plain": [
       "<Figure size 1200x500 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "sns.set_style(\"whitegrid\")\n",
    "plt.figure(figsize=(12, 5))\n",
    "\n",
    "colors = {'naive_bayes': '#FF9800', 'k_nearest_neighbor': '#F7C566'}\n",
    "sns.lineplot(x='latih_uji', y='w_uji', hue='model', data=dataperbandingan, markers=True, palette=colors)\n",
    "sns.scatterplot(x='latih_uji', y='w_uji', hue='model', data=dataperbandingan, marker='o', s=40, legend=False, palette=colors)\n",
    "\n",
    "plt.grid(alpha=0.4)\n",
    "plt.title('Waktu Pengujian Berdasarkan Rasio Data Latih dan Data Uji Setiap Model Klasifikasi')\n",
    "plt.xlabel('Perbandingan Data Latih dan Data Uji')\n",
    "plt.xticks(rotation=30, ha='right')\n",
    "plt.ylabel('Waktu Pengujian')\n",
    "plt.legend(title='Model')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4e1136a4",
   "metadata": {},
   "source": [
    "## Analisis perbandingan hasil setiap algoritma"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "id": "5400e172",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 139428 characters]",
      "text/plain": [
       "<Figure size 1200x500 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "NV = dataperbandingan[dataperbandingan['model'] == 'naive_bayes']\n",
    "\n",
    "sns.set_style(\"whitegrid\")\n",
    "plt.figure(figsize=(12, 5))\n",
    "\n",
    "plt.plot(NV['latih_uji'], NV['akurasi'], 'o-',  markersize=4, color = '#E81416', label='Akurasi')\n",
    "plt.plot(NV['latih_uji'], NV['presisi'], 'o-', markersize=4, color='#FFA500', label='Presisi')\n",
    "plt.plot(NV['latih_uji'], NV['recal'], 'o-', markersize=4, color='#FAEB36', label='Recal')\n",
    "plt.plot(NV['latih_uji'], NV['F1'], 'o-', markersize=4, color='#79C314', label='Skor F1')\n",
    "\n",
    "plt.legend()\n",
    "plt.grid(alpha=0.4)\n",
    "plt.title(\"Hasil Kinerja Naive Bayes untuk Rasio Data 2089:22\")\n",
    "plt.xlabel('Perbandingan Data Latih dan Data Uji')\n",
    "plt.xticks(rotation=30, ha='right')\n",
    "plt.ylabel('Nilai Kinerja')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "id": "5a242758",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 113368 characters]",
      "text/plain": [
       "<Figure size 1200x500 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "KNN = dataperbandingan[dataperbandingan['model'] == 'k_nearest_neighbor']\n",
    "\n",
    "sns.set_style(\"whitegrid\")\n",
    "plt.figure(figsize=(12, 5))\n",
    "\n",
    "plt.plot(KNN['latih_uji'], KNN['akurasi'], 'o-',  markersize=4, color = '#E81416', label='Akurasi')\n",
    "plt.plot(KNN['latih_uji'], KNN['presisi'], 'o-', markersize=4, color='#FFA500', label='Presisi')\n",
    "plt.plot(KNN['latih_uji'], KNN['recal'], 'o-', markersize=4, color='#FAEB36', label='Recal')\n",
    "plt.plot(KNN['latih_uji'], KNN['F1'], 'o-', markersize=4, color='#79C314', label='Skor F1')\n",
    "\n",
    "plt.legend()\n",
    "plt.grid(alpha=0.4)\n",
    "plt.title(\"Hasil Kinerja K-Nearest Neighbor untuk Rasio Data 2089:22\")\n",
    "plt.xlabel('Perbandingan Data Latih dan Data Uji')\n",
    "plt.xticks(rotation=30, ha='right')\n",
    "plt.ylabel('Nilai Kinerja')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ca3aefeb",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f6156b09",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python (tugasakhir)",
   "language": "python",
   "name": "myenvtugasakhir"
  },
  "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.11.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
