{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "ef7e2426",
   "metadata": {},
   "source": [
    "# PREPROCESSING"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "3e039183",
   "metadata": {
    "scrolled": true
   },
   "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",
    "\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.metrics import accuracy_score, precision_score, recall_score, f1_score\n",
    "from sklearn.metrics import classification_report\n",
    "from sklearn.metrics import confusion_matrix\n",
    "from sklearn.metrics import roc_curve,auc\n",
    "from sklearn.metrics import roc_auc_score\n",
    "from sklearn.neighbors import KNeighborsClassifier\n",
    "from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "779fc4f9",
   "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>Gender</th>\n",
       "      <th>Age</th>\n",
       "      <th>Height</th>\n",
       "      <th>Weight</th>\n",
       "      <th>family_history_with_overweight</th>\n",
       "      <th>FAVC</th>\n",
       "      <th>FCVC</th>\n",
       "      <th>NCP</th>\n",
       "      <th>CAEC</th>\n",
       "      <th>SMOKE</th>\n",
       "      <th>CH2O</th>\n",
       "      <th>SCC</th>\n",
       "      <th>FAF</th>\n",
       "      <th>TUE</th>\n",
       "      <th>CALC</th>\n",
       "      <th>MTRANS</th>\n",
       "      <th>NObeyesdad</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Female</td>\n",
       "      <td>21.000000</td>\n",
       "      <td>1.620000</td>\n",
       "      <td>64.000000</td>\n",
       "      <td>yes</td>\n",
       "      <td>no</td>\n",
       "      <td>2.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>no</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>no</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>no</td>\n",
       "      <td>Public_Transportation</td>\n",
       "      <td>Normal_Weight</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Female</td>\n",
       "      <td>21.000000</td>\n",
       "      <td>1.520000</td>\n",
       "      <td>56.000000</td>\n",
       "      <td>yes</td>\n",
       "      <td>no</td>\n",
       "      <td>3.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>yes</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>yes</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>Public_Transportation</td>\n",
       "      <td>Normal_Weight</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Male</td>\n",
       "      <td>23.000000</td>\n",
       "      <td>1.800000</td>\n",
       "      <td>77.000000</td>\n",
       "      <td>yes</td>\n",
       "      <td>no</td>\n",
       "      <td>2.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>no</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>no</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>Frequently</td>\n",
       "      <td>Public_Transportation</td>\n",
       "      <td>Normal_Weight</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Male</td>\n",
       "      <td>27.000000</td>\n",
       "      <td>1.800000</td>\n",
       "      <td>87.000000</td>\n",
       "      <td>no</td>\n",
       "      <td>no</td>\n",
       "      <td>3.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>no</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>no</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>Frequently</td>\n",
       "      <td>Walking</td>\n",
       "      <td>Overweight_Level_I</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Male</td>\n",
       "      <td>22.000000</td>\n",
       "      <td>1.780000</td>\n",
       "      <td>89.800000</td>\n",
       "      <td>no</td>\n",
       "      <td>no</td>\n",
       "      <td>2.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>no</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>no</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>Public_Transportation</td>\n",
       "      <td>Overweight_Level_II</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>2106</th>\n",
       "      <td>Female</td>\n",
       "      <td>20.976842</td>\n",
       "      <td>1.710730</td>\n",
       "      <td>131.408528</td>\n",
       "      <td>yes</td>\n",
       "      <td>yes</td>\n",
       "      <td>3.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>no</td>\n",
       "      <td>1.728139</td>\n",
       "      <td>no</td>\n",
       "      <td>1.676269</td>\n",
       "      <td>0.906247</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>Public_Transportation</td>\n",
       "      <td>Obesity_Type_III</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2107</th>\n",
       "      <td>Female</td>\n",
       "      <td>21.982942</td>\n",
       "      <td>1.748584</td>\n",
       "      <td>133.742943</td>\n",
       "      <td>yes</td>\n",
       "      <td>yes</td>\n",
       "      <td>3.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>no</td>\n",
       "      <td>2.005130</td>\n",
       "      <td>no</td>\n",
       "      <td>1.341390</td>\n",
       "      <td>0.599270</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>Public_Transportation</td>\n",
       "      <td>Obesity_Type_III</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2108</th>\n",
       "      <td>Female</td>\n",
       "      <td>22.524036</td>\n",
       "      <td>1.752206</td>\n",
       "      <td>133.689352</td>\n",
       "      <td>yes</td>\n",
       "      <td>yes</td>\n",
       "      <td>3.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>no</td>\n",
       "      <td>2.054193</td>\n",
       "      <td>no</td>\n",
       "      <td>1.414209</td>\n",
       "      <td>0.646288</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>Public_Transportation</td>\n",
       "      <td>Obesity_Type_III</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2109</th>\n",
       "      <td>Female</td>\n",
       "      <td>24.361936</td>\n",
       "      <td>1.739450</td>\n",
       "      <td>133.346641</td>\n",
       "      <td>yes</td>\n",
       "      <td>yes</td>\n",
       "      <td>3.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>no</td>\n",
       "      <td>2.852339</td>\n",
       "      <td>no</td>\n",
       "      <td>1.139107</td>\n",
       "      <td>0.586035</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>Public_Transportation</td>\n",
       "      <td>Obesity_Type_III</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2110</th>\n",
       "      <td>Female</td>\n",
       "      <td>23.664709</td>\n",
       "      <td>1.738836</td>\n",
       "      <td>133.472641</td>\n",
       "      <td>yes</td>\n",
       "      <td>yes</td>\n",
       "      <td>3.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>no</td>\n",
       "      <td>2.863513</td>\n",
       "      <td>no</td>\n",
       "      <td>1.026452</td>\n",
       "      <td>0.714137</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>Public_Transportation</td>\n",
       "      <td>Obesity_Type_III</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>2111 rows × 17 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      Gender        Age    Height      Weight family_history_with_overweight  \\\n",
       "0     Female  21.000000  1.620000   64.000000                            yes   \n",
       "1     Female  21.000000  1.520000   56.000000                            yes   \n",
       "2       Male  23.000000  1.800000   77.000000                            yes   \n",
       "3       Male  27.000000  1.800000   87.000000                             no   \n",
       "4       Male  22.000000  1.780000   89.800000                             no   \n",
       "...      ...        ...       ...         ...                            ...   \n",
       "2106  Female  20.976842  1.710730  131.408528                            yes   \n",
       "2107  Female  21.982942  1.748584  133.742943                            yes   \n",
       "2108  Female  22.524036  1.752206  133.689352                            yes   \n",
       "2109  Female  24.361936  1.739450  133.346641                            yes   \n",
       "2110  Female  23.664709  1.738836  133.472641                            yes   \n",
       "\n",
       "     FAVC  FCVC  NCP       CAEC SMOKE      CH2O  SCC       FAF       TUE  \\\n",
       "0      no   2.0  3.0  Sometimes    no  2.000000   no  0.000000  1.000000   \n",
       "1      no   3.0  3.0  Sometimes   yes  3.000000  yes  3.000000  0.000000   \n",
       "2      no   2.0  3.0  Sometimes    no  2.000000   no  2.000000  1.000000   \n",
       "3      no   3.0  3.0  Sometimes    no  2.000000   no  2.000000  0.000000   \n",
       "4      no   2.0  1.0  Sometimes    no  2.000000   no  0.000000  0.000000   \n",
       "...   ...   ...  ...        ...   ...       ...  ...       ...       ...   \n",
       "2106  yes   3.0  3.0  Sometimes    no  1.728139   no  1.676269  0.906247   \n",
       "2107  yes   3.0  3.0  Sometimes    no  2.005130   no  1.341390  0.599270   \n",
       "2108  yes   3.0  3.0  Sometimes    no  2.054193   no  1.414209  0.646288   \n",
       "2109  yes   3.0  3.0  Sometimes    no  2.852339   no  1.139107  0.586035   \n",
       "2110  yes   3.0  3.0  Sometimes    no  2.863513   no  1.026452  0.714137   \n",
       "\n",
       "            CALC                 MTRANS           NObeyesdad  \n",
       "0             no  Public_Transportation        Normal_Weight  \n",
       "1      Sometimes  Public_Transportation        Normal_Weight  \n",
       "2     Frequently  Public_Transportation        Normal_Weight  \n",
       "3     Frequently                Walking   Overweight_Level_I  \n",
       "4      Sometimes  Public_Transportation  Overweight_Level_II  \n",
       "...          ...                    ...                  ...  \n",
       "2106   Sometimes  Public_Transportation     Obesity_Type_III  \n",
       "2107   Sometimes  Public_Transportation     Obesity_Type_III  \n",
       "2108   Sometimes  Public_Transportation     Obesity_Type_III  \n",
       "2109   Sometimes  Public_Transportation     Obesity_Type_III  \n",
       "2110   Sometimes  Public_Transportation     Obesity_Type_III  \n",
       "\n",
       "[2111 rows x 17 columns]"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = pd.read_csv('dataset/ObesityDataSet_raw_and_data_sinthetic.csv')\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "6a28ed66",
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 2111 entries, 0 to 2110\n",
      "Data columns (total 17 columns):\n",
      " #   Column                          Non-Null Count  Dtype  \n",
      "---  ------                          --------------  -----  \n",
      " 0   Gender                          2111 non-null   object \n",
      " 1   Age                             2111 non-null   float64\n",
      " 2   Height                          2111 non-null   float64\n",
      " 3   Weight                          2111 non-null   float64\n",
      " 4   family_history_with_overweight  2111 non-null   object \n",
      " 5   FAVC                            2111 non-null   object \n",
      " 6   FCVC                            2111 non-null   float64\n",
      " 7   NCP                             2111 non-null   float64\n",
      " 8   CAEC                            2111 non-null   object \n",
      " 9   SMOKE                           2111 non-null   object \n",
      " 10  CH2O                            2111 non-null   float64\n",
      " 11  SCC                             2111 non-null   object \n",
      " 12  FAF                             2111 non-null   float64\n",
      " 13  TUE                             2111 non-null   float64\n",
      " 14  CALC                            2111 non-null   object \n",
      " 15  MTRANS                          2111 non-null   object \n",
      " 16  NObeyesdad                      2111 non-null   object \n",
      "dtypes: float64(8), object(9)\n",
      "memory usage: 280.5+ KB\n"
     ]
    }
   ],
   "source": [
    "data.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "355e9726",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "renameColomn = data.rename(columns = \n",
    "                           {'Gender':'gender',\n",
    "                            'Age':'age',\n",
    "                            'Height':'height_meter',\n",
    "                            'Weight':'weight_kilogram',\n",
    "                            'FAVC':'consumption_high_calorie',\n",
    "                            'FCVC':'consumption_vegetables',\n",
    "                            'NCP':'heavy_meal',\n",
    "                            'CAEC':'eat_food_in_between_meals',\n",
    "                            'SMOKE':'smoke',\n",
    "                            'CH2O':'consumption_water_liter',\n",
    "                            'SCC':'food_calorie_monitoring',\n",
    "                            'FAF':'physical_activity',\n",
    "                            'TUE':'duration_technological_devices',\n",
    "                            'CALC':'consumption_alcohol',\n",
    "                            'MTRANS':'commonly_used_transportation',\n",
    "                            'NObeyesdad':'obesity_class'}, inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "3153d950",
   "metadata": {
    "scrolled": false
   },
   "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>gender</th>\n",
       "      <th>age</th>\n",
       "      <th>height_meter</th>\n",
       "      <th>weight_kilogram</th>\n",
       "      <th>family_history_with_overweight</th>\n",
       "      <th>consumption_high_calorie</th>\n",
       "      <th>consumption_vegetables</th>\n",
       "      <th>heavy_meal</th>\n",
       "      <th>eat_food_in_between_meals</th>\n",
       "      <th>smoke</th>\n",
       "      <th>consumption_water_liter</th>\n",
       "      <th>food_calorie_monitoring</th>\n",
       "      <th>physical_activity</th>\n",
       "      <th>duration_technological_devices</th>\n",
       "      <th>consumption_alcohol</th>\n",
       "      <th>commonly_used_transportation</th>\n",
       "      <th>obesity_class</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Female</td>\n",
       "      <td>21.000000</td>\n",
       "      <td>1.620000</td>\n",
       "      <td>64.000000</td>\n",
       "      <td>yes</td>\n",
       "      <td>no</td>\n",
       "      <td>2.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>no</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>no</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>no</td>\n",
       "      <td>Public_Transportation</td>\n",
       "      <td>Normal_Weight</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Female</td>\n",
       "      <td>21.000000</td>\n",
       "      <td>1.520000</td>\n",
       "      <td>56.000000</td>\n",
       "      <td>yes</td>\n",
       "      <td>no</td>\n",
       "      <td>3.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>yes</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>yes</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>Public_Transportation</td>\n",
       "      <td>Normal_Weight</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Male</td>\n",
       "      <td>23.000000</td>\n",
       "      <td>1.800000</td>\n",
       "      <td>77.000000</td>\n",
       "      <td>yes</td>\n",
       "      <td>no</td>\n",
       "      <td>2.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>no</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>no</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>Frequently</td>\n",
       "      <td>Public_Transportation</td>\n",
       "      <td>Normal_Weight</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Male</td>\n",
       "      <td>27.000000</td>\n",
       "      <td>1.800000</td>\n",
       "      <td>87.000000</td>\n",
       "      <td>no</td>\n",
       "      <td>no</td>\n",
       "      <td>3.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>no</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>no</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>Frequently</td>\n",
       "      <td>Walking</td>\n",
       "      <td>Overweight_Level_I</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Male</td>\n",
       "      <td>22.000000</td>\n",
       "      <td>1.780000</td>\n",
       "      <td>89.800000</td>\n",
       "      <td>no</td>\n",
       "      <td>no</td>\n",
       "      <td>2.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>no</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>no</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>Public_Transportation</td>\n",
       "      <td>Overweight_Level_II</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>2106</th>\n",
       "      <td>Female</td>\n",
       "      <td>20.976842</td>\n",
       "      <td>1.710730</td>\n",
       "      <td>131.408528</td>\n",
       "      <td>yes</td>\n",
       "      <td>yes</td>\n",
       "      <td>3.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>no</td>\n",
       "      <td>1.728139</td>\n",
       "      <td>no</td>\n",
       "      <td>1.676269</td>\n",
       "      <td>0.906247</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>Public_Transportation</td>\n",
       "      <td>Obesity_Type_III</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2107</th>\n",
       "      <td>Female</td>\n",
       "      <td>21.982942</td>\n",
       "      <td>1.748584</td>\n",
       "      <td>133.742943</td>\n",
       "      <td>yes</td>\n",
       "      <td>yes</td>\n",
       "      <td>3.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>no</td>\n",
       "      <td>2.005130</td>\n",
       "      <td>no</td>\n",
       "      <td>1.341390</td>\n",
       "      <td>0.599270</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>Public_Transportation</td>\n",
       "      <td>Obesity_Type_III</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2108</th>\n",
       "      <td>Female</td>\n",
       "      <td>22.524036</td>\n",
       "      <td>1.752206</td>\n",
       "      <td>133.689352</td>\n",
       "      <td>yes</td>\n",
       "      <td>yes</td>\n",
       "      <td>3.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>no</td>\n",
       "      <td>2.054193</td>\n",
       "      <td>no</td>\n",
       "      <td>1.414209</td>\n",
       "      <td>0.646288</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>Public_Transportation</td>\n",
       "      <td>Obesity_Type_III</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2109</th>\n",
       "      <td>Female</td>\n",
       "      <td>24.361936</td>\n",
       "      <td>1.739450</td>\n",
       "      <td>133.346641</td>\n",
       "      <td>yes</td>\n",
       "      <td>yes</td>\n",
       "      <td>3.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>no</td>\n",
       "      <td>2.852339</td>\n",
       "      <td>no</td>\n",
       "      <td>1.139107</td>\n",
       "      <td>0.586035</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>Public_Transportation</td>\n",
       "      <td>Obesity_Type_III</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2110</th>\n",
       "      <td>Female</td>\n",
       "      <td>23.664709</td>\n",
       "      <td>1.738836</td>\n",
       "      <td>133.472641</td>\n",
       "      <td>yes</td>\n",
       "      <td>yes</td>\n",
       "      <td>3.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>no</td>\n",
       "      <td>2.863513</td>\n",
       "      <td>no</td>\n",
       "      <td>1.026452</td>\n",
       "      <td>0.714137</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>Public_Transportation</td>\n",
       "      <td>Obesity_Type_III</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>2111 rows × 17 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      gender        age  height_meter  weight_kilogram  \\\n",
       "0     Female  21.000000      1.620000        64.000000   \n",
       "1     Female  21.000000      1.520000        56.000000   \n",
       "2       Male  23.000000      1.800000        77.000000   \n",
       "3       Male  27.000000      1.800000        87.000000   \n",
       "4       Male  22.000000      1.780000        89.800000   \n",
       "...      ...        ...           ...              ...   \n",
       "2106  Female  20.976842      1.710730       131.408528   \n",
       "2107  Female  21.982942      1.748584       133.742943   \n",
       "2108  Female  22.524036      1.752206       133.689352   \n",
       "2109  Female  24.361936      1.739450       133.346641   \n",
       "2110  Female  23.664709      1.738836       133.472641   \n",
       "\n",
       "     family_history_with_overweight consumption_high_calorie  \\\n",
       "0                               yes                       no   \n",
       "1                               yes                       no   \n",
       "2                               yes                       no   \n",
       "3                                no                       no   \n",
       "4                                no                       no   \n",
       "...                             ...                      ...   \n",
       "2106                            yes                      yes   \n",
       "2107                            yes                      yes   \n",
       "2108                            yes                      yes   \n",
       "2109                            yes                      yes   \n",
       "2110                            yes                      yes   \n",
       "\n",
       "      consumption_vegetables  heavy_meal eat_food_in_between_meals smoke  \\\n",
       "0                        2.0         3.0                 Sometimes    no   \n",
       "1                        3.0         3.0                 Sometimes   yes   \n",
       "2                        2.0         3.0                 Sometimes    no   \n",
       "3                        3.0         3.0                 Sometimes    no   \n",
       "4                        2.0         1.0                 Sometimes    no   \n",
       "...                      ...         ...                       ...   ...   \n",
       "2106                     3.0         3.0                 Sometimes    no   \n",
       "2107                     3.0         3.0                 Sometimes    no   \n",
       "2108                     3.0         3.0                 Sometimes    no   \n",
       "2109                     3.0         3.0                 Sometimes    no   \n",
       "2110                     3.0         3.0                 Sometimes    no   \n",
       "\n",
       "      consumption_water_liter food_calorie_monitoring  physical_activity  \\\n",
       "0                    2.000000                      no           0.000000   \n",
       "1                    3.000000                     yes           3.000000   \n",
       "2                    2.000000                      no           2.000000   \n",
       "3                    2.000000                      no           2.000000   \n",
       "4                    2.000000                      no           0.000000   \n",
       "...                       ...                     ...                ...   \n",
       "2106                 1.728139                      no           1.676269   \n",
       "2107                 2.005130                      no           1.341390   \n",
       "2108                 2.054193                      no           1.414209   \n",
       "2109                 2.852339                      no           1.139107   \n",
       "2110                 2.863513                      no           1.026452   \n",
       "\n",
       "      duration_technological_devices consumption_alcohol  \\\n",
       "0                           1.000000                  no   \n",
       "1                           0.000000           Sometimes   \n",
       "2                           1.000000          Frequently   \n",
       "3                           0.000000          Frequently   \n",
       "4                           0.000000           Sometimes   \n",
       "...                              ...                 ...   \n",
       "2106                        0.906247           Sometimes   \n",
       "2107                        0.599270           Sometimes   \n",
       "2108                        0.646288           Sometimes   \n",
       "2109                        0.586035           Sometimes   \n",
       "2110                        0.714137           Sometimes   \n",
       "\n",
       "     commonly_used_transportation        obesity_class  \n",
       "0           Public_Transportation        Normal_Weight  \n",
       "1           Public_Transportation        Normal_Weight  \n",
       "2           Public_Transportation        Normal_Weight  \n",
       "3                         Walking   Overweight_Level_I  \n",
       "4           Public_Transportation  Overweight_Level_II  \n",
       "...                           ...                  ...  \n",
       "2106        Public_Transportation     Obesity_Type_III  \n",
       "2107        Public_Transportation     Obesity_Type_III  \n",
       "2108        Public_Transportation     Obesity_Type_III  \n",
       "2109        Public_Transportation     Obesity_Type_III  \n",
       "2110        Public_Transportation     Obesity_Type_III  \n",
       "\n",
       "[2111 rows x 17 columns]"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "e5779e6e",
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 2111 entries, 0 to 2110\n",
      "Data columns (total 17 columns):\n",
      " #   Column                          Non-Null Count  Dtype  \n",
      "---  ------                          --------------  -----  \n",
      " 0   gender                          2111 non-null   object \n",
      " 1   age                             2111 non-null   float64\n",
      " 2   height_meter                    2111 non-null   float64\n",
      " 3   weight_kilogram                 2111 non-null   float64\n",
      " 4   family_history_with_overweight  2111 non-null   object \n",
      " 5   consumption_high_calorie        2111 non-null   object \n",
      " 6   consumption_vegetables          2111 non-null   float64\n",
      " 7   heavy_meal                      2111 non-null   float64\n",
      " 8   eat_food_in_between_meals       2111 non-null   object \n",
      " 9   smoke                           2111 non-null   object \n",
      " 10  consumption_water_liter         2111 non-null   float64\n",
      " 11  food_calorie_monitoring         2111 non-null   object \n",
      " 12  physical_activity               2111 non-null   float64\n",
      " 13  duration_technological_devices  2111 non-null   float64\n",
      " 14  consumption_alcohol             2111 non-null   object \n",
      " 15  commonly_used_transportation    2111 non-null   object \n",
      " 16  obesity_class                   2111 non-null   object \n",
      "dtypes: float64(8), object(9)\n",
      "memory usage: 280.5+ KB\n"
     ]
    }
   ],
   "source": [
    "data.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "ea763a7e",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(2111, 17)"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b5f12fa5",
   "metadata": {},
   "source": [
    "### balance class "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "33065691",
   "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>obesity_class</th>\n",
       "      <th>jumlah</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Obesity_Type_I</td>\n",
       "      <td>351</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Obesity_Type_III</td>\n",
       "      <td>324</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Obesity_Type_II</td>\n",
       "      <td>297</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Overweight_Level_I</td>\n",
       "      <td>290</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Overweight_Level_II</td>\n",
       "      <td>290</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>Normal_Weight</td>\n",
       "      <td>287</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>Insufficient_Weight</td>\n",
       "      <td>272</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         obesity_class  jumlah\n",
       "0       Obesity_Type_I     351\n",
       "1     Obesity_Type_III     324\n",
       "2      Obesity_Type_II     297\n",
       "3   Overweight_Level_I     290\n",
       "4  Overweight_Level_II     290\n",
       "5        Normal_Weight     287\n",
       "6  Insufficient_Weight     272"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "kelas_obesitas = data['obesity_class'].value_counts().rename_axis('obesity_class').reset_index(name='jumlah')\n",
    "kelas_obesitas"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "66ce700c",
   "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>obesity_class</th>\n",
       "      <th>jumlah</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>Insufficient_Weight</td>\n",
       "      <td>272</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>Normal_Weight</td>\n",
       "      <td>287</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Overweight_Level_I</td>\n",
       "      <td>290</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Overweight_Level_II</td>\n",
       "      <td>290</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Obesity_Type_I</td>\n",
       "      <td>351</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Obesity_Type_II</td>\n",
       "      <td>297</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Obesity_Type_III</td>\n",
       "      <td>324</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         obesity_class  jumlah\n",
       "6  Insufficient_Weight     272\n",
       "5        Normal_Weight     287\n",
       "3   Overweight_Level_I     290\n",
       "4  Overweight_Level_II     290\n",
       "0       Obesity_Type_I     351\n",
       "2      Obesity_Type_II     297\n",
       "1     Obesity_Type_III     324"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "urutan_obesitas = ['Insufficient_Weight',\n",
    "                'Normal_Weight',\n",
    "                'Overweight_Level_I',\n",
    "                'Overweight_Level_II',\n",
    "                'Obesity_Type_I',\n",
    "                'Obesity_Type_II',\n",
    "                'Obesity_Type_III']\n",
    "kelas_obesitas['obesity_class'] = pd.Categorical(kelas_obesitas['obesity_class'], categories=urutan_obesitas, ordered=True)\n",
    "kelas_obesitas = kelas_obesitas.sort_values(by='obesity_class')\n",
    "kelas_obesitas"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "593d7c58",
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 55112 characters]",
      "text/plain": [
       "<Figure size 500x500 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sns\n",
    "\n",
    "plt.figure(figsize=(5, 5))\n",
    "colors = sns.color_palette('pastel')\n",
    "\n",
    "plt.pie(kelas_obesitas['jumlah'], labels=kelas_obesitas['obesity_class'], autopct='%1.1f%%', colors=colors)\n",
    "\n",
    "plt.title('Perbandingan Persentase Kelas Obesitas')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b2ee997e",
   "metadata": {},
   "source": [
    "### transformasi"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "4f3bc22b",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "def change_value_vegetables(x):\n",
    "    if x <= 1:\n",
    "        return 0\n",
    "    elif x <= 2:\n",
    "        return 1\n",
    "    else:\n",
    "        return 2\n",
    "\n",
    "def change_value_meal(x):\n",
    "    if x <= 2:\n",
    "        return 1\n",
    "    elif x <= 3:\n",
    "        return 2\n",
    "    else:\n",
    "        return 3\n",
    "\n",
    "def change_value_water(x):\n",
    "    if x < 1:\n",
    "        return 1\n",
    "    elif x <= 2:\n",
    "        return 2\n",
    "    else:\n",
    "        return 3\n",
    "\n",
    "def change_value_technologi(x):\n",
    "    if x < 2:\n",
    "        return 1\n",
    "    elif x < 5:\n",
    "        return 2\n",
    "    else:\n",
    "        return 3\n",
    "\n",
    "data['consumption_vegetables'] = data['consumption_vegetables'].apply(change_value_vegetables)\n",
    "data['heavy_meal'] = data['heavy_meal'].apply(change_value_meal)\n",
    "data['consumption_water_liter'] = data['consumption_water_liter'].apply(change_value_water)\n",
    "data['duration_technological_devices'] = data['duration_technological_devices'].apply(change_value_technologi)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "55f99513",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "data['age'] = data['age'].astype('int64')\n",
    "data['physical_activity'] = data['physical_activity'].astype('int64')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "70710563",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "data['height_meter'] = data['height_meter'].apply(lambda x: round(x, 2))\n",
    "data['weight_kilogram'] = data['weight_kilogram'].apply(lambda x: round(x, 2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "b8bb5875",
   "metadata": {
    "scrolled": false
   },
   "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>gender</th>\n",
       "      <th>age</th>\n",
       "      <th>height_meter</th>\n",
       "      <th>weight_kilogram</th>\n",
       "      <th>family_history_with_overweight</th>\n",
       "      <th>consumption_high_calorie</th>\n",
       "      <th>consumption_vegetables</th>\n",
       "      <th>heavy_meal</th>\n",
       "      <th>eat_food_in_between_meals</th>\n",
       "      <th>smoke</th>\n",
       "      <th>consumption_water_liter</th>\n",
       "      <th>food_calorie_monitoring</th>\n",
       "      <th>physical_activity</th>\n",
       "      <th>duration_technological_devices</th>\n",
       "      <th>consumption_alcohol</th>\n",
       "      <th>commonly_used_transportation</th>\n",
       "      <th>obesity_class</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.00</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>Normal_Weight</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.00</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>Normal_Weight</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>23</td>\n",
       "      <td>1.80</td>\n",
       "      <td>77.00</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>2</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>Normal_Weight</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>27</td>\n",
       "      <td>1.80</td>\n",
       "      <td>87.00</td>\n",
       "      <td>0</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>2</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>Overweight_Level_I</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1</td>\n",
       "      <td>22</td>\n",
       "      <td>1.78</td>\n",
       "      <td>89.80</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</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>1</td>\n",
       "      <td>Overweight_Level_II</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>2106</th>\n",
       "      <td>0</td>\n",
       "      <td>20</td>\n",
       "      <td>1.71</td>\n",
       "      <td>131.41</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>1</td>\n",
       "      <td>Obesity_Type_III</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2107</th>\n",
       "      <td>0</td>\n",
       "      <td>21</td>\n",
       "      <td>1.75</td>\n",
       "      <td>133.74</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>1</td>\n",
       "      <td>Obesity_Type_III</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2108</th>\n",
       "      <td>0</td>\n",
       "      <td>22</td>\n",
       "      <td>1.75</td>\n",
       "      <td>133.69</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>1</td>\n",
       "      <td>Obesity_Type_III</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2109</th>\n",
       "      <td>0</td>\n",
       "      <td>24</td>\n",
       "      <td>1.74</td>\n",
       "      <td>133.35</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>1</td>\n",
       "      <td>Obesity_Type_III</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2110</th>\n",
       "      <td>0</td>\n",
       "      <td>23</td>\n",
       "      <td>1.74</td>\n",
       "      <td>133.47</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>1</td>\n",
       "      <td>Obesity_Type_III</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>2111 rows × 17 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      gender  age  height_meter  weight_kilogram  \\\n",
       "0          0   21          1.62            64.00   \n",
       "1          0   21          1.52            56.00   \n",
       "2          1   23          1.80            77.00   \n",
       "3          1   27          1.80            87.00   \n",
       "4          1   22          1.78            89.80   \n",
       "...      ...  ...           ...              ...   \n",
       "2106       0   20          1.71           131.41   \n",
       "2107       0   21          1.75           133.74   \n",
       "2108       0   22          1.75           133.69   \n",
       "2109       0   24          1.74           133.35   \n",
       "2110       0   23          1.74           133.47   \n",
       "\n",
       "      family_history_with_overweight  consumption_high_calorie  \\\n",
       "0                                  1                         0   \n",
       "1                                  1                         0   \n",
       "2                                  1                         0   \n",
       "3                                  0                         0   \n",
       "4                                  0                         0   \n",
       "...                              ...                       ...   \n",
       "2106                               1                         1   \n",
       "2107                               1                         1   \n",
       "2108                               1                         1   \n",
       "2109                               1                         1   \n",
       "2110                               1                         1   \n",
       "\n",
       "      consumption_vegetables  heavy_meal  eat_food_in_between_meals  smoke  \\\n",
       "0                          1           2                          1      0   \n",
       "1                          2           2                          1      1   \n",
       "2                          1           2                          1      0   \n",
       "3                          2           2                          1      0   \n",
       "4                          1           1                          1      0   \n",
       "...                      ...         ...                        ...    ...   \n",
       "2106                       2           2                          1      0   \n",
       "2107                       2           2                          1      0   \n",
       "2108                       2           2                          1      0   \n",
       "2109                       2           2                          1      0   \n",
       "2110                       2           2                          1      0   \n",
       "\n",
       "      consumption_water_liter  food_calorie_monitoring  physical_activity  \\\n",
       "0                           2                        0                  0   \n",
       "1                           3                        1                  3   \n",
       "2                           2                        0                  2   \n",
       "3                           2                        0                  2   \n",
       "4                           2                        0                  0   \n",
       "...                       ...                      ...                ...   \n",
       "2106                        2                        0                  1   \n",
       "2107                        3                        0                  1   \n",
       "2108                        3                        0                  1   \n",
       "2109                        3                        0                  1   \n",
       "2110                        3                        0                  1   \n",
       "\n",
       "      duration_technological_devices  consumption_alcohol  \\\n",
       "0                                  1                    0   \n",
       "1                                  1                    1   \n",
       "2                                  1                    2   \n",
       "3                                  1                    2   \n",
       "4                                  1                    1   \n",
       "...                              ...                  ...   \n",
       "2106                               1                    1   \n",
       "2107                               1                    1   \n",
       "2108                               1                    1   \n",
       "2109                               1                    1   \n",
       "2110                               1                    1   \n",
       "\n",
       "      commonly_used_transportation        obesity_class  \n",
       "0                                1        Normal_Weight  \n",
       "1                                1        Normal_Weight  \n",
       "2                                1        Normal_Weight  \n",
       "3                                0   Overweight_Level_I  \n",
       "4                                1  Overweight_Level_II  \n",
       "...                            ...                  ...  \n",
       "2106                             1     Obesity_Type_III  \n",
       "2107                             1     Obesity_Type_III  \n",
       "2108                             1     Obesity_Type_III  \n",
       "2109                             1     Obesity_Type_III  \n",
       "2110                             1     Obesity_Type_III  \n",
       "\n",
       "[2111 rows x 17 columns]"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data['gender'] = data['gender'].replace('Male', 1)\n",
    "data['gender'] = data['gender'].replace('Female', 0)\n",
    "\n",
    "data['family_history_with_overweight'] = data['family_history_with_overweight'].replace('yes', 1)\n",
    "data['family_history_with_overweight'] = data['family_history_with_overweight'].replace('no', 0)\n",
    "\n",
    "data['consumption_high_calorie'] = data['consumption_high_calorie'].replace('yes', 1)\n",
    "data['consumption_high_calorie'] = data['consumption_high_calorie'].replace('no', 0)\n",
    "\n",
    "data['eat_food_in_between_meals'] = data['eat_food_in_between_meals'].replace('Always', 3)\n",
    "data['eat_food_in_between_meals'] = data['eat_food_in_between_meals'].replace('Frequently', 2)\n",
    "data['eat_food_in_between_meals'] = data['eat_food_in_between_meals'].replace('Sometimes', 1)\n",
    "data['eat_food_in_between_meals'] = data['eat_food_in_between_meals'].replace('no', 0)\n",
    "\n",
    "data['smoke'] = data['smoke'].replace('yes', 1)\n",
    "data['smoke'] = data['smoke'].replace('no', 0)\n",
    "\n",
    "data['food_calorie_monitoring'] = data['food_calorie_monitoring'].replace('yes', 1)\n",
    "data['food_calorie_monitoring'] = data['food_calorie_monitoring'].replace('no', 0)\n",
    "\n",
    "data['consumption_alcohol'] = data['consumption_alcohol'].replace('Always', 3)\n",
    "data['consumption_alcohol'] = data['consumption_alcohol'].replace('Frequently', 2)\n",
    "data['consumption_alcohol'] = data['consumption_alcohol'].replace('Sometimes', 1)\n",
    "data['consumption_alcohol'] = data['consumption_alcohol'].replace('no', 0)\n",
    "\n",
    "data['commonly_used_transportation'] = data['commonly_used_transportation'].replace('Walking', 0)\n",
    "data['commonly_used_transportation'] = data['commonly_used_transportation'].replace('Public_Transportation', 1)\n",
    "data['commonly_used_transportation'] = data['commonly_used_transportation'].replace('Bike', 2)\n",
    "data['commonly_used_transportation'] = data['commonly_used_transportation'].replace('Motorbike', 3)\n",
    "data['commonly_used_transportation'] = data['commonly_used_transportation'].replace('Automobile', 4)\n",
    "\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "8eb75c36",
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 2111 entries, 0 to 2110\n",
      "Data columns (total 17 columns):\n",
      " #   Column                          Non-Null Count  Dtype  \n",
      "---  ------                          --------------  -----  \n",
      " 0   gender                          2111 non-null   int64  \n",
      " 1   age                             2111 non-null   int64  \n",
      " 2   height_meter                    2111 non-null   float64\n",
      " 3   weight_kilogram                 2111 non-null   float64\n",
      " 4   family_history_with_overweight  2111 non-null   int64  \n",
      " 5   consumption_high_calorie        2111 non-null   int64  \n",
      " 6   consumption_vegetables          2111 non-null   int64  \n",
      " 7   heavy_meal                      2111 non-null   int64  \n",
      " 8   eat_food_in_between_meals       2111 non-null   int64  \n",
      " 9   smoke                           2111 non-null   int64  \n",
      " 10  consumption_water_liter         2111 non-null   int64  \n",
      " 11  food_calorie_monitoring         2111 non-null   int64  \n",
      " 12  physical_activity               2111 non-null   int64  \n",
      " 13  duration_technological_devices  2111 non-null   int64  \n",
      " 14  consumption_alcohol             2111 non-null   int64  \n",
      " 15  commonly_used_transportation    2111 non-null   int64  \n",
      " 16  obesity_class                   2111 non-null   object \n",
      "dtypes: float64(2), int64(14), object(1)\n",
      "memory usage: 280.5+ KB\n"
     ]
    }
   ],
   "source": [
    "data.info()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ca97e7a5",
   "metadata": {},
   "source": [
    "### transformasi data (kategori) yang akan didownload "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "034edb80",
   "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>gender</th>\n",
       "      <th>age</th>\n",
       "      <th>height_meter</th>\n",
       "      <th>weight_kilogram</th>\n",
       "      <th>family_history_with_overweight</th>\n",
       "      <th>consumption_high_calorie</th>\n",
       "      <th>consumption_vegetables</th>\n",
       "      <th>heavy_meal</th>\n",
       "      <th>eat_food_in_between_meals</th>\n",
       "      <th>smoke</th>\n",
       "      <th>consumption_water_liter</th>\n",
       "      <th>food_calorie_monitoring</th>\n",
       "      <th>physical_activity</th>\n",
       "      <th>duration_technological_devices</th>\n",
       "      <th>consumption_alcohol</th>\n",
       "      <th>commonly_used_transportation</th>\n",
       "      <th>obesity_class</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.00</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>Normal_Weight</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.00</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>Normal_Weight</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>23</td>\n",
       "      <td>1.80</td>\n",
       "      <td>77.00</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>2</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>Normal_Weight</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>27</td>\n",
       "      <td>1.80</td>\n",
       "      <td>87.00</td>\n",
       "      <td>0</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>2</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>Overweight_Level_I</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1</td>\n",
       "      <td>22</td>\n",
       "      <td>1.78</td>\n",
       "      <td>89.80</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</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>1</td>\n",
       "      <td>Overweight_Level_II</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>2106</th>\n",
       "      <td>0</td>\n",
       "      <td>20</td>\n",
       "      <td>1.71</td>\n",
       "      <td>131.41</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>1</td>\n",
       "      <td>Obesity_Type_III</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2107</th>\n",
       "      <td>0</td>\n",
       "      <td>21</td>\n",
       "      <td>1.75</td>\n",
       "      <td>133.74</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>1</td>\n",
       "      <td>Obesity_Type_III</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2108</th>\n",
       "      <td>0</td>\n",
       "      <td>22</td>\n",
       "      <td>1.75</td>\n",
       "      <td>133.69</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>1</td>\n",
       "      <td>Obesity_Type_III</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2109</th>\n",
       "      <td>0</td>\n",
       "      <td>24</td>\n",
       "      <td>1.74</td>\n",
       "      <td>133.35</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>1</td>\n",
       "      <td>Obesity_Type_III</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2110</th>\n",
       "      <td>0</td>\n",
       "      <td>23</td>\n",
       "      <td>1.74</td>\n",
       "      <td>133.47</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>1</td>\n",
       "      <td>Obesity_Type_III</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>2111 rows × 17 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      gender  age  height_meter  weight_kilogram  \\\n",
       "0          0   21          1.62            64.00   \n",
       "1          0   21          1.52            56.00   \n",
       "2          1   23          1.80            77.00   \n",
       "3          1   27          1.80            87.00   \n",
       "4          1   22          1.78            89.80   \n",
       "...      ...  ...           ...              ...   \n",
       "2106       0   20          1.71           131.41   \n",
       "2107       0   21          1.75           133.74   \n",
       "2108       0   22          1.75           133.69   \n",
       "2109       0   24          1.74           133.35   \n",
       "2110       0   23          1.74           133.47   \n",
       "\n",
       "      family_history_with_overweight  consumption_high_calorie  \\\n",
       "0                                  1                         0   \n",
       "1                                  1                         0   \n",
       "2                                  1                         0   \n",
       "3                                  0                         0   \n",
       "4                                  0                         0   \n",
       "...                              ...                       ...   \n",
       "2106                               1                         1   \n",
       "2107                               1                         1   \n",
       "2108                               1                         1   \n",
       "2109                               1                         1   \n",
       "2110                               1                         1   \n",
       "\n",
       "      consumption_vegetables  heavy_meal  eat_food_in_between_meals  smoke  \\\n",
       "0                          1           2                          1      0   \n",
       "1                          2           2                          1      1   \n",
       "2                          1           2                          1      0   \n",
       "3                          2           2                          1      0   \n",
       "4                          1           1                          1      0   \n",
       "...                      ...         ...                        ...    ...   \n",
       "2106                       2           2                          1      0   \n",
       "2107                       2           2                          1      0   \n",
       "2108                       2           2                          1      0   \n",
       "2109                       2           2                          1      0   \n",
       "2110                       2           2                          1      0   \n",
       "\n",
       "      consumption_water_liter  food_calorie_monitoring  physical_activity  \\\n",
       "0                           2                        0                  0   \n",
       "1                           3                        1                  3   \n",
       "2                           2                        0                  2   \n",
       "3                           2                        0                  2   \n",
       "4                           2                        0                  0   \n",
       "...                       ...                      ...                ...   \n",
       "2106                        2                        0                  1   \n",
       "2107                        3                        0                  1   \n",
       "2108                        3                        0                  1   \n",
       "2109                        3                        0                  1   \n",
       "2110                        3                        0                  1   \n",
       "\n",
       "      duration_technological_devices  consumption_alcohol  \\\n",
       "0                                  1                    0   \n",
       "1                                  1                    1   \n",
       "2                                  1                    2   \n",
       "3                                  1                    2   \n",
       "4                                  1                    1   \n",
       "...                              ...                  ...   \n",
       "2106                               1                    1   \n",
       "2107                               1                    1   \n",
       "2108                               1                    1   \n",
       "2109                               1                    1   \n",
       "2110                               1                    1   \n",
       "\n",
       "      commonly_used_transportation        obesity_class  \n",
       "0                                1        Normal_Weight  \n",
       "1                                1        Normal_Weight  \n",
       "2                                1        Normal_Weight  \n",
       "3                                0   Overweight_Level_I  \n",
       "4                                1  Overweight_Level_II  \n",
       "...                            ...                  ...  \n",
       "2106                             1     Obesity_Type_III  \n",
       "2107                             1     Obesity_Type_III  \n",
       "2108                             1     Obesity_Type_III  \n",
       "2109                             1     Obesity_Type_III  \n",
       "2110                             1     Obesity_Type_III  \n",
       "\n",
       "[2111 rows x 17 columns]"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_obesitas_baru = data.copy()\n",
    "data_obesitas_baru"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "bd567299",
   "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>gender</th>\n",
       "      <th>age</th>\n",
       "      <th>height_meter</th>\n",
       "      <th>weight_kilogram</th>\n",
       "      <th>family_history_with_overweight</th>\n",
       "      <th>consumption_high_calorie</th>\n",
       "      <th>consumption_vegetables</th>\n",
       "      <th>heavy_meal</th>\n",
       "      <th>eat_food_in_between_meals</th>\n",
       "      <th>smoke</th>\n",
       "      <th>consumption_water_liter</th>\n",
       "      <th>food_calorie_monitoring</th>\n",
       "      <th>physical_activity</th>\n",
       "      <th>duration_technological_devices</th>\n",
       "      <th>consumption_alcohol</th>\n",
       "      <th>commonly_used_transportation</th>\n",
       "      <th>obesity_class</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Female</td>\n",
       "      <td>21</td>\n",
       "      <td>1.62</td>\n",
       "      <td>64.00</td>\n",
       "      <td>yes</td>\n",
       "      <td>no</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>Three</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>no</td>\n",
       "      <td>1 - 2 liter</td>\n",
       "      <td>no</td>\n",
       "      <td>naver</td>\n",
       "      <td>0 - 2 hours</td>\n",
       "      <td>no</td>\n",
       "      <td>Public_Transportation</td>\n",
       "      <td>Normal_Weight</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Female</td>\n",
       "      <td>21</td>\n",
       "      <td>1.52</td>\n",
       "      <td>56.00</td>\n",
       "      <td>yes</td>\n",
       "      <td>no</td>\n",
       "      <td>Always</td>\n",
       "      <td>Three</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>yes</td>\n",
       "      <td>More than 2 liter</td>\n",
       "      <td>yes</td>\n",
       "      <td>4 or 5 day</td>\n",
       "      <td>0 - 2 hours</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>Public_Transportation</td>\n",
       "      <td>Normal_Weight</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Male</td>\n",
       "      <td>23</td>\n",
       "      <td>1.80</td>\n",
       "      <td>77.00</td>\n",
       "      <td>yes</td>\n",
       "      <td>no</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>Three</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>no</td>\n",
       "      <td>1 - 2 liter</td>\n",
       "      <td>no</td>\n",
       "      <td>2 or 4 day</td>\n",
       "      <td>0 - 2 hours</td>\n",
       "      <td>Frequently</td>\n",
       "      <td>Public_Transportation</td>\n",
       "      <td>Normal_Weight</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Male</td>\n",
       "      <td>27</td>\n",
       "      <td>1.80</td>\n",
       "      <td>87.00</td>\n",
       "      <td>no</td>\n",
       "      <td>no</td>\n",
       "      <td>Always</td>\n",
       "      <td>Three</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>no</td>\n",
       "      <td>1 - 2 liter</td>\n",
       "      <td>no</td>\n",
       "      <td>2 or 4 day</td>\n",
       "      <td>0 - 2 hours</td>\n",
       "      <td>Frequently</td>\n",
       "      <td>Walking</td>\n",
       "      <td>Overweight_Level_I</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Male</td>\n",
       "      <td>22</td>\n",
       "      <td>1.78</td>\n",
       "      <td>89.80</td>\n",
       "      <td>no</td>\n",
       "      <td>no</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>Once to twice</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>no</td>\n",
       "      <td>1 - 2 liter</td>\n",
       "      <td>no</td>\n",
       "      <td>naver</td>\n",
       "      <td>0 - 2 hours</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>Public_Transportation</td>\n",
       "      <td>Overweight_Level_II</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>2106</th>\n",
       "      <td>Female</td>\n",
       "      <td>20</td>\n",
       "      <td>1.71</td>\n",
       "      <td>131.41</td>\n",
       "      <td>yes</td>\n",
       "      <td>yes</td>\n",
       "      <td>Always</td>\n",
       "      <td>Three</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>no</td>\n",
       "      <td>1 - 2 liter</td>\n",
       "      <td>no</td>\n",
       "      <td>1 or 2 day</td>\n",
       "      <td>0 - 2 hours</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>Public_Transportation</td>\n",
       "      <td>Obesity_Type_III</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2107</th>\n",
       "      <td>Female</td>\n",
       "      <td>21</td>\n",
       "      <td>1.75</td>\n",
       "      <td>133.74</td>\n",
       "      <td>yes</td>\n",
       "      <td>yes</td>\n",
       "      <td>Always</td>\n",
       "      <td>Three</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>no</td>\n",
       "      <td>More than 2 liter</td>\n",
       "      <td>no</td>\n",
       "      <td>1 or 2 day</td>\n",
       "      <td>0 - 2 hours</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>Public_Transportation</td>\n",
       "      <td>Obesity_Type_III</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2108</th>\n",
       "      <td>Female</td>\n",
       "      <td>22</td>\n",
       "      <td>1.75</td>\n",
       "      <td>133.69</td>\n",
       "      <td>yes</td>\n",
       "      <td>yes</td>\n",
       "      <td>Always</td>\n",
       "      <td>Three</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>no</td>\n",
       "      <td>More than 2 liter</td>\n",
       "      <td>no</td>\n",
       "      <td>1 or 2 day</td>\n",
       "      <td>0 - 2 hours</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>Public_Transportation</td>\n",
       "      <td>Obesity_Type_III</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2109</th>\n",
       "      <td>Female</td>\n",
       "      <td>24</td>\n",
       "      <td>1.74</td>\n",
       "      <td>133.35</td>\n",
       "      <td>yes</td>\n",
       "      <td>yes</td>\n",
       "      <td>Always</td>\n",
       "      <td>Three</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>no</td>\n",
       "      <td>More than 2 liter</td>\n",
       "      <td>no</td>\n",
       "      <td>1 or 2 day</td>\n",
       "      <td>0 - 2 hours</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>Public_Transportation</td>\n",
       "      <td>Obesity_Type_III</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2110</th>\n",
       "      <td>Female</td>\n",
       "      <td>23</td>\n",
       "      <td>1.74</td>\n",
       "      <td>133.47</td>\n",
       "      <td>yes</td>\n",
       "      <td>yes</td>\n",
       "      <td>Always</td>\n",
       "      <td>Three</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>no</td>\n",
       "      <td>More than 2 liter</td>\n",
       "      <td>no</td>\n",
       "      <td>1 or 2 day</td>\n",
       "      <td>0 - 2 hours</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>Public_Transportation</td>\n",
       "      <td>Obesity_Type_III</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>2111 rows × 17 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      gender  age  height_meter  weight_kilogram  \\\n",
       "0     Female   21          1.62            64.00   \n",
       "1     Female   21          1.52            56.00   \n",
       "2       Male   23          1.80            77.00   \n",
       "3       Male   27          1.80            87.00   \n",
       "4       Male   22          1.78            89.80   \n",
       "...      ...  ...           ...              ...   \n",
       "2106  Female   20          1.71           131.41   \n",
       "2107  Female   21          1.75           133.74   \n",
       "2108  Female   22          1.75           133.69   \n",
       "2109  Female   24          1.74           133.35   \n",
       "2110  Female   23          1.74           133.47   \n",
       "\n",
       "     family_history_with_overweight consumption_high_calorie  \\\n",
       "0                               yes                       no   \n",
       "1                               yes                       no   \n",
       "2                               yes                       no   \n",
       "3                                no                       no   \n",
       "4                                no                       no   \n",
       "...                             ...                      ...   \n",
       "2106                            yes                      yes   \n",
       "2107                            yes                      yes   \n",
       "2108                            yes                      yes   \n",
       "2109                            yes                      yes   \n",
       "2110                            yes                      yes   \n",
       "\n",
       "     consumption_vegetables     heavy_meal eat_food_in_between_meals smoke  \\\n",
       "0                 Sometimes          Three                 Sometimes    no   \n",
       "1                    Always          Three                 Sometimes   yes   \n",
       "2                 Sometimes          Three                 Sometimes    no   \n",
       "3                    Always          Three                 Sometimes    no   \n",
       "4                 Sometimes  Once to twice                 Sometimes    no   \n",
       "...                     ...            ...                       ...   ...   \n",
       "2106                 Always          Three                 Sometimes    no   \n",
       "2107                 Always          Three                 Sometimes    no   \n",
       "2108                 Always          Three                 Sometimes    no   \n",
       "2109                 Always          Three                 Sometimes    no   \n",
       "2110                 Always          Three                 Sometimes    no   \n",
       "\n",
       "     consumption_water_liter food_calorie_monitoring physical_activity  \\\n",
       "0                1 - 2 liter                      no             naver   \n",
       "1          More than 2 liter                     yes        4 or 5 day   \n",
       "2                1 - 2 liter                      no        2 or 4 day   \n",
       "3                1 - 2 liter                      no        2 or 4 day   \n",
       "4                1 - 2 liter                      no             naver   \n",
       "...                      ...                     ...               ...   \n",
       "2106             1 - 2 liter                      no        1 or 2 day   \n",
       "2107       More than 2 liter                      no        1 or 2 day   \n",
       "2108       More than 2 liter                      no        1 or 2 day   \n",
       "2109       More than 2 liter                      no        1 or 2 day   \n",
       "2110       More than 2 liter                      no        1 or 2 day   \n",
       "\n",
       "     duration_technological_devices consumption_alcohol  \\\n",
       "0                       0 - 2 hours                  no   \n",
       "1                       0 - 2 hours           Sometimes   \n",
       "2                       0 - 2 hours          Frequently   \n",
       "3                       0 - 2 hours          Frequently   \n",
       "4                       0 - 2 hours           Sometimes   \n",
       "...                             ...                 ...   \n",
       "2106                    0 - 2 hours           Sometimes   \n",
       "2107                    0 - 2 hours           Sometimes   \n",
       "2108                    0 - 2 hours           Sometimes   \n",
       "2109                    0 - 2 hours           Sometimes   \n",
       "2110                    0 - 2 hours           Sometimes   \n",
       "\n",
       "     commonly_used_transportation        obesity_class  \n",
       "0           Public_Transportation        Normal_Weight  \n",
       "1           Public_Transportation        Normal_Weight  \n",
       "2           Public_Transportation        Normal_Weight  \n",
       "3                         Walking   Overweight_Level_I  \n",
       "4           Public_Transportation  Overweight_Level_II  \n",
       "...                           ...                  ...  \n",
       "2106        Public_Transportation     Obesity_Type_III  \n",
       "2107        Public_Transportation     Obesity_Type_III  \n",
       "2108        Public_Transportation     Obesity_Type_III  \n",
       "2109        Public_Transportation     Obesity_Type_III  \n",
       "2110        Public_Transportation     Obesity_Type_III  \n",
       "\n",
       "[2111 rows x 17 columns]"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_obesitas_baru['gender'] = data_obesitas_baru['gender'].replace(1, 'Male')\n",
    "data_obesitas_baru['gender'] = data_obesitas_baru['gender'].replace(0, 'Female')\n",
    "\n",
    "data_obesitas_baru['family_history_with_overweight'] = data_obesitas_baru['family_history_with_overweight'].replace(1, 'yes')\n",
    "data_obesitas_baru['family_history_with_overweight'] = data_obesitas_baru['family_history_with_overweight'].replace(0, 'no')\n",
    "\n",
    "data_obesitas_baru['consumption_high_calorie'] = data_obesitas_baru['consumption_high_calorie'].replace(1, 'yes')\n",
    "data_obesitas_baru['consumption_high_calorie'] = data_obesitas_baru['consumption_high_calorie'].replace(0, 'no')\n",
    "\n",
    "data_obesitas_baru['consumption_vegetables'] = data_obesitas_baru['consumption_vegetables'].replace(2, 'Always')\n",
    "data_obesitas_baru['consumption_vegetables'] = data_obesitas_baru['consumption_vegetables'].replace(1, 'Sometimes')\n",
    "data_obesitas_baru['consumption_vegetables'] = data_obesitas_baru['consumption_vegetables'].replace(0, 'Never')\n",
    "\n",
    "data_obesitas_baru['heavy_meal'] = data_obesitas_baru['heavy_meal'].replace(3, 'More than three')\n",
    "data_obesitas_baru['heavy_meal'] = data_obesitas_baru['heavy_meal'].replace(2, 'Three')\n",
    "data_obesitas_baru['heavy_meal'] = data_obesitas_baru['heavy_meal'].replace(1, 'Once to twice')\n",
    "\n",
    "data_obesitas_baru['eat_food_in_between_meals'] = data_obesitas_baru['eat_food_in_between_meals'].replace(3, 'Always')\n",
    "data_obesitas_baru['eat_food_in_between_meals'] = data_obesitas_baru['eat_food_in_between_meals'].replace(2, 'Frequently')\n",
    "data_obesitas_baru['eat_food_in_between_meals'] = data_obesitas_baru['eat_food_in_between_meals'].replace(1, 'Sometimes')\n",
    "data_obesitas_baru['eat_food_in_between_meals'] = data_obesitas_baru['eat_food_in_between_meals'].replace(0, 'no')\n",
    "\n",
    "data_obesitas_baru['smoke'] = data_obesitas_baru['smoke'].replace(1, 'yes')\n",
    "data_obesitas_baru['smoke'] = data_obesitas_baru['smoke'].replace(0, 'no')\n",
    "\n",
    "data_obesitas_baru['consumption_water_liter'] = data_obesitas_baru['consumption_water_liter'].replace(3, 'More than 2 liter')\n",
    "data_obesitas_baru['consumption_water_liter'] = data_obesitas_baru['consumption_water_liter'].replace(2, '1 - 2 liter')\n",
    "data_obesitas_baru['consumption_water_liter'] = data_obesitas_baru['consumption_water_liter'].replace(1, 'Less than a liter')\n",
    "\n",
    "data_obesitas_baru['food_calorie_monitoring'] = data_obesitas_baru['food_calorie_monitoring'].replace(1, 'yes')\n",
    "data_obesitas_baru['food_calorie_monitoring'] = data_obesitas_baru['food_calorie_monitoring'].replace(0, 'no')\n",
    "\n",
    "data_obesitas_baru['physical_activity'] = data_obesitas_baru['physical_activity'].replace(3, '4 or 5 day')\n",
    "data_obesitas_baru['physical_activity'] = data_obesitas_baru['physical_activity'].replace(2, '2 or 4 day')\n",
    "data_obesitas_baru['physical_activity'] = data_obesitas_baru['physical_activity'].replace(1, '1 or 2 day')\n",
    "data_obesitas_baru['physical_activity'] = data_obesitas_baru['physical_activity'].replace(0, 'naver')\n",
    "\n",
    "data_obesitas_baru['duration_technological_devices'] = data_obesitas_baru['duration_technological_devices'].replace(3, 'More than 5 hours')\n",
    "data_obesitas_baru['duration_technological_devices'] = data_obesitas_baru['duration_technological_devices'].replace(2, '3 - 5 hours')\n",
    "data_obesitas_baru['duration_technological_devices'] = data_obesitas_baru['duration_technological_devices'].replace(1, '0 - 2 hours')\n",
    "\n",
    "data_obesitas_baru['consumption_alcohol'] = data_obesitas_baru['consumption_alcohol'].replace(3, 'Always')\n",
    "data_obesitas_baru['consumption_alcohol'] = data_obesitas_baru['consumption_alcohol'].replace(2, 'Frequently')\n",
    "data_obesitas_baru['consumption_alcohol'] = data_obesitas_baru['consumption_alcohol'].replace(1, 'Sometimes')\n",
    "data_obesitas_baru['consumption_alcohol'] = data_obesitas_baru['consumption_alcohol'].replace(0, 'no')\n",
    "\n",
    "data_obesitas_baru['commonly_used_transportation'] = data_obesitas_baru['commonly_used_transportation'].replace(0, 'Walking')\n",
    "data_obesitas_baru['commonly_used_transportation'] = data_obesitas_baru['commonly_used_transportation'].replace(1, 'Public_Transportation')\n",
    "data_obesitas_baru['commonly_used_transportation'] = data_obesitas_baru['commonly_used_transportation'].replace(2, 'Bike')\n",
    "data_obesitas_baru['commonly_used_transportation'] = data_obesitas_baru['commonly_used_transportation'].replace(3, 'Motorbike')\n",
    "data_obesitas_baru['commonly_used_transportation'] = data_obesitas_baru['commonly_used_transportation'].replace(4, 'Automobile')\n",
    "\n",
    "data_obesitas_baru"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "150e7586",
   "metadata": {},
   "source": [
    "###  pilih data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "2838f74f",
   "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>gender</th>\n",
       "      <th>age</th>\n",
       "      <th>height_meter</th>\n",
       "      <th>weight_kilogram</th>\n",
       "      <th>family_history_with_overweight</th>\n",
       "      <th>consumption_high_calorie</th>\n",
       "      <th>consumption_vegetables</th>\n",
       "      <th>heavy_meal</th>\n",
       "      <th>eat_food_in_between_meals</th>\n",
       "      <th>smoke</th>\n",
       "      <th>consumption_water_liter</th>\n",
       "      <th>food_calorie_monitoring</th>\n",
       "      <th>physical_activity</th>\n",
       "      <th>duration_technological_devices</th>\n",
       "      <th>consumption_alcohol</th>\n",
       "      <th>commonly_used_transportation</th>\n",
       "      <th>obesity_class</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Female</td>\n",
       "      <td>21</td>\n",
       "      <td>1.62</td>\n",
       "      <td>64.00</td>\n",
       "      <td>yes</td>\n",
       "      <td>no</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>Three</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>no</td>\n",
       "      <td>1 - 2 liter</td>\n",
       "      <td>no</td>\n",
       "      <td>naver</td>\n",
       "      <td>0 - 2 hours</td>\n",
       "      <td>no</td>\n",
       "      <td>Public_Transportation</td>\n",
       "      <td>Normal_Weight</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Female</td>\n",
       "      <td>21</td>\n",
       "      <td>1.52</td>\n",
       "      <td>56.00</td>\n",
       "      <td>yes</td>\n",
       "      <td>no</td>\n",
       "      <td>Always</td>\n",
       "      <td>Three</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>yes</td>\n",
       "      <td>More than 2 liter</td>\n",
       "      <td>yes</td>\n",
       "      <td>4 or 5 day</td>\n",
       "      <td>0 - 2 hours</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>Public_Transportation</td>\n",
       "      <td>Normal_Weight</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Male</td>\n",
       "      <td>23</td>\n",
       "      <td>1.80</td>\n",
       "      <td>77.00</td>\n",
       "      <td>yes</td>\n",
       "      <td>no</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>Three</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>no</td>\n",
       "      <td>1 - 2 liter</td>\n",
       "      <td>no</td>\n",
       "      <td>2 or 4 day</td>\n",
       "      <td>0 - 2 hours</td>\n",
       "      <td>Frequently</td>\n",
       "      <td>Public_Transportation</td>\n",
       "      <td>Normal_Weight</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Male</td>\n",
       "      <td>27</td>\n",
       "      <td>1.80</td>\n",
       "      <td>87.00</td>\n",
       "      <td>no</td>\n",
       "      <td>no</td>\n",
       "      <td>Always</td>\n",
       "      <td>Three</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>no</td>\n",
       "      <td>1 - 2 liter</td>\n",
       "      <td>no</td>\n",
       "      <td>2 or 4 day</td>\n",
       "      <td>0 - 2 hours</td>\n",
       "      <td>Frequently</td>\n",
       "      <td>Walking</td>\n",
       "      <td>Overweight_Level_I</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Male</td>\n",
       "      <td>22</td>\n",
       "      <td>1.78</td>\n",
       "      <td>89.80</td>\n",
       "      <td>no</td>\n",
       "      <td>no</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>Once to twice</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>no</td>\n",
       "      <td>1 - 2 liter</td>\n",
       "      <td>no</td>\n",
       "      <td>naver</td>\n",
       "      <td>0 - 2 hours</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>Public_Transportation</td>\n",
       "      <td>Overweight_Level_II</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>2106</th>\n",
       "      <td>Female</td>\n",
       "      <td>20</td>\n",
       "      <td>1.71</td>\n",
       "      <td>131.41</td>\n",
       "      <td>yes</td>\n",
       "      <td>yes</td>\n",
       "      <td>Always</td>\n",
       "      <td>Three</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>no</td>\n",
       "      <td>1 - 2 liter</td>\n",
       "      <td>no</td>\n",
       "      <td>1 or 2 day</td>\n",
       "      <td>0 - 2 hours</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>Public_Transportation</td>\n",
       "      <td>Obesity_Type_III</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2107</th>\n",
       "      <td>Female</td>\n",
       "      <td>21</td>\n",
       "      <td>1.75</td>\n",
       "      <td>133.74</td>\n",
       "      <td>yes</td>\n",
       "      <td>yes</td>\n",
       "      <td>Always</td>\n",
       "      <td>Three</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>no</td>\n",
       "      <td>More than 2 liter</td>\n",
       "      <td>no</td>\n",
       "      <td>1 or 2 day</td>\n",
       "      <td>0 - 2 hours</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>Public_Transportation</td>\n",
       "      <td>Obesity_Type_III</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2108</th>\n",
       "      <td>Female</td>\n",
       "      <td>22</td>\n",
       "      <td>1.75</td>\n",
       "      <td>133.69</td>\n",
       "      <td>yes</td>\n",
       "      <td>yes</td>\n",
       "      <td>Always</td>\n",
       "      <td>Three</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>no</td>\n",
       "      <td>More than 2 liter</td>\n",
       "      <td>no</td>\n",
       "      <td>1 or 2 day</td>\n",
       "      <td>0 - 2 hours</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>Public_Transportation</td>\n",
       "      <td>Obesity_Type_III</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2109</th>\n",
       "      <td>Female</td>\n",
       "      <td>24</td>\n",
       "      <td>1.74</td>\n",
       "      <td>133.35</td>\n",
       "      <td>yes</td>\n",
       "      <td>yes</td>\n",
       "      <td>Always</td>\n",
       "      <td>Three</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>no</td>\n",
       "      <td>More than 2 liter</td>\n",
       "      <td>no</td>\n",
       "      <td>1 or 2 day</td>\n",
       "      <td>0 - 2 hours</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>Public_Transportation</td>\n",
       "      <td>Obesity_Type_III</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2110</th>\n",
       "      <td>Female</td>\n",
       "      <td>23</td>\n",
       "      <td>1.74</td>\n",
       "      <td>133.47</td>\n",
       "      <td>yes</td>\n",
       "      <td>yes</td>\n",
       "      <td>Always</td>\n",
       "      <td>Three</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>no</td>\n",
       "      <td>More than 2 liter</td>\n",
       "      <td>no</td>\n",
       "      <td>1 or 2 day</td>\n",
       "      <td>0 - 2 hours</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>Public_Transportation</td>\n",
       "      <td>Obesity_Type_III</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>2111 rows × 17 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      gender  age  height_meter  weight_kilogram  \\\n",
       "0     Female   21          1.62            64.00   \n",
       "1     Female   21          1.52            56.00   \n",
       "2       Male   23          1.80            77.00   \n",
       "3       Male   27          1.80            87.00   \n",
       "4       Male   22          1.78            89.80   \n",
       "...      ...  ...           ...              ...   \n",
       "2106  Female   20          1.71           131.41   \n",
       "2107  Female   21          1.75           133.74   \n",
       "2108  Female   22          1.75           133.69   \n",
       "2109  Female   24          1.74           133.35   \n",
       "2110  Female   23          1.74           133.47   \n",
       "\n",
       "     family_history_with_overweight consumption_high_calorie  \\\n",
       "0                               yes                       no   \n",
       "1                               yes                       no   \n",
       "2                               yes                       no   \n",
       "3                                no                       no   \n",
       "4                                no                       no   \n",
       "...                             ...                      ...   \n",
       "2106                            yes                      yes   \n",
       "2107                            yes                      yes   \n",
       "2108                            yes                      yes   \n",
       "2109                            yes                      yes   \n",
       "2110                            yes                      yes   \n",
       "\n",
       "     consumption_vegetables     heavy_meal eat_food_in_between_meals smoke  \\\n",
       "0                 Sometimes          Three                 Sometimes    no   \n",
       "1                    Always          Three                 Sometimes   yes   \n",
       "2                 Sometimes          Three                 Sometimes    no   \n",
       "3                    Always          Three                 Sometimes    no   \n",
       "4                 Sometimes  Once to twice                 Sometimes    no   \n",
       "...                     ...            ...                       ...   ...   \n",
       "2106                 Always          Three                 Sometimes    no   \n",
       "2107                 Always          Three                 Sometimes    no   \n",
       "2108                 Always          Three                 Sometimes    no   \n",
       "2109                 Always          Three                 Sometimes    no   \n",
       "2110                 Always          Three                 Sometimes    no   \n",
       "\n",
       "     consumption_water_liter food_calorie_monitoring physical_activity  \\\n",
       "0                1 - 2 liter                      no             naver   \n",
       "1          More than 2 liter                     yes        4 or 5 day   \n",
       "2                1 - 2 liter                      no        2 or 4 day   \n",
       "3                1 - 2 liter                      no        2 or 4 day   \n",
       "4                1 - 2 liter                      no             naver   \n",
       "...                      ...                     ...               ...   \n",
       "2106             1 - 2 liter                      no        1 or 2 day   \n",
       "2107       More than 2 liter                      no        1 or 2 day   \n",
       "2108       More than 2 liter                      no        1 or 2 day   \n",
       "2109       More than 2 liter                      no        1 or 2 day   \n",
       "2110       More than 2 liter                      no        1 or 2 day   \n",
       "\n",
       "     duration_technological_devices consumption_alcohol  \\\n",
       "0                       0 - 2 hours                  no   \n",
       "1                       0 - 2 hours           Sometimes   \n",
       "2                       0 - 2 hours          Frequently   \n",
       "3                       0 - 2 hours          Frequently   \n",
       "4                       0 - 2 hours           Sometimes   \n",
       "...                             ...                 ...   \n",
       "2106                    0 - 2 hours           Sometimes   \n",
       "2107                    0 - 2 hours           Sometimes   \n",
       "2108                    0 - 2 hours           Sometimes   \n",
       "2109                    0 - 2 hours           Sometimes   \n",
       "2110                    0 - 2 hours           Sometimes   \n",
       "\n",
       "     commonly_used_transportation        obesity_class  \n",
       "0           Public_Transportation        Normal_Weight  \n",
       "1           Public_Transportation        Normal_Weight  \n",
       "2           Public_Transportation        Normal_Weight  \n",
       "3                         Walking   Overweight_Level_I  \n",
       "4           Public_Transportation  Overweight_Level_II  \n",
       "...                           ...                  ...  \n",
       "2106        Public_Transportation     Obesity_Type_III  \n",
       "2107        Public_Transportation     Obesity_Type_III  \n",
       "2108        Public_Transportation     Obesity_Type_III  \n",
       "2109        Public_Transportation     Obesity_Type_III  \n",
       "2110        Public_Transportation     Obesity_Type_III  \n",
       "\n",
       "[2111 rows x 17 columns]"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_obesitas = data_obesitas_baru.copy()\n",
    "data_obesitas"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "1d049fe7",
   "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>age</th>\n",
       "      <th>height_meter</th>\n",
       "      <th>weight_kilogram</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>2111.000000</td>\n",
       "      <td>2111.000000</td>\n",
       "      <td>2111.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>23.972525</td>\n",
       "      <td>1.701620</td>\n",
       "      <td>86.586035</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>6.308664</td>\n",
       "      <td>0.093368</td>\n",
       "      <td>26.191163</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>14.000000</td>\n",
       "      <td>1.450000</td>\n",
       "      <td>39.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>19.000000</td>\n",
       "      <td>1.630000</td>\n",
       "      <td>65.470000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>22.000000</td>\n",
       "      <td>1.700000</td>\n",
       "      <td>83.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>26.000000</td>\n",
       "      <td>1.770000</td>\n",
       "      <td>107.430000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>61.000000</td>\n",
       "      <td>1.980000</td>\n",
       "      <td>173.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "               age  height_meter  weight_kilogram\n",
       "count  2111.000000   2111.000000      2111.000000\n",
       "mean     23.972525      1.701620        86.586035\n",
       "std       6.308664      0.093368        26.191163\n",
       "min      14.000000      1.450000        39.000000\n",
       "25%      19.000000      1.630000        65.470000\n",
       "50%      22.000000      1.700000        83.000000\n",
       "75%      26.000000      1.770000       107.430000\n",
       "max      61.000000      1.980000       173.000000"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_obesitas.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "fd27320d",
   "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>gender</th>\n",
       "      <th>age</th>\n",
       "      <th>height_meter</th>\n",
       "      <th>weight_kilogram</th>\n",
       "      <th>family_history_with_overweight</th>\n",
       "      <th>consumption_high_calorie</th>\n",
       "      <th>consumption_vegetables</th>\n",
       "      <th>heavy_meal</th>\n",
       "      <th>eat_food_in_between_meals</th>\n",
       "      <th>smoke</th>\n",
       "      <th>consumption_water_liter</th>\n",
       "      <th>food_calorie_monitoring</th>\n",
       "      <th>physical_activity</th>\n",
       "      <th>duration_technological_devices</th>\n",
       "      <th>consumption_alcohol</th>\n",
       "      <th>commonly_used_transportation</th>\n",
       "      <th>obesity_class</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Female</td>\n",
       "      <td>21</td>\n",
       "      <td>1.62</td>\n",
       "      <td>64.00</td>\n",
       "      <td>yes</td>\n",
       "      <td>no</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>Three</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>no</td>\n",
       "      <td>1 - 2 liter</td>\n",
       "      <td>no</td>\n",
       "      <td>naver</td>\n",
       "      <td>0 - 2 hours</td>\n",
       "      <td>no</td>\n",
       "      <td>Public_Transportation</td>\n",
       "      <td>Normal_Weight</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Female</td>\n",
       "      <td>21</td>\n",
       "      <td>1.52</td>\n",
       "      <td>56.00</td>\n",
       "      <td>yes</td>\n",
       "      <td>no</td>\n",
       "      <td>Always</td>\n",
       "      <td>Three</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>yes</td>\n",
       "      <td>More than 2 liter</td>\n",
       "      <td>yes</td>\n",
       "      <td>4 or 5 day</td>\n",
       "      <td>0 - 2 hours</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>Public_Transportation</td>\n",
       "      <td>Normal_Weight</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>Male</td>\n",
       "      <td>29</td>\n",
       "      <td>1.62</td>\n",
       "      <td>53.00</td>\n",
       "      <td>no</td>\n",
       "      <td>yes</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>Three</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>no</td>\n",
       "      <td>1 - 2 liter</td>\n",
       "      <td>no</td>\n",
       "      <td>naver</td>\n",
       "      <td>0 - 2 hours</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>Automobile</td>\n",
       "      <td>Normal_Weight</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>Female</td>\n",
       "      <td>23</td>\n",
       "      <td>1.50</td>\n",
       "      <td>55.00</td>\n",
       "      <td>yes</td>\n",
       "      <td>yes</td>\n",
       "      <td>Always</td>\n",
       "      <td>Three</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>no</td>\n",
       "      <td>1 - 2 liter</td>\n",
       "      <td>no</td>\n",
       "      <td>1 or 2 day</td>\n",
       "      <td>0 - 2 hours</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>Motorbike</td>\n",
       "      <td>Normal_Weight</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>Male</td>\n",
       "      <td>22</td>\n",
       "      <td>1.64</td>\n",
       "      <td>53.00</td>\n",
       "      <td>no</td>\n",
       "      <td>no</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>Three</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>no</td>\n",
       "      <td>1 - 2 liter</td>\n",
       "      <td>no</td>\n",
       "      <td>4 or 5 day</td>\n",
       "      <td>0 - 2 hours</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>Public_Transportation</td>\n",
       "      <td>Normal_Weight</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>1502</th>\n",
       "      <td>Male</td>\n",
       "      <td>27</td>\n",
       "      <td>1.67</td>\n",
       "      <td>90.00</td>\n",
       "      <td>yes</td>\n",
       "      <td>yes</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>Three</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>no</td>\n",
       "      <td>More than 2 liter</td>\n",
       "      <td>no</td>\n",
       "      <td>naver</td>\n",
       "      <td>0 - 2 hours</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>Automobile</td>\n",
       "      <td>Obesity_Type_I</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1503</th>\n",
       "      <td>Female</td>\n",
       "      <td>18</td>\n",
       "      <td>1.62</td>\n",
       "      <td>83.12</td>\n",
       "      <td>yes</td>\n",
       "      <td>yes</td>\n",
       "      <td>Always</td>\n",
       "      <td>Three</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>no</td>\n",
       "      <td>1 - 2 liter</td>\n",
       "      <td>no</td>\n",
       "      <td>1 or 2 day</td>\n",
       "      <td>0 - 2 hours</td>\n",
       "      <td>no</td>\n",
       "      <td>Public_Transportation</td>\n",
       "      <td>Obesity_Type_I</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1504</th>\n",
       "      <td>Female</td>\n",
       "      <td>18</td>\n",
       "      <td>1.60</td>\n",
       "      <td>82.41</td>\n",
       "      <td>yes</td>\n",
       "      <td>yes</td>\n",
       "      <td>Always</td>\n",
       "      <td>Three</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>no</td>\n",
       "      <td>1 - 2 liter</td>\n",
       "      <td>no</td>\n",
       "      <td>naver</td>\n",
       "      <td>0 - 2 hours</td>\n",
       "      <td>no</td>\n",
       "      <td>Public_Transportation</td>\n",
       "      <td>Obesity_Type_I</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1509</th>\n",
       "      <td>Female</td>\n",
       "      <td>19</td>\n",
       "      <td>1.61</td>\n",
       "      <td>82.19</td>\n",
       "      <td>yes</td>\n",
       "      <td>yes</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>Three</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>no</td>\n",
       "      <td>1 - 2 liter</td>\n",
       "      <td>no</td>\n",
       "      <td>naver</td>\n",
       "      <td>0 - 2 hours</td>\n",
       "      <td>no</td>\n",
       "      <td>Public_Transportation</td>\n",
       "      <td>Obesity_Type_I</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1510</th>\n",
       "      <td>Female</td>\n",
       "      <td>18</td>\n",
       "      <td>1.61</td>\n",
       "      <td>82.04</td>\n",
       "      <td>yes</td>\n",
       "      <td>yes</td>\n",
       "      <td>Always</td>\n",
       "      <td>Three</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>no</td>\n",
       "      <td>1 - 2 liter</td>\n",
       "      <td>no</td>\n",
       "      <td>naver</td>\n",
       "      <td>0 - 2 hours</td>\n",
       "      <td>no</td>\n",
       "      <td>Public_Transportation</td>\n",
       "      <td>Obesity_Type_I</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>925 rows × 17 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      gender  age  height_meter  weight_kilogram  \\\n",
       "0     Female   21          1.62            64.00   \n",
       "1     Female   21          1.52            56.00   \n",
       "5       Male   29          1.62            53.00   \n",
       "6     Female   23          1.50            55.00   \n",
       "7       Male   22          1.64            53.00   \n",
       "...      ...  ...           ...              ...   \n",
       "1502    Male   27          1.67            90.00   \n",
       "1503  Female   18          1.62            83.12   \n",
       "1504  Female   18          1.60            82.41   \n",
       "1509  Female   19          1.61            82.19   \n",
       "1510  Female   18          1.61            82.04   \n",
       "\n",
       "     family_history_with_overweight consumption_high_calorie  \\\n",
       "0                               yes                       no   \n",
       "1                               yes                       no   \n",
       "5                                no                      yes   \n",
       "6                               yes                      yes   \n",
       "7                                no                       no   \n",
       "...                             ...                      ...   \n",
       "1502                            yes                      yes   \n",
       "1503                            yes                      yes   \n",
       "1504                            yes                      yes   \n",
       "1509                            yes                      yes   \n",
       "1510                            yes                      yes   \n",
       "\n",
       "     consumption_vegetables heavy_meal eat_food_in_between_meals smoke  \\\n",
       "0                 Sometimes      Three                 Sometimes    no   \n",
       "1                    Always      Three                 Sometimes   yes   \n",
       "5                 Sometimes      Three                 Sometimes    no   \n",
       "6                    Always      Three                 Sometimes    no   \n",
       "7                 Sometimes      Three                 Sometimes    no   \n",
       "...                     ...        ...                       ...   ...   \n",
       "1502              Sometimes      Three                 Sometimes    no   \n",
       "1503                 Always      Three                 Sometimes    no   \n",
       "1504                 Always      Three                 Sometimes    no   \n",
       "1509              Sometimes      Three                 Sometimes    no   \n",
       "1510                 Always      Three                 Sometimes    no   \n",
       "\n",
       "     consumption_water_liter food_calorie_monitoring physical_activity  \\\n",
       "0                1 - 2 liter                      no             naver   \n",
       "1          More than 2 liter                     yes        4 or 5 day   \n",
       "5                1 - 2 liter                      no             naver   \n",
       "6                1 - 2 liter                      no        1 or 2 day   \n",
       "7                1 - 2 liter                      no        4 or 5 day   \n",
       "...                      ...                     ...               ...   \n",
       "1502       More than 2 liter                      no             naver   \n",
       "1503             1 - 2 liter                      no        1 or 2 day   \n",
       "1504             1 - 2 liter                      no             naver   \n",
       "1509             1 - 2 liter                      no             naver   \n",
       "1510             1 - 2 liter                      no             naver   \n",
       "\n",
       "     duration_technological_devices consumption_alcohol  \\\n",
       "0                       0 - 2 hours                  no   \n",
       "1                       0 - 2 hours           Sometimes   \n",
       "5                       0 - 2 hours           Sometimes   \n",
       "6                       0 - 2 hours           Sometimes   \n",
       "7                       0 - 2 hours           Sometimes   \n",
       "...                             ...                 ...   \n",
       "1502                    0 - 2 hours           Sometimes   \n",
       "1503                    0 - 2 hours                  no   \n",
       "1504                    0 - 2 hours                  no   \n",
       "1509                    0 - 2 hours                  no   \n",
       "1510                    0 - 2 hours                  no   \n",
       "\n",
       "     commonly_used_transportation   obesity_class  \n",
       "0           Public_Transportation   Normal_Weight  \n",
       "1           Public_Transportation   Normal_Weight  \n",
       "5                      Automobile   Normal_Weight  \n",
       "6                       Motorbike   Normal_Weight  \n",
       "7           Public_Transportation   Normal_Weight  \n",
       "...                           ...             ...  \n",
       "1502                   Automobile  Obesity_Type_I  \n",
       "1503        Public_Transportation  Obesity_Type_I  \n",
       "1504        Public_Transportation  Obesity_Type_I  \n",
       "1509        Public_Transportation  Obesity_Type_I  \n",
       "1510        Public_Transportation  Obesity_Type_I  \n",
       "\n",
       "[925 rows x 17 columns]"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_obesitas = data_obesitas[data_obesitas['height_meter'] <= 1.72]\n",
    "data_obesitas = data_obesitas[data_obesitas['weight_kilogram'] <= 92]\n",
    "data_obesitas"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "38a026a0",
   "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>age</th>\n",
       "      <th>height_meter</th>\n",
       "      <th>weight_kilogram</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>925.000000</td>\n",
       "      <td>925.000000</td>\n",
       "      <td>925.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>23.803243</td>\n",
       "      <td>1.631189</td>\n",
       "      <td>67.094897</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>7.129764</td>\n",
       "      <td>0.062463</td>\n",
       "      <td>14.142452</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>14.000000</td>\n",
       "      <td>1.450000</td>\n",
       "      <td>39.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>19.000000</td>\n",
       "      <td>1.590000</td>\n",
       "      <td>55.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>21.000000</td>\n",
       "      <td>1.640000</td>\n",
       "      <td>68.800000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>25.000000</td>\n",
       "      <td>1.690000</td>\n",
       "      <td>80.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>61.000000</td>\n",
       "      <td>1.720000</td>\n",
       "      <td>91.500000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              age  height_meter  weight_kilogram\n",
       "count  925.000000    925.000000       925.000000\n",
       "mean    23.803243      1.631189        67.094897\n",
       "std      7.129764      0.062463        14.142452\n",
       "min     14.000000      1.450000        39.000000\n",
       "25%     19.000000      1.590000        55.000000\n",
       "50%     21.000000      1.640000        68.800000\n",
       "75%     25.000000      1.690000        80.000000\n",
       "max     61.000000      1.720000        91.500000"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_obesitas.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "e8de0756",
   "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_kilogram</th>\n",
       "      <th>berat_badan_meter</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>Female</td>\n",
       "      <td>21</td>\n",
       "      <td>1.62</td>\n",
       "      <td>64.00</td>\n",
       "      <td>yes</td>\n",
       "      <td>no</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>Three</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>no</td>\n",
       "      <td>1 - 2 liter</td>\n",
       "      <td>no</td>\n",
       "      <td>naver</td>\n",
       "      <td>0 - 2 hours</td>\n",
       "      <td>no</td>\n",
       "      <td>Public_Transportation</td>\n",
       "      <td>Normal_Weight</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Female</td>\n",
       "      <td>21</td>\n",
       "      <td>1.52</td>\n",
       "      <td>56.00</td>\n",
       "      <td>yes</td>\n",
       "      <td>no</td>\n",
       "      <td>Always</td>\n",
       "      <td>Three</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>yes</td>\n",
       "      <td>More than 2 liter</td>\n",
       "      <td>yes</td>\n",
       "      <td>4 or 5 day</td>\n",
       "      <td>0 - 2 hours</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>Public_Transportation</td>\n",
       "      <td>Normal_Weight</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>Male</td>\n",
       "      <td>29</td>\n",
       "      <td>1.62</td>\n",
       "      <td>53.00</td>\n",
       "      <td>no</td>\n",
       "      <td>yes</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>Three</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>no</td>\n",
       "      <td>1 - 2 liter</td>\n",
       "      <td>no</td>\n",
       "      <td>naver</td>\n",
       "      <td>0 - 2 hours</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>Automobile</td>\n",
       "      <td>Normal_Weight</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>Female</td>\n",
       "      <td>23</td>\n",
       "      <td>1.50</td>\n",
       "      <td>55.00</td>\n",
       "      <td>yes</td>\n",
       "      <td>yes</td>\n",
       "      <td>Always</td>\n",
       "      <td>Three</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>no</td>\n",
       "      <td>1 - 2 liter</td>\n",
       "      <td>no</td>\n",
       "      <td>1 or 2 day</td>\n",
       "      <td>0 - 2 hours</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>Motorbike</td>\n",
       "      <td>Normal_Weight</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>Male</td>\n",
       "      <td>22</td>\n",
       "      <td>1.64</td>\n",
       "      <td>53.00</td>\n",
       "      <td>no</td>\n",
       "      <td>no</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>Three</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>no</td>\n",
       "      <td>1 - 2 liter</td>\n",
       "      <td>no</td>\n",
       "      <td>4 or 5 day</td>\n",
       "      <td>0 - 2 hours</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>Public_Transportation</td>\n",
       "      <td>Normal_Weight</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>1502</th>\n",
       "      <td>Male</td>\n",
       "      <td>27</td>\n",
       "      <td>1.67</td>\n",
       "      <td>90.00</td>\n",
       "      <td>yes</td>\n",
       "      <td>yes</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>Three</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>no</td>\n",
       "      <td>More than 2 liter</td>\n",
       "      <td>no</td>\n",
       "      <td>naver</td>\n",
       "      <td>0 - 2 hours</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>Automobile</td>\n",
       "      <td>Obesity_Type_I</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1503</th>\n",
       "      <td>Female</td>\n",
       "      <td>18</td>\n",
       "      <td>1.62</td>\n",
       "      <td>83.12</td>\n",
       "      <td>yes</td>\n",
       "      <td>yes</td>\n",
       "      <td>Always</td>\n",
       "      <td>Three</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>no</td>\n",
       "      <td>1 - 2 liter</td>\n",
       "      <td>no</td>\n",
       "      <td>1 or 2 day</td>\n",
       "      <td>0 - 2 hours</td>\n",
       "      <td>no</td>\n",
       "      <td>Public_Transportation</td>\n",
       "      <td>Obesity_Type_I</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1504</th>\n",
       "      <td>Female</td>\n",
       "      <td>18</td>\n",
       "      <td>1.60</td>\n",
       "      <td>82.41</td>\n",
       "      <td>yes</td>\n",
       "      <td>yes</td>\n",
       "      <td>Always</td>\n",
       "      <td>Three</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>no</td>\n",
       "      <td>1 - 2 liter</td>\n",
       "      <td>no</td>\n",
       "      <td>naver</td>\n",
       "      <td>0 - 2 hours</td>\n",
       "      <td>no</td>\n",
       "      <td>Public_Transportation</td>\n",
       "      <td>Obesity_Type_I</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1509</th>\n",
       "      <td>Female</td>\n",
       "      <td>19</td>\n",
       "      <td>1.61</td>\n",
       "      <td>82.19</td>\n",
       "      <td>yes</td>\n",
       "      <td>yes</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>Three</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>no</td>\n",
       "      <td>1 - 2 liter</td>\n",
       "      <td>no</td>\n",
       "      <td>naver</td>\n",
       "      <td>0 - 2 hours</td>\n",
       "      <td>no</td>\n",
       "      <td>Public_Transportation</td>\n",
       "      <td>Obesity_Type_I</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1510</th>\n",
       "      <td>Female</td>\n",
       "      <td>18</td>\n",
       "      <td>1.61</td>\n",
       "      <td>82.04</td>\n",
       "      <td>yes</td>\n",
       "      <td>yes</td>\n",
       "      <td>Always</td>\n",
       "      <td>Three</td>\n",
       "      <td>Sometimes</td>\n",
       "      <td>no</td>\n",
       "      <td>1 - 2 liter</td>\n",
       "      <td>no</td>\n",
       "      <td>naver</td>\n",
       "      <td>0 - 2 hours</td>\n",
       "      <td>no</td>\n",
       "      <td>Public_Transportation</td>\n",
       "      <td>Obesity_Type_I</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>925 rows × 17 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     jenis_kelamin  umur  tinggi_badan_kilogram  berat_badan_meter  \\\n",
       "0           Female    21                   1.62              64.00   \n",
       "1           Female    21                   1.52              56.00   \n",
       "5             Male    29                   1.62              53.00   \n",
       "6           Female    23                   1.50              55.00   \n",
       "7             Male    22                   1.64              53.00   \n",
       "...            ...   ...                    ...                ...   \n",
       "1502          Male    27                   1.67              90.00   \n",
       "1503        Female    18                   1.62              83.12   \n",
       "1504        Female    18                   1.60              82.41   \n",
       "1509        Female    19                   1.61              82.19   \n",
       "1510        Female    18                   1.61              82.04   \n",
       "\n",
       "     histori_keluarga_kelebihan_BB konsumsi_tinggi_kalori konsumsi_sayuran  \\\n",
       "0                              yes                     no        Sometimes   \n",
       "1                              yes                     no           Always   \n",
       "5                               no                    yes        Sometimes   \n",
       "6                              yes                    yes           Always   \n",
       "7                               no                     no        Sometimes   \n",
       "...                            ...                    ...              ...   \n",
       "1502                           yes                    yes        Sometimes   \n",
       "1503                           yes                    yes           Always   \n",
       "1504                           yes                    yes           Always   \n",
       "1509                           yes                    yes        Sometimes   \n",
       "1510                           yes                    yes           Always   \n",
       "\n",
       "     makan_berat     ngemil merokok konsumsi_air_liter pemantauan_kalori  \\\n",
       "0          Three  Sometimes      no        1 - 2 liter                no   \n",
       "1          Three  Sometimes     yes  More than 2 liter               yes   \n",
       "5          Three  Sometimes      no        1 - 2 liter                no   \n",
       "6          Three  Sometimes      no        1 - 2 liter                no   \n",
       "7          Three  Sometimes      no        1 - 2 liter                no   \n",
       "...          ...        ...     ...                ...               ...   \n",
       "1502       Three  Sometimes      no  More than 2 liter                no   \n",
       "1503       Three  Sometimes      no        1 - 2 liter                no   \n",
       "1504       Three  Sometimes      no        1 - 2 liter                no   \n",
       "1509       Three  Sometimes      no        1 - 2 liter                no   \n",
       "1510       Three  Sometimes      no        1 - 2 liter                no   \n",
       "\n",
       "     aktifitas_fisik penggunaan_perangkat_teknologi konsumsi_alkohol  \\\n",
       "0              naver                    0 - 2 hours               no   \n",
       "1         4 or 5 day                    0 - 2 hours        Sometimes   \n",
       "5              naver                    0 - 2 hours        Sometimes   \n",
       "6         1 or 2 day                    0 - 2 hours        Sometimes   \n",
       "7         4 or 5 day                    0 - 2 hours        Sometimes   \n",
       "...              ...                            ...              ...   \n",
       "1502           naver                    0 - 2 hours        Sometimes   \n",
       "1503      1 or 2 day                    0 - 2 hours               no   \n",
       "1504           naver                    0 - 2 hours               no   \n",
       "1509           naver                    0 - 2 hours               no   \n",
       "1510           naver                    0 - 2 hours               no   \n",
       "\n",
       "     transporasi_biasa_digunakan  kelas_obesitas  \n",
       "0          Public_Transportation   Normal_Weight  \n",
       "1          Public_Transportation   Normal_Weight  \n",
       "5                     Automobile   Normal_Weight  \n",
       "6                      Motorbike   Normal_Weight  \n",
       "7          Public_Transportation   Normal_Weight  \n",
       "...                          ...             ...  \n",
       "1502                  Automobile  Obesity_Type_I  \n",
       "1503       Public_Transportation  Obesity_Type_I  \n",
       "1504       Public_Transportation  Obesity_Type_I  \n",
       "1509       Public_Transportation  Obesity_Type_I  \n",
       "1510       Public_Transportation  Obesity_Type_I  \n",
       "\n",
       "[925 rows x 17 columns]"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "renameColomn = data_obesitas.rename(columns = \n",
    "                           {'gender':'jenis_kelamin',\n",
    "                            'age':'umur',\n",
    "                            'height_meter':'tinggi_badan_kilogram',\n",
    "                            'weight_kilogram':'berat_badan_meter',\n",
    "                            'family_history_with_overweight': 'histori_keluarga_kelebihan_BB',\n",
    "                            'consumption_high_calorie':'konsumsi_tinggi_kalori',\n",
    "                            'consumption_vegetables':'konsumsi_sayuran',\n",
    "                            'heavy_meal':'makan_berat',\n",
    "                            'eat_food_in_between_meals':'ngemil',\n",
    "                            'smoke':'merokok',\n",
    "                            'consumption_water_liter':'konsumsi_air_liter',\n",
    "                            'food_calorie_monitoring':'pemantauan_kalori',\n",
    "                            'physical_activity':'aktifitas_fisik',\n",
    "                            'duration_technological_devices':'penggunaan_perangkat_teknologi',\n",
    "                            'consumption_alcohol':'konsumsi_alkohol',\n",
    "                            'commonly_used_transportation':'transporasi_biasa_digunakan',\n",
    "                            'obesity_class':'kelas_obesitas'}, inplace=True)\n",
    "data_obesitas"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "1c4ad990",
   "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_kilogram</th>\n",
       "      <th>berat_badan_meter</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.00</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>Normal_Weight</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.00</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>Normal_Weight</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>Laki-laki</td>\n",
       "      <td>29</td>\n",
       "      <td>1.62</td>\n",
       "      <td>53.00</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_Weight</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>23</td>\n",
       "      <td>1.50</td>\n",
       "      <td>55.00</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>Normal_Weight</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>Laki-laki</td>\n",
       "      <td>22</td>\n",
       "      <td>1.64</td>\n",
       "      <td>53.00</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_Weight</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>1502</th>\n",
       "      <td>Laki-laki</td>\n",
       "      <td>27</td>\n",
       "      <td>1.67</td>\n",
       "      <td>90.00</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>Obesity_Type_I</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1503</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>18</td>\n",
       "      <td>1.62</td>\n",
       "      <td>83.12</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>Tidak pernah</td>\n",
       "      <td>Sepeda motor</td>\n",
       "      <td>Obesity_Type_I</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1504</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>18</td>\n",
       "      <td>1.60</td>\n",
       "      <td>82.41</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>Tidak pernah</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>Sepeda motor</td>\n",
       "      <td>Obesity_Type_I</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1509</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>19</td>\n",
       "      <td>1.61</td>\n",
       "      <td>82.19</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>Tidak pernah</td>\n",
       "      <td>Sepeda motor</td>\n",
       "      <td>Obesity_Type_I</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1510</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>18</td>\n",
       "      <td>1.61</td>\n",
       "      <td>82.04</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>Tidak pernah</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>Sepeda motor</td>\n",
       "      <td>Obesity_Type_I</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>925 rows × 17 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     jenis_kelamin  umur  tinggi_badan_kilogram  berat_badan_meter  \\\n",
       "0        Perempuan    21                   1.62              64.00   \n",
       "1        Perempuan    21                   1.52              56.00   \n",
       "5        Laki-laki    29                   1.62              53.00   \n",
       "6        Perempuan    23                   1.50              55.00   \n",
       "7        Laki-laki    22                   1.64              53.00   \n",
       "...            ...   ...                    ...                ...   \n",
       "1502     Laki-laki    27                   1.67              90.00   \n",
       "1503     Perempuan    18                   1.62              83.12   \n",
       "1504     Perempuan    18                   1.60              82.41   \n",
       "1509     Perempuan    19                   1.61              82.19   \n",
       "1510     Perempuan    18                   1.61              82.04   \n",
       "\n",
       "     histori_keluarga_kelebihan_BB konsumsi_tinggi_kalori konsumsi_sayuran  \\\n",
       "0                               Ya                  Tidak    Kadang-kadang   \n",
       "1                               Ya                  Tidak           Selalu   \n",
       "5                            Tidak                     Ya    Kadang-kadang   \n",
       "6                               Ya                     Ya           Selalu   \n",
       "7                            Tidak                  Tidak    Kadang-kadang   \n",
       "...                            ...                    ...              ...   \n",
       "1502                            Ya                     Ya    Kadang-kadang   \n",
       "1503                            Ya                     Ya           Selalu   \n",
       "1504                            Ya                     Ya           Selalu   \n",
       "1509                            Ya                     Ya    Kadang-kadang   \n",
       "1510                            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",
       "5             3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "6             3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "7             3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "...          ...            ...     ...                ...               ...   \n",
       "1502          3x  Kadang-kadang   Tidak      Lebih 2 liter             Tidak   \n",
       "1503          3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "1504          3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "1509          3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "1510          3x  Kadang-kadang   Tidak          1-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",
       "5       Tidak pernah                        0-2 jam    Kadang-kadang   \n",
       "6           1-2 hari                        0-2 jam    Kadang-kadang   \n",
       "7           4-5 hari                        0-2 jam    Kadang-kadang   \n",
       "...              ...                            ...              ...   \n",
       "1502    Tidak pernah                        0-2 jam    Kadang-kadang   \n",
       "1503        1-2 hari                        0-2 jam     Tidak pernah   \n",
       "1504    Tidak pernah                        0-2 jam     Tidak pernah   \n",
       "1509    Tidak pernah                        0-2 jam     Tidak pernah   \n",
       "1510    Tidak pernah                        0-2 jam     Tidak pernah   \n",
       "\n",
       "     transporasi_biasa_digunakan  kelas_obesitas  \n",
       "0                   Sepeda motor   Normal_Weight  \n",
       "1                   Sepeda motor   Normal_Weight  \n",
       "5                     Jalan kaki   Normal_Weight  \n",
       "6              Transportasi umum   Normal_Weight  \n",
       "7                   Sepeda motor   Normal_Weight  \n",
       "...                          ...             ...  \n",
       "1502                  Jalan kaki  Obesity_Type_I  \n",
       "1503                Sepeda motor  Obesity_Type_I  \n",
       "1504                Sepeda motor  Obesity_Type_I  \n",
       "1509                Sepeda motor  Obesity_Type_I  \n",
       "1510                Sepeda motor  Obesity_Type_I  \n",
       "\n",
       "[925 rows x 17 columns]"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_obesitas['jenis_kelamin'] = data_obesitas['jenis_kelamin'].replace('Male', 'Laki-laki')\n",
    "data_obesitas['jenis_kelamin'] = data_obesitas['jenis_kelamin'].replace('Female', 'Perempuan')\n",
    "\n",
    "data_obesitas['histori_keluarga_kelebihan_BB'] = data_obesitas['histori_keluarga_kelebihan_BB'].replace('yes', 'Ya')\n",
    "data_obesitas['histori_keluarga_kelebihan_BB'] = data_obesitas['histori_keluarga_kelebihan_BB'].replace('no', 'Tidak')\n",
    "\n",
    "data_obesitas['konsumsi_tinggi_kalori'] = data_obesitas['konsumsi_tinggi_kalori'].replace('yes', 'Ya')\n",
    "data_obesitas['konsumsi_tinggi_kalori'] = data_obesitas['konsumsi_tinggi_kalori'].replace('no', 'Tidak')\n",
    "\n",
    "data_obesitas['konsumsi_sayuran'] = data_obesitas['konsumsi_sayuran'].replace('Always', 'Selalu')\n",
    "data_obesitas['konsumsi_sayuran'] = data_obesitas['konsumsi_sayuran'].replace('Sometimes', 'Kadang-kadang')\n",
    "data_obesitas['konsumsi_sayuran'] = data_obesitas['konsumsi_sayuran'].replace('Never', 'Tidak pernah')\n",
    "\n",
    "data_obesitas['makan_berat'] = data_obesitas['makan_berat'].replace('More than three', 'Lebih 3x')\n",
    "data_obesitas['makan_berat'] = data_obesitas['makan_berat'].replace('Three', '3x')\n",
    "data_obesitas['makan_berat'] = data_obesitas['makan_berat'].replace('Once to twice', '1-2x')\n",
    "\n",
    "data_obesitas['ngemil'] = data_obesitas['ngemil'].replace('Always', 'Selalu')\n",
    "data_obesitas['ngemil'] = data_obesitas['ngemil'].replace('Frequently', 'Sering')\n",
    "data_obesitas['ngemil'] = data_obesitas['ngemil'].replace('Sometimes', 'Kadang-kadang')\n",
    "data_obesitas['ngemil'] = data_obesitas['ngemil'].replace('no', 'Tidak pernah')\n",
    "\n",
    "data_obesitas['merokok'] = data_obesitas['merokok'].replace('yes', 'Ya')\n",
    "data_obesitas['merokok'] = data_obesitas['merokok'].replace('no', 'Tidak')\n",
    "\n",
    "data_obesitas['konsumsi_air_liter'] = data_obesitas['konsumsi_air_liter'].replace('More than 2 liter', 'Lebih 2 liter')\n",
    "data_obesitas['konsumsi_air_liter'] = data_obesitas['konsumsi_air_liter'].replace('1 - 2 liter', '1-2 liter')\n",
    "data_obesitas['konsumsi_air_liter'] = data_obesitas['konsumsi_air_liter'].replace('Less than a liter', 'Kurang 1 liter')\n",
    "\n",
    "data_obesitas['pemantauan_kalori'] = data_obesitas['pemantauan_kalori'].replace('yes', 'Ya')\n",
    "data_obesitas['pemantauan_kalori'] = data_obesitas['pemantauan_kalori'].replace('no', 'Tidak')\n",
    "\n",
    "data_obesitas['aktifitas_fisik'] = data_obesitas['aktifitas_fisik'].replace('4 or 5 day', '4-5 hari')\n",
    "data_obesitas['aktifitas_fisik'] = data_obesitas['aktifitas_fisik'].replace('2 or 4 day', '2-4 hari')\n",
    "data_obesitas['aktifitas_fisik'] = data_obesitas['aktifitas_fisik'].replace('1 or 2 day', '1-2 hari')\n",
    "data_obesitas['aktifitas_fisik'] = data_obesitas['aktifitas_fisik'].replace('naver', 'Tidak pernah')\n",
    "\n",
    "data_obesitas['penggunaan_perangkat_teknologi'] = data_obesitas['penggunaan_perangkat_teknologi'].replace('More than 5 hours', 'Lebih 5 jam')\n",
    "data_obesitas['penggunaan_perangkat_teknologi'] = data_obesitas['penggunaan_perangkat_teknologi'].replace('3 - 5 hours', '3-5 jam')\n",
    "data_obesitas['penggunaan_perangkat_teknologi'] = data_obesitas['penggunaan_perangkat_teknologi'].replace('0 - 2 hours', '0-2 jam')\n",
    "\n",
    "data_obesitas['konsumsi_alkohol'] = data_obesitas['konsumsi_alkohol'].replace('Always', 'Selalu')\n",
    "data_obesitas['konsumsi_alkohol'] = data_obesitas['konsumsi_alkohol'].replace('Frequently', 'Sering')\n",
    "data_obesitas['konsumsi_alkohol'] = data_obesitas['konsumsi_alkohol'].replace('Sometimes', 'Kadang-kadang')\n",
    "data_obesitas['konsumsi_alkohol'] = data_obesitas['konsumsi_alkohol'].replace('no', 'Tidak pernah')\n",
    "\n",
    "data_obesitas['transporasi_biasa_digunakan'] = data_obesitas['transporasi_biasa_digunakan'].replace('Walking', 'Mobil')\n",
    "data_obesitas['transporasi_biasa_digunakan'] = data_obesitas['transporasi_biasa_digunakan'].replace('Public_Transportation', 'Sepeda motor')\n",
    "data_obesitas['transporasi_biasa_digunakan'] = data_obesitas['transporasi_biasa_digunakan'].replace('Bike', 'Sepeda')\n",
    "data_obesitas['transporasi_biasa_digunakan'] = data_obesitas['transporasi_biasa_digunakan'].replace('Motorbike', 'Transportasi umum')\n",
    "data_obesitas['transporasi_biasa_digunakan'] = data_obesitas['transporasi_biasa_digunakan'].replace('Automobile', 'Jalan kaki')\n",
    "\n",
    "data_obesitas"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "f6939328",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "Int64Index: 925 entries, 0 to 1510\n",
      "Data columns (total 17 columns):\n",
      " #   Column                          Non-Null Count  Dtype  \n",
      "---  ------                          --------------  -----  \n",
      " 0   jenis_kelamin                   925 non-null    object \n",
      " 1   umur                            925 non-null    int64  \n",
      " 2   tinggi_badan_kilogram           925 non-null    float64\n",
      " 3   berat_badan_meter               925 non-null    float64\n",
      " 4   histori_keluarga_kelebihan_BB   925 non-null    object \n",
      " 5   konsumsi_tinggi_kalori          925 non-null    object \n",
      " 6   konsumsi_sayuran                925 non-null    object \n",
      " 7   makan_berat                     925 non-null    object \n",
      " 8   ngemil                          925 non-null    object \n",
      " 9   merokok                         925 non-null    object \n",
      " 10  konsumsi_air_liter              925 non-null    object \n",
      " 11  pemantauan_kalori               925 non-null    object \n",
      " 12  aktifitas_fisik                 925 non-null    object \n",
      " 13  penggunaan_perangkat_teknologi  925 non-null    object \n",
      " 14  konsumsi_alkohol                925 non-null    object \n",
      " 15  transporasi_biasa_digunakan     925 non-null    object \n",
      " 16  kelas_obesitas                  925 non-null    object \n",
      "dtypes: float64(2), int64(1), object(14)\n",
      "memory usage: 130.1+ KB\n"
     ]
    }
   ],
   "source": [
    "data_obesitas.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "0b8ab3e2",
   "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_kilogram</th>\n",
       "      <th>berat_badan_meter</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.00</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>None</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.00</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>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>Laki-laki</td>\n",
       "      <td>29</td>\n",
       "      <td>1.62</td>\n",
       "      <td>53.00</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>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>23</td>\n",
       "      <td>1.50</td>\n",
       "      <td>55.00</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>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>Laki-laki</td>\n",
       "      <td>22</td>\n",
       "      <td>1.64</td>\n",
       "      <td>53.00</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>None</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>1502</th>\n",
       "      <td>Laki-laki</td>\n",
       "      <td>27</td>\n",
       "      <td>1.67</td>\n",
       "      <td>90.00</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>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1503</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>18</td>\n",
       "      <td>1.62</td>\n",
       "      <td>83.12</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>Tidak pernah</td>\n",
       "      <td>Sepeda motor</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1504</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>18</td>\n",
       "      <td>1.60</td>\n",
       "      <td>82.41</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>Tidak pernah</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>Sepeda motor</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1509</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>19</td>\n",
       "      <td>1.61</td>\n",
       "      <td>82.19</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>Tidak pernah</td>\n",
       "      <td>Sepeda motor</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1510</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>18</td>\n",
       "      <td>1.61</td>\n",
       "      <td>82.04</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>Tidak pernah</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>Sepeda motor</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>925 rows × 17 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     jenis_kelamin  umur  tinggi_badan_kilogram  berat_badan_meter  \\\n",
       "0        Perempuan    21                   1.62              64.00   \n",
       "1        Perempuan    21                   1.52              56.00   \n",
       "5        Laki-laki    29                   1.62              53.00   \n",
       "6        Perempuan    23                   1.50              55.00   \n",
       "7        Laki-laki    22                   1.64              53.00   \n",
       "...            ...   ...                    ...                ...   \n",
       "1502     Laki-laki    27                   1.67              90.00   \n",
       "1503     Perempuan    18                   1.62              83.12   \n",
       "1504     Perempuan    18                   1.60              82.41   \n",
       "1509     Perempuan    19                   1.61              82.19   \n",
       "1510     Perempuan    18                   1.61              82.04   \n",
       "\n",
       "     histori_keluarga_kelebihan_BB konsumsi_tinggi_kalori konsumsi_sayuran  \\\n",
       "0                               Ya                  Tidak    Kadang-kadang   \n",
       "1                               Ya                  Tidak           Selalu   \n",
       "5                            Tidak                     Ya    Kadang-kadang   \n",
       "6                               Ya                     Ya           Selalu   \n",
       "7                            Tidak                  Tidak    Kadang-kadang   \n",
       "...                            ...                    ...              ...   \n",
       "1502                            Ya                     Ya    Kadang-kadang   \n",
       "1503                            Ya                     Ya           Selalu   \n",
       "1504                            Ya                     Ya           Selalu   \n",
       "1509                            Ya                     Ya    Kadang-kadang   \n",
       "1510                            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",
       "5             3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "6             3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "7             3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "...          ...            ...     ...                ...               ...   \n",
       "1502          3x  Kadang-kadang   Tidak      Lebih 2 liter             Tidak   \n",
       "1503          3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "1504          3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "1509          3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "1510          3x  Kadang-kadang   Tidak          1-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",
       "5       Tidak pernah                        0-2 jam    Kadang-kadang   \n",
       "6           1-2 hari                        0-2 jam    Kadang-kadang   \n",
       "7           4-5 hari                        0-2 jam    Kadang-kadang   \n",
       "...              ...                            ...              ...   \n",
       "1502    Tidak pernah                        0-2 jam    Kadang-kadang   \n",
       "1503        1-2 hari                        0-2 jam     Tidak pernah   \n",
       "1504    Tidak pernah                        0-2 jam     Tidak pernah   \n",
       "1509    Tidak pernah                        0-2 jam     Tidak pernah   \n",
       "1510    Tidak pernah                        0-2 jam     Tidak pernah   \n",
       "\n",
       "     transporasi_biasa_digunakan kelas_obesitas  \n",
       "0                   Sepeda motor           None  \n",
       "1                   Sepeda motor           None  \n",
       "5                     Jalan kaki           None  \n",
       "6              Transportasi umum           None  \n",
       "7                   Sepeda motor           None  \n",
       "...                          ...            ...  \n",
       "1502                  Jalan kaki           None  \n",
       "1503                Sepeda motor           None  \n",
       "1504                Sepeda motor           None  \n",
       "1509                Sepeda motor           None  \n",
       "1510                Sepeda motor           None  \n",
       "\n",
       "[925 rows x 17 columns]"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_obesitas['kelas_obesitas'] = None\n",
    "data_obesitas"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "5b3ad836",
   "metadata": {},
   "outputs": [],
   "source": [
    "data_obesitas['BMI'] = data_obesitas['berat_badan_meter'] / (data_obesitas['tinggi_badan_kilogram'] ** 2)\n",
    "\n",
    "def determine_obesity_class(bmi):\n",
    "    if bmi < 18.5:\n",
    "        return 'berat_badan_kurang'\n",
    "    elif 18.5 <= bmi <= 22.9:\n",
    "        return 'normal'\n",
    "    elif 23 <= bmi <= 24.9:\n",
    "        return 'kelebihan_berat_badan'\n",
    "    elif 25 <= bmi <= 29.9:\n",
    "        return 'obesitas_I'\n",
    "    else:\n",
    "        return 'obesitas_II'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "0fb49805",
   "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_kilogram</th>\n",
       "      <th>berat_badan_meter</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>BMI</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.00</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>None</td>\n",
       "      <td>24.386526</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.00</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>None</td>\n",
       "      <td>24.238227</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>Laki-laki</td>\n",
       "      <td>29</td>\n",
       "      <td>1.62</td>\n",
       "      <td>53.00</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>None</td>\n",
       "      <td>20.195092</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>23</td>\n",
       "      <td>1.50</td>\n",
       "      <td>55.00</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>None</td>\n",
       "      <td>24.444444</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>Laki-laki</td>\n",
       "      <td>22</td>\n",
       "      <td>1.64</td>\n",
       "      <td>53.00</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>None</td>\n",
       "      <td>19.705532</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",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1502</th>\n",
       "      <td>Laki-laki</td>\n",
       "      <td>27</td>\n",
       "      <td>1.67</td>\n",
       "      <td>90.00</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>None</td>\n",
       "      <td>32.270788</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1503</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>18</td>\n",
       "      <td>1.62</td>\n",
       "      <td>83.12</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>Tidak pernah</td>\n",
       "      <td>Sepeda motor</td>\n",
       "      <td>None</td>\n",
       "      <td>31.672001</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1504</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>18</td>\n",
       "      <td>1.60</td>\n",
       "      <td>82.41</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>Tidak pernah</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>Sepeda motor</td>\n",
       "      <td>None</td>\n",
       "      <td>32.191406</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1509</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>19</td>\n",
       "      <td>1.61</td>\n",
       "      <td>82.19</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>Tidak pernah</td>\n",
       "      <td>Sepeda motor</td>\n",
       "      <td>None</td>\n",
       "      <td>31.707882</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1510</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>18</td>\n",
       "      <td>1.61</td>\n",
       "      <td>82.04</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>Tidak pernah</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>Sepeda motor</td>\n",
       "      <td>None</td>\n",
       "      <td>31.650014</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>925 rows × 18 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     jenis_kelamin  umur  tinggi_badan_kilogram  berat_badan_meter  \\\n",
       "0        Perempuan    21                   1.62              64.00   \n",
       "1        Perempuan    21                   1.52              56.00   \n",
       "5        Laki-laki    29                   1.62              53.00   \n",
       "6        Perempuan    23                   1.50              55.00   \n",
       "7        Laki-laki    22                   1.64              53.00   \n",
       "...            ...   ...                    ...                ...   \n",
       "1502     Laki-laki    27                   1.67              90.00   \n",
       "1503     Perempuan    18                   1.62              83.12   \n",
       "1504     Perempuan    18                   1.60              82.41   \n",
       "1509     Perempuan    19                   1.61              82.19   \n",
       "1510     Perempuan    18                   1.61              82.04   \n",
       "\n",
       "     histori_keluarga_kelebihan_BB konsumsi_tinggi_kalori konsumsi_sayuran  \\\n",
       "0                               Ya                  Tidak    Kadang-kadang   \n",
       "1                               Ya                  Tidak           Selalu   \n",
       "5                            Tidak                     Ya    Kadang-kadang   \n",
       "6                               Ya                     Ya           Selalu   \n",
       "7                            Tidak                  Tidak    Kadang-kadang   \n",
       "...                            ...                    ...              ...   \n",
       "1502                            Ya                     Ya    Kadang-kadang   \n",
       "1503                            Ya                     Ya           Selalu   \n",
       "1504                            Ya                     Ya           Selalu   \n",
       "1509                            Ya                     Ya    Kadang-kadang   \n",
       "1510                            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",
       "5             3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "6             3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "7             3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "...          ...            ...     ...                ...               ...   \n",
       "1502          3x  Kadang-kadang   Tidak      Lebih 2 liter             Tidak   \n",
       "1503          3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "1504          3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "1509          3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "1510          3x  Kadang-kadang   Tidak          1-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",
       "5       Tidak pernah                        0-2 jam    Kadang-kadang   \n",
       "6           1-2 hari                        0-2 jam    Kadang-kadang   \n",
       "7           4-5 hari                        0-2 jam    Kadang-kadang   \n",
       "...              ...                            ...              ...   \n",
       "1502    Tidak pernah                        0-2 jam    Kadang-kadang   \n",
       "1503        1-2 hari                        0-2 jam     Tidak pernah   \n",
       "1504    Tidak pernah                        0-2 jam     Tidak pernah   \n",
       "1509    Tidak pernah                        0-2 jam     Tidak pernah   \n",
       "1510    Tidak pernah                        0-2 jam     Tidak pernah   \n",
       "\n",
       "     transporasi_biasa_digunakan kelas_obesitas        BMI  \n",
       "0                   Sepeda motor           None  24.386526  \n",
       "1                   Sepeda motor           None  24.238227  \n",
       "5                     Jalan kaki           None  20.195092  \n",
       "6              Transportasi umum           None  24.444444  \n",
       "7                   Sepeda motor           None  19.705532  \n",
       "...                          ...            ...        ...  \n",
       "1502                  Jalan kaki           None  32.270788  \n",
       "1503                Sepeda motor           None  31.672001  \n",
       "1504                Sepeda motor           None  32.191406  \n",
       "1509                Sepeda motor           None  31.707882  \n",
       "1510                Sepeda motor           None  31.650014  \n",
       "\n",
       "[925 rows x 18 columns]"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_obesitas"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "60622995",
   "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_kilogram</th>\n",
       "      <th>berat_badan_meter</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>BMI</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.00</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",
       "      <td>24.386526</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.00</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",
       "      <td>24.238227</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>Laki-laki</td>\n",
       "      <td>29</td>\n",
       "      <td>1.62</td>\n",
       "      <td>53.00</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",
       "      <td>20.195092</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>23</td>\n",
       "      <td>1.50</td>\n",
       "      <td>55.00</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",
       "      <td>24.444444</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>Laki-laki</td>\n",
       "      <td>22</td>\n",
       "      <td>1.64</td>\n",
       "      <td>53.00</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",
       "      <td>19.705532</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",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1502</th>\n",
       "      <td>Laki-laki</td>\n",
       "      <td>27</td>\n",
       "      <td>1.67</td>\n",
       "      <td>90.00</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",
       "      <td>32.270788</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1503</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>18</td>\n",
       "      <td>1.62</td>\n",
       "      <td>83.12</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>Tidak pernah</td>\n",
       "      <td>Sepeda motor</td>\n",
       "      <td>obesitas_II</td>\n",
       "      <td>31.672001</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1504</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>18</td>\n",
       "      <td>1.60</td>\n",
       "      <td>82.41</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>Tidak pernah</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>Sepeda motor</td>\n",
       "      <td>obesitas_II</td>\n",
       "      <td>32.191406</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1509</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>19</td>\n",
       "      <td>1.61</td>\n",
       "      <td>82.19</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>Tidak pernah</td>\n",
       "      <td>Sepeda motor</td>\n",
       "      <td>obesitas_II</td>\n",
       "      <td>31.707882</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1510</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>18</td>\n",
       "      <td>1.61</td>\n",
       "      <td>82.04</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>Tidak pernah</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>Sepeda motor</td>\n",
       "      <td>obesitas_II</td>\n",
       "      <td>31.650014</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>925 rows × 18 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     jenis_kelamin  umur  tinggi_badan_kilogram  berat_badan_meter  \\\n",
       "0        Perempuan    21                   1.62              64.00   \n",
       "1        Perempuan    21                   1.52              56.00   \n",
       "5        Laki-laki    29                   1.62              53.00   \n",
       "6        Perempuan    23                   1.50              55.00   \n",
       "7        Laki-laki    22                   1.64              53.00   \n",
       "...            ...   ...                    ...                ...   \n",
       "1502     Laki-laki    27                   1.67              90.00   \n",
       "1503     Perempuan    18                   1.62              83.12   \n",
       "1504     Perempuan    18                   1.60              82.41   \n",
       "1509     Perempuan    19                   1.61              82.19   \n",
       "1510     Perempuan    18                   1.61              82.04   \n",
       "\n",
       "     histori_keluarga_kelebihan_BB konsumsi_tinggi_kalori konsumsi_sayuran  \\\n",
       "0                               Ya                  Tidak    Kadang-kadang   \n",
       "1                               Ya                  Tidak           Selalu   \n",
       "5                            Tidak                     Ya    Kadang-kadang   \n",
       "6                               Ya                     Ya           Selalu   \n",
       "7                            Tidak                  Tidak    Kadang-kadang   \n",
       "...                            ...                    ...              ...   \n",
       "1502                            Ya                     Ya    Kadang-kadang   \n",
       "1503                            Ya                     Ya           Selalu   \n",
       "1504                            Ya                     Ya           Selalu   \n",
       "1509                            Ya                     Ya    Kadang-kadang   \n",
       "1510                            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",
       "5             3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "6             3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "7             3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "...          ...            ...     ...                ...               ...   \n",
       "1502          3x  Kadang-kadang   Tidak      Lebih 2 liter             Tidak   \n",
       "1503          3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "1504          3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "1509          3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "1510          3x  Kadang-kadang   Tidak          1-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",
       "5       Tidak pernah                        0-2 jam    Kadang-kadang   \n",
       "6           1-2 hari                        0-2 jam    Kadang-kadang   \n",
       "7           4-5 hari                        0-2 jam    Kadang-kadang   \n",
       "...              ...                            ...              ...   \n",
       "1502    Tidak pernah                        0-2 jam    Kadang-kadang   \n",
       "1503        1-2 hari                        0-2 jam     Tidak pernah   \n",
       "1504    Tidak pernah                        0-2 jam     Tidak pernah   \n",
       "1509    Tidak pernah                        0-2 jam     Tidak pernah   \n",
       "1510    Tidak pernah                        0-2 jam     Tidak pernah   \n",
       "\n",
       "     transporasi_biasa_digunakan         kelas_obesitas        BMI  \n",
       "0                   Sepeda motor  kelebihan_berat_badan  24.386526  \n",
       "1                   Sepeda motor  kelebihan_berat_badan  24.238227  \n",
       "5                     Jalan kaki                 normal  20.195092  \n",
       "6              Transportasi umum  kelebihan_berat_badan  24.444444  \n",
       "7                   Sepeda motor                 normal  19.705532  \n",
       "...                          ...                    ...        ...  \n",
       "1502                  Jalan kaki            obesitas_II  32.270788  \n",
       "1503                Sepeda motor            obesitas_II  31.672001  \n",
       "1504                Sepeda motor            obesitas_II  32.191406  \n",
       "1509                Sepeda motor            obesitas_II  31.707882  \n",
       "1510                Sepeda motor            obesitas_II  31.650014  \n",
       "\n",
       "[925 rows x 18 columns]"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_obesitas['kelas_obesitas'] = data_obesitas['BMI'].apply(determine_obesity_class)\n",
    "data_obesitas"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "a02f548c",
   "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_kilogram</th>\n",
       "      <th>berat_badan_meter</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.00</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.00</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>5</th>\n",
       "      <td>Laki-laki</td>\n",
       "      <td>29</td>\n",
       "      <td>1.62</td>\n",
       "      <td>53.00</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>6</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>23</td>\n",
       "      <td>1.50</td>\n",
       "      <td>55.00</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>7</th>\n",
       "      <td>Laki-laki</td>\n",
       "      <td>22</td>\n",
       "      <td>1.64</td>\n",
       "      <td>53.00</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>1502</th>\n",
       "      <td>Laki-laki</td>\n",
       "      <td>27</td>\n",
       "      <td>1.67</td>\n",
       "      <td>90.00</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>1503</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>18</td>\n",
       "      <td>1.62</td>\n",
       "      <td>83.12</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>Tidak pernah</td>\n",
       "      <td>Sepeda motor</td>\n",
       "      <td>obesitas_II</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1504</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>18</td>\n",
       "      <td>1.60</td>\n",
       "      <td>82.41</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>Tidak pernah</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>Sepeda motor</td>\n",
       "      <td>obesitas_II</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1509</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>19</td>\n",
       "      <td>1.61</td>\n",
       "      <td>82.19</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>Tidak pernah</td>\n",
       "      <td>Sepeda motor</td>\n",
       "      <td>obesitas_II</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1510</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>18</td>\n",
       "      <td>1.61</td>\n",
       "      <td>82.04</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>Tidak pernah</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>Sepeda motor</td>\n",
       "      <td>obesitas_II</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>925 rows × 17 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     jenis_kelamin  umur  tinggi_badan_kilogram  berat_badan_meter  \\\n",
       "0        Perempuan    21                   1.62              64.00   \n",
       "1        Perempuan    21                   1.52              56.00   \n",
       "5        Laki-laki    29                   1.62              53.00   \n",
       "6        Perempuan    23                   1.50              55.00   \n",
       "7        Laki-laki    22                   1.64              53.00   \n",
       "...            ...   ...                    ...                ...   \n",
       "1502     Laki-laki    27                   1.67              90.00   \n",
       "1503     Perempuan    18                   1.62              83.12   \n",
       "1504     Perempuan    18                   1.60              82.41   \n",
       "1509     Perempuan    19                   1.61              82.19   \n",
       "1510     Perempuan    18                   1.61              82.04   \n",
       "\n",
       "     histori_keluarga_kelebihan_BB konsumsi_tinggi_kalori konsumsi_sayuran  \\\n",
       "0                               Ya                  Tidak    Kadang-kadang   \n",
       "1                               Ya                  Tidak           Selalu   \n",
       "5                            Tidak                     Ya    Kadang-kadang   \n",
       "6                               Ya                     Ya           Selalu   \n",
       "7                            Tidak                  Tidak    Kadang-kadang   \n",
       "...                            ...                    ...              ...   \n",
       "1502                            Ya                     Ya    Kadang-kadang   \n",
       "1503                            Ya                     Ya           Selalu   \n",
       "1504                            Ya                     Ya           Selalu   \n",
       "1509                            Ya                     Ya    Kadang-kadang   \n",
       "1510                            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",
       "5             3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "6             3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "7             3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "...          ...            ...     ...                ...               ...   \n",
       "1502          3x  Kadang-kadang   Tidak      Lebih 2 liter             Tidak   \n",
       "1503          3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "1504          3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "1509          3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "1510          3x  Kadang-kadang   Tidak          1-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",
       "5       Tidak pernah                        0-2 jam    Kadang-kadang   \n",
       "6           1-2 hari                        0-2 jam    Kadang-kadang   \n",
       "7           4-5 hari                        0-2 jam    Kadang-kadang   \n",
       "...              ...                            ...              ...   \n",
       "1502    Tidak pernah                        0-2 jam    Kadang-kadang   \n",
       "1503        1-2 hari                        0-2 jam     Tidak pernah   \n",
       "1504    Tidak pernah                        0-2 jam     Tidak pernah   \n",
       "1509    Tidak pernah                        0-2 jam     Tidak pernah   \n",
       "1510    Tidak pernah                        0-2 jam     Tidak pernah   \n",
       "\n",
       "     transporasi_biasa_digunakan         kelas_obesitas  \n",
       "0                   Sepeda motor  kelebihan_berat_badan  \n",
       "1                   Sepeda motor  kelebihan_berat_badan  \n",
       "5                     Jalan kaki                 normal  \n",
       "6              Transportasi umum  kelebihan_berat_badan  \n",
       "7                   Sepeda motor                 normal  \n",
       "...                          ...                    ...  \n",
       "1502                  Jalan kaki            obesitas_II  \n",
       "1503                Sepeda motor            obesitas_II  \n",
       "1504                Sepeda motor            obesitas_II  \n",
       "1509                Sepeda motor            obesitas_II  \n",
       "1510                Sepeda motor            obesitas_II  \n",
       "\n",
       "[925 rows x 17 columns]"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_obesitas.drop(columns=['BMI'], inplace=True)\n",
    "data_obesitas"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "b9413928",
   "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_kilogram</th>\n",
       "      <th>berat_badan_meter</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.00</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.00</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>5</th>\n",
       "      <td>Laki-laki</td>\n",
       "      <td>29</td>\n",
       "      <td>1.62</td>\n",
       "      <td>53.00</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>6</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>23</td>\n",
       "      <td>1.50</td>\n",
       "      <td>55.00</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>7</th>\n",
       "      <td>Laki-laki</td>\n",
       "      <td>22</td>\n",
       "      <td>1.64</td>\n",
       "      <td>53.00</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>1484</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>37</td>\n",
       "      <td>1.55</td>\n",
       "      <td>76.08</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>1487</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>39</td>\n",
       "      <td>1.56</td>\n",
       "      <td>76.66</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>1488</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>37</td>\n",
       "      <td>1.50</td>\n",
       "      <td>75.28</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>1489</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>41</td>\n",
       "      <td>1.54</td>\n",
       "      <td>77.05</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>1490</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>43</td>\n",
       "      <td>1.59</td>\n",
       "      <td>77.00</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>530 rows × 17 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     jenis_kelamin  umur  tinggi_badan_kilogram  berat_badan_meter  \\\n",
       "0        Perempuan    21                   1.62              64.00   \n",
       "1        Perempuan    21                   1.52              56.00   \n",
       "5        Laki-laki    29                   1.62              53.00   \n",
       "6        Perempuan    23                   1.50              55.00   \n",
       "7        Laki-laki    22                   1.64              53.00   \n",
       "...            ...   ...                    ...                ...   \n",
       "1484     Perempuan    37                   1.55              76.08   \n",
       "1487     Perempuan    39                   1.56              76.66   \n",
       "1488     Perempuan    37                   1.50              75.28   \n",
       "1489     Perempuan    41                   1.54              77.05   \n",
       "1490     Perempuan    43                   1.59              77.00   \n",
       "\n",
       "     histori_keluarga_kelebihan_BB konsumsi_tinggi_kalori konsumsi_sayuran  \\\n",
       "0                               Ya                  Tidak    Kadang-kadang   \n",
       "1                               Ya                  Tidak           Selalu   \n",
       "5                            Tidak                     Ya    Kadang-kadang   \n",
       "6                               Ya                     Ya           Selalu   \n",
       "7                            Tidak                  Tidak    Kadang-kadang   \n",
       "...                            ...                    ...              ...   \n",
       "1484                            Ya                     Ya    Kadang-kadang   \n",
       "1487                            Ya                     Ya    Kadang-kadang   \n",
       "1488                            Ya                     Ya    Kadang-kadang   \n",
       "1489                            Ya                     Ya    Kadang-kadang   \n",
       "1490                            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",
       "5             3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "6             3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "7             3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "...          ...            ...     ...                ...               ...   \n",
       "1484          3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "1487          3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "1488          3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "1489          3x  Kadang-kadang   Tidak      Lebih 2 liter             Tidak   \n",
       "1490          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",
       "5       Tidak pernah                        0-2 jam    Kadang-kadang   \n",
       "6           1-2 hari                        0-2 jam    Kadang-kadang   \n",
       "7           4-5 hari                        0-2 jam    Kadang-kadang   \n",
       "...              ...                            ...              ...   \n",
       "1484        1-2 hari                        0-2 jam    Kadang-kadang   \n",
       "1487    Tidak pernah                        0-2 jam    Kadang-kadang   \n",
       "1488    Tidak pernah                        0-2 jam    Kadang-kadang   \n",
       "1489    Tidak pernah                        0-2 jam    Kadang-kadang   \n",
       "1490    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",
       "5                     Jalan kaki                 normal  \n",
       "6              Transportasi umum  kelebihan_berat_badan  \n",
       "7                   Sepeda motor                 normal  \n",
       "...                          ...                    ...  \n",
       "1484                  Jalan kaki            obesitas_II  \n",
       "1487                  Jalan kaki            obesitas_II  \n",
       "1488                  Jalan kaki            obesitas_II  \n",
       "1489                  Jalan kaki            obesitas_II  \n",
       "1490                  Jalan kaki            obesitas_II  \n",
       "\n",
       "[530 rows x 17 columns]"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# data_obesitas = data_obesitas[~((data_obesitas['kelas_obesitas'] == 'berat_badan_kurang') & (data_obesitas['umur'].between(20, 23)))]\n",
    "data_obesitas = data_obesitas[~((data_obesitas['kelas_obesitas'] == 'obesitas_I') & (data_obesitas['umur'] < 30))]\n",
    "data_obesitas = data_obesitas[~((data_obesitas['kelas_obesitas'] == 'obesitas_II') & (data_obesitas['umur'] < 30))]\n",
    "data_obesitas"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "2b372c6d",
   "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>0</th>\n",
       "      <td>berat_badan_kurang</td>\n",
       "      <td>168</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>normal</td>\n",
       "      <td>141</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>obesitas_I</td>\n",
       "      <td>87</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>kelebihan_berat_badan</td>\n",
       "      <td>68</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",
       "0     berat_badan_kurang     168\n",
       "1                 normal     141\n",
       "2             obesitas_I      87\n",
       "3  kelebihan_berat_badan      68\n",
       "4            obesitas_II      66"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "kelas_obesitas = data_obesitas['kelas_obesitas'].value_counts().rename_axis('kelas_obesitas').reset_index(name='jumlah')\n",
    "kelas_obesitas"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "255eacab",
   "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>0</th>\n",
       "      <td>berat_badan_kurang</td>\n",
       "      <td>168</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</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>68</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>obesitas_I</td>\n",
       "      <td>87</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",
       "0     berat_badan_kurang     168\n",
       "1                 normal     141\n",
       "3  kelebihan_berat_badan      68\n",
       "2             obesitas_I      87\n",
       "4            obesitas_II      66"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "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": 33,
   "id": "36009d70",
   "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>0</th>\n",
       "      <td>berat_badan_kurang</td>\n",
       "      <td>168</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</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>68</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>obesitas_I</td>\n",
       "      <td>87</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",
       "0     berat_badan_kurang     168\n",
       "1                 normal     141\n",
       "3  kelebihan_berat_badan      68\n",
       "2             obesitas_I      87\n",
       "4            obesitas_II      66"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# cek balance kelas data\n",
    "distribusi_kelas = data_obesitas['kelas_obesitas'].value_counts().rename_axis('kelas_obesitas').reset_index(name='jumlah')\n",
    "\n",
    "distribusi_kelas['kelas_obesitas'] = pd.Categorical(distribusi_kelas['kelas_obesitas'], categories=urutan_obesitas, ordered=True)\n",
    "distribusi_kelas = distribusi_kelas.sort_values(by='kelas_obesitas')\n",
    "distribusi_kelas"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "03dbbfa5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 42308 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(distribusi_kelas['jumlah'], labels=distribusi_kelas['kelas_obesitas'], autopct='%1.1f%%', colors=colors)\n",
    "\n",
    "plt.title('Perbandingan Persentase Kelas Obesitas')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "d34d024b",
   "metadata": {},
   "outputs": [],
   "source": [
    "# from sklearn.utils import resample\n",
    "\n",
    "# # Tentukan ukuran sampel yang seimbang\n",
    "# # Dalam hal ini, kita memilih ukuran kelas terkecil, yaitu 68 (kelebihan_berat_badan)\n",
    "# n_samples = data_obesitas['kelas_obesitas'].value_counts().min()\n",
    "\n",
    "# # List untuk menampung DataFrame yang sudah disampling\n",
    "# df_resampled = []\n",
    "\n",
    "# # Undersample setiap kelas ke ukuran n_samples\n",
    "# for kelas in data_obesitas['kelas_obesitas'].unique():\n",
    "#     df_kelas = data_obesitas[data_obesitas['kelas_obesitas'] == kelas]\n",
    "#     df_kelas_resampled = resample(df_kelas, replace=False, n_samples=n_samples, random_state=0)\n",
    "#     df_resampled.append(df_kelas_resampled)\n",
    "\n",
    "# # Gabungkan semua kelas yang sudah disampling\n",
    "# data_obesitas = pd.concat(df_resampled)\n",
    "\n",
    "# # Tampilkan distribusi kelas setelah undersampling\n",
    "# print(data_obesitas['kelas_obesitas'].value_counts())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "9fe3b0bb",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "X = data_obesitas.drop(columns='kelas_obesitas', axis = 1)\n",
    "Y = data_obesitas['kelas_obesitas']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "952f8ceb",
   "metadata": {},
   "outputs": [
    {
     "ename": "ImportError",
     "evalue": "cannot import name '_get_column_indices' from 'sklearn.utils' (C:\\Users\\nurul\\anaconda3\\Lib\\site-packages\\sklearn\\utils\\__init__.py)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mImportError\u001b[0m                               Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[37], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mimblearn\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01munder_sampling\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m TomekLinks\n\u001b[0;32m      3\u001b[0m \u001b[38;5;66;03m# Inisialisasi TomekLinks\u001b[39;00m\n\u001b[0;32m      4\u001b[0m tl \u001b[38;5;241m=\u001b[39m TomekLinks()\n",
      "File \u001b[1;32m~\\anaconda3\\Lib\\site-packages\\imblearn\\__init__.py:52\u001b[0m\n\u001b[0;32m     48\u001b[0m     sys\u001b[38;5;241m.\u001b[39mstderr\u001b[38;5;241m.\u001b[39mwrite(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mPartial import of imblearn during the build process.\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m     49\u001b[0m     \u001b[38;5;66;03m# We are not importing the rest of scikit-learn during the build\u001b[39;00m\n\u001b[0;32m     50\u001b[0m     \u001b[38;5;66;03m# process, as it may not be compiled yet\u001b[39;00m\n\u001b[0;32m     51\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m---> 52\u001b[0m     \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m (\n\u001b[0;32m     53\u001b[0m         combine,\n\u001b[0;32m     54\u001b[0m         ensemble,\n\u001b[0;32m     55\u001b[0m         exceptions,\n\u001b[0;32m     56\u001b[0m         metrics,\n\u001b[0;32m     57\u001b[0m         over_sampling,\n\u001b[0;32m     58\u001b[0m         pipeline,\n\u001b[0;32m     59\u001b[0m         tensorflow,\n\u001b[0;32m     60\u001b[0m         under_sampling,\n\u001b[0;32m     61\u001b[0m         utils,\n\u001b[0;32m     62\u001b[0m     )\n\u001b[0;32m     63\u001b[0m     \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01m_version\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m __version__\n\u001b[0;32m     64\u001b[0m     \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mbase\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m FunctionSampler\n",
      "File \u001b[1;32m~\\anaconda3\\Lib\\site-packages\\imblearn\\combine\\__init__.py:5\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[38;5;124;03m\"\"\"The :mod:`imblearn.combine` provides methods which combine\u001b[39;00m\n\u001b[0;32m      2\u001b[0m \u001b[38;5;124;03mover-sampling and under-sampling.\u001b[39;00m\n\u001b[0;32m      3\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m----> 5\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01m_smote_enn\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m SMOTEENN\n\u001b[0;32m      6\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01m_smote_tomek\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m SMOTETomek\n\u001b[0;32m      8\u001b[0m __all__ \u001b[38;5;241m=\u001b[39m [\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mSMOTEENN\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mSMOTETomek\u001b[39m\u001b[38;5;124m\"\u001b[39m]\n",
      "File \u001b[1;32m~\\anaconda3\\Lib\\site-packages\\imblearn\\combine\\_smote_enn.py:13\u001b[0m\n\u001b[0;32m     10\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01msklearn\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mutils\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m check_X_y\n\u001b[0;32m     12\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mbase\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m BaseSampler\n\u001b[1;32m---> 13\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mover_sampling\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m SMOTE\n\u001b[0;32m     14\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mover_sampling\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mbase\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m BaseOverSampler\n\u001b[0;32m     15\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01munder_sampling\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m EditedNearestNeighbours\n",
      "File \u001b[1;32m~\\anaconda3\\Lib\\site-packages\\imblearn\\over_sampling\\__init__.py:8\u001b[0m\n\u001b[0;32m      6\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01m_adasyn\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m ADASYN\n\u001b[0;32m      7\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01m_random_over_sampler\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m RandomOverSampler\n\u001b[1;32m----> 8\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01m_smote\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m SMOTE, SMOTEN, SMOTENC, SVMSMOTE, BorderlineSMOTE, KMeansSMOTE\n\u001b[0;32m     10\u001b[0m __all__ \u001b[38;5;241m=\u001b[39m [\n\u001b[0;32m     11\u001b[0m     \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mADASYN\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[0;32m     12\u001b[0m     \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mRandomOverSampler\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[1;32m   (...)\u001b[0m\n\u001b[0;32m     18\u001b[0m     \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mSMOTEN\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[0;32m     19\u001b[0m ]\n",
      "File \u001b[1;32m~\\anaconda3\\Lib\\site-packages\\imblearn\\over_sampling\\_smote\\__init__.py:1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mbase\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m SMOTE, SMOTEN, SMOTENC\n\u001b[0;32m      2\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mcluster\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m KMeansSMOTE\n\u001b[0;32m      3\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mfilter\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m SVMSMOTE, BorderlineSMOTE\n",
      "File \u001b[1;32m~\\anaconda3\\Lib\\site-packages\\imblearn\\over_sampling\\_smote\\base.py:18\u001b[0m\n\u001b[0;32m     16\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01msklearn\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mexceptions\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m DataConversionWarning\n\u001b[0;32m     17\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01msklearn\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mpreprocessing\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m OneHotEncoder, OrdinalEncoder\n\u001b[1;32m---> 18\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01msklearn\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mutils\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m (\n\u001b[0;32m     19\u001b[0m     _get_column_indices,\n\u001b[0;32m     20\u001b[0m     _safe_indexing,\n\u001b[0;32m     21\u001b[0m     check_array,\n\u001b[0;32m     22\u001b[0m     check_random_state,\n\u001b[0;32m     23\u001b[0m )\n\u001b[0;32m     24\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01msklearn\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mutils\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01msparsefuncs_fast\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m (\n\u001b[0;32m     25\u001b[0m     csr_mean_variance_axis0,\n\u001b[0;32m     26\u001b[0m )\n\u001b[0;32m     27\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01msklearn\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mutils\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mvalidation\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m _num_features\n",
      "\u001b[1;31mImportError\u001b[0m: cannot import name '_get_column_indices' from 'sklearn.utils' (C:\\Users\\nurul\\anaconda3\\Lib\\site-packages\\sklearn\\utils\\__init__.py)"
     ]
    }
   ],
   "source": [
    "from imblearn.under_sampling import TomekLinks\n",
    "\n",
    "# Inisialisasi TomekLinks\n",
    "tl = TomekLinks()\n",
    "\n",
    "# Lakukan undersampling\n",
    "X_res, y_res = tl.fit_resample(X, Y)\n",
    "\n",
    "# Gabungkan kembali fitur dan target ke dalam DataFrame\n",
    "data_obesitas = pd.concat([X_res, y_res], axis=1)\n",
    "\n",
    "# Tampilkan distribusi kelas setelah undersampling\n",
    "print(data_obesitas['kelas_obesitas'].value_counts())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "399e412f",
   "metadata": {},
   "outputs": [],
   "source": [
    "data_obesitas"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a1633388",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "98234c79",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 375,
   "id": "b56901f7",
   "metadata": {},
   "outputs": [],
   "source": [
    "X_sample, _, y_sample, _ = train_test_split(X, Y, test_size=0.8, stratify=Y, random_state=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 376,
   "id": "6d6df40a",
   "metadata": {},
   "outputs": [],
   "source": [
    "data_obesitas = pd.concat([X_sample, y_sample], axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 377,
   "id": "4eb417ea",
   "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_kilogram</th>\n",
       "      <th>berat_badan_meter</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>303</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>16</td>\n",
       "      <td>1.57</td>\n",
       "      <td>49.0</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Lebih 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>Sepeda motor</td>\n",
       "      <td>normal</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>396</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>38</td>\n",
       "      <td>1.55</td>\n",
       "      <td>59.0</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>2-4 hari</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Sering</td>\n",
       "      <td>Jalan kaki</td>\n",
       "      <td>kelebihan_berat_badan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>682</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>19</td>\n",
       "      <td>1.69</td>\n",
       "      <td>49.9</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Lebih 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>berat_badan_kurang</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>271</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>19</td>\n",
       "      <td>1.50</td>\n",
       "      <td>50.0</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Kadang-kadang</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>3-5 jam</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Sepeda motor</td>\n",
       "      <td>normal</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>372</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>18</td>\n",
       "      <td>1.62</td>\n",
       "      <td>58.0</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>Tidak pernah</td>\n",
       "      <td>3-5 jam</td>\n",
       "      <td>Tidak pernah</td>\n",
       "      <td>Jalan kaki</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>223</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>22</td>\n",
       "      <td>1.61</td>\n",
       "      <td>63.0</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>Lebih 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>Sepeda motor</td>\n",
       "      <td>kelebihan_berat_badan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>175</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>38</td>\n",
       "      <td>1.64</td>\n",
       "      <td>59.8</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>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>362</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>37</td>\n",
       "      <td>1.65</td>\n",
       "      <td>73.0</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>1-2 hari</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>98</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>21</td>\n",
       "      <td>1.52</td>\n",
       "      <td>42.0</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Tidak</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>367</th>\n",
       "      <td>Perempuan</td>\n",
       "      <td>40</td>\n",
       "      <td>1.58</td>\n",
       "      <td>63.0</td>\n",
       "      <td>Tidak</td>\n",
       "      <td>Ya</td>\n",
       "      <td>Kadang-kadang</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>4-5 hari</td>\n",
       "      <td>0-2 jam</td>\n",
       "      <td>Kadang-kadang</td>\n",
       "      <td>Sepeda motor</td>\n",
       "      <td>obesitas_I</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>106 rows × 17 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    jenis_kelamin  umur  tinggi_badan_kilogram  berat_badan_meter  \\\n",
       "303     Perempuan    16                   1.57               49.0   \n",
       "396     Perempuan    38                   1.55               59.0   \n",
       "682     Perempuan    19                   1.69               49.9   \n",
       "271     Perempuan    19                   1.50               50.0   \n",
       "372     Perempuan    18                   1.62               58.0   \n",
       "..            ...   ...                    ...                ...   \n",
       "223     Perempuan    22                   1.61               63.0   \n",
       "175     Perempuan    38                   1.64               59.8   \n",
       "362     Perempuan    37                   1.65               73.0   \n",
       "98      Perempuan    21                   1.52               42.0   \n",
       "367     Perempuan    40                   1.58               63.0   \n",
       "\n",
       "    histori_keluarga_kelebihan_BB konsumsi_tinggi_kalori konsumsi_sayuran  \\\n",
       "303                         Tidak                     Ya    Kadang-kadang   \n",
       "396                            Ya                  Tidak           Selalu   \n",
       "682                         Tidak                     Ya    Kadang-kadang   \n",
       "271                         Tidak                     Ya    Kadang-kadang   \n",
       "372                         Tidak                     Ya           Selalu   \n",
       "..                            ...                    ...              ...   \n",
       "223                            Ya                     Ya           Selalu   \n",
       "175                            Ya                     Ya    Kadang-kadang   \n",
       "362                            Ya                  Tidak           Selalu   \n",
       "98                          Tidak                  Tidak           Selalu   \n",
       "367                         Tidak                     Ya    Kadang-kadang   \n",
       "\n",
       "    makan_berat         ngemil merokok konsumsi_air_liter pemantauan_kalori  \\\n",
       "303    Lebih 3x         Selalu   Tidak          1-2 liter             Tidak   \n",
       "396          3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "682    Lebih 3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "271          3x         Sering   Tidak          1-2 liter             Tidak   \n",
       "372          3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "..          ...            ...     ...                ...               ...   \n",
       "223          3x         Sering   Tidak      Lebih 2 liter             Tidak   \n",
       "175          3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "362          3x  Kadang-kadang   Tidak          1-2 liter             Tidak   \n",
       "98         1-2x         Sering   Tidak          1-2 liter             Tidak   \n",
       "367          3x         Sering   Tidak          1-2 liter             Tidak   \n",
       "\n",
       "    aktifitas_fisik penggunaan_perangkat_teknologi konsumsi_alkohol  \\\n",
       "303    Tidak pernah                        0-2 jam    Kadang-kadang   \n",
       "396        2-4 hari                        0-2 jam           Sering   \n",
       "682        2-4 hari                        0-2 jam    Kadang-kadang   \n",
       "271    Tidak pernah                        3-5 jam    Kadang-kadang   \n",
       "372    Tidak pernah                        3-5 jam     Tidak pernah   \n",
       "..              ...                            ...              ...   \n",
       "223        1-2 hari                        0-2 jam     Tidak pernah   \n",
       "175        2-4 hari                        0-2 jam     Tidak pernah   \n",
       "362        1-2 hari                        0-2 jam    Kadang-kadang   \n",
       "98     Tidak pernah                        0-2 jam    Kadang-kadang   \n",
       "367        4-5 hari                        0-2 jam    Kadang-kadang   \n",
       "\n",
       "    transporasi_biasa_digunakan         kelas_obesitas  \n",
       "303                Sepeda motor                 normal  \n",
       "396                  Jalan kaki  kelebihan_berat_badan  \n",
       "682                Sepeda motor     berat_badan_kurang  \n",
       "271                Sepeda motor                 normal  \n",
       "372                  Jalan kaki                 normal  \n",
       "..                          ...                    ...  \n",
       "223                Sepeda motor  kelebihan_berat_badan  \n",
       "175                Sepeda motor                 normal  \n",
       "362                  Jalan kaki             obesitas_I  \n",
       "98                 Sepeda motor     berat_badan_kurang  \n",
       "367                Sepeda motor             obesitas_I  \n",
       "\n",
       "[106 rows x 17 columns]"
      ]
     },
     "execution_count": 377,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_obesitas"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2379d234",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2a907dc1",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 378,
   "id": "7afd93ea",
   "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_kilogram</th>\n",
       "      <th>berat_badan_meter</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>303</th>\n",
       "      <td>0</td>\n",
       "      <td>16</td>\n",
       "      <td>1.57</td>\n",
       "      <td>49.0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>3</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>normal</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>396</th>\n",
       "      <td>0</td>\n",
       "      <td>38</td>\n",
       "      <td>1.55</td>\n",
       "      <td>59.0</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>2</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>kelebihan_berat_badan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>682</th>\n",
       "      <td>0</td>\n",
       "      <td>19</td>\n",
       "      <td>1.69</td>\n",
       "      <td>49.9</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>2</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>271</th>\n",
       "      <td>0</td>\n",
       "      <td>19</td>\n",
       "      <td>1.50</td>\n",
       "      <td>50.0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>normal</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>372</th>\n",
       "      <td>0</td>\n",
       "      <td>18</td>\n",
       "      <td>1.62</td>\n",
       "      <td>58.0</td>\n",
       "      <td>0</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>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>4</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>223</th>\n",
       "      <td>0</td>\n",
       "      <td>22</td>\n",
       "      <td>1.61</td>\n",
       "      <td>63.0</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>1</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>175</th>\n",
       "      <td>0</td>\n",
       "      <td>38</td>\n",
       "      <td>1.64</td>\n",
       "      <td>59.8</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>2</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>normal</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>362</th>\n",
       "      <td>0</td>\n",
       "      <td>37</td>\n",
       "      <td>1.65</td>\n",
       "      <td>73.0</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>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>obesitas_I</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>98</th>\n",
       "      <td>0</td>\n",
       "      <td>21</td>\n",
       "      <td>1.52</td>\n",
       "      <td>42.0</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>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>367</th>\n",
       "      <td>0</td>\n",
       "      <td>40</td>\n",
       "      <td>1.58</td>\n",
       "      <td>63.0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>2</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>obesitas_I</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>106 rows × 17 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     jenis_kelamin  umur  tinggi_badan_kilogram  berat_badan_meter  \\\n",
       "303              0    16                   1.57               49.0   \n",
       "396              0    38                   1.55               59.0   \n",
       "682              0    19                   1.69               49.9   \n",
       "271              0    19                   1.50               50.0   \n",
       "372              0    18                   1.62               58.0   \n",
       "..             ...   ...                    ...                ...   \n",
       "223              0    22                   1.61               63.0   \n",
       "175              0    38                   1.64               59.8   \n",
       "362              0    37                   1.65               73.0   \n",
       "98               0    21                   1.52               42.0   \n",
       "367              0    40                   1.58               63.0   \n",
       "\n",
       "     histori_keluarga_kelebihan_BB  konsumsi_tinggi_kalori  konsumsi_sayuran  \\\n",
       "303                              0                       1                 1   \n",
       "396                              1                       0                 2   \n",
       "682                              0                       1                 1   \n",
       "271                              0                       1                 1   \n",
       "372                              0                       1                 2   \n",
       "..                             ...                     ...               ...   \n",
       "223                              1                       1                 2   \n",
       "175                              1                       1                 1   \n",
       "362                              1                       0                 2   \n",
       "98                               0                       0                 2   \n",
       "367                              0                       1                 1   \n",
       "\n",
       "     makan_berat  ngemil  merokok  konsumsi_air_liter  pemantauan_kalori  \\\n",
       "303            3       3        0                   2                  0   \n",
       "396            2       1        0                   2                  0   \n",
       "682            3       1        0                   2                  0   \n",
       "271            2       2        0                   2                  0   \n",
       "372            2       1        0                   2                  0   \n",
       "..           ...     ...      ...                 ...                ...   \n",
       "223            2       2        0                   3                  0   \n",
       "175            2       1        0                   2                  0   \n",
       "362            2       1        0                   2                  0   \n",
       "98             1       2        0                   2                  0   \n",
       "367            2       2        0                   2                  0   \n",
       "\n",
       "     aktifitas_fisik  penggunaan_perangkat_teknologi  konsumsi_alkohol  \\\n",
       "303                0                               1                 1   \n",
       "396                2                               1                 2   \n",
       "682                2                               1                 1   \n",
       "271                0                               2                 1   \n",
       "372                0                               2                 0   \n",
       "..               ...                             ...               ...   \n",
       "223                1                               1                 0   \n",
       "175                2                               1                 0   \n",
       "362                1                               1                 1   \n",
       "98                 0                               1                 1   \n",
       "367                3                               1                 1   \n",
       "\n",
       "     transporasi_biasa_digunakan         kelas_obesitas  \n",
       "303                            1                 normal  \n",
       "396                            4  kelebihan_berat_badan  \n",
       "682                            1     berat_badan_kurang  \n",
       "271                            1                 normal  \n",
       "372                            4                 normal  \n",
       "..                           ...                    ...  \n",
       "223                            1  kelebihan_berat_badan  \n",
       "175                            1                 normal  \n",
       "362                            4             obesitas_I  \n",
       "98                             1     berat_badan_kurang  \n",
       "367                            1             obesitas_I  \n",
       "\n",
       "[106 rows x 17 columns]"
      ]
     },
     "execution_count": 378,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_obesitas['jenis_kelamin'] = data_obesitas['jenis_kelamin'].replace('Laki-laki', 1)\n",
    "data_obesitas['jenis_kelamin'] = data_obesitas['jenis_kelamin'].replace('Perempuan', 0)\n",
    "\n",
    "data_obesitas['histori_keluarga_kelebihan_BB'] = data_obesitas['histori_keluarga_kelebihan_BB'].replace('Ya', 1)\n",
    "data_obesitas['histori_keluarga_kelebihan_BB'] = data_obesitas['histori_keluarga_kelebihan_BB'].replace('Tidak', 0)\n",
    "\n",
    "data_obesitas['konsumsi_tinggi_kalori'] = data_obesitas['konsumsi_tinggi_kalori'].replace('Ya', 1)\n",
    "data_obesitas['konsumsi_tinggi_kalori'] = data_obesitas['konsumsi_tinggi_kalori'].replace('Tidak', 0)\n",
    "\n",
    "data_obesitas['konsumsi_sayuran'] = data_obesitas['konsumsi_sayuran'].replace('Selalu', 2)\n",
    "data_obesitas['konsumsi_sayuran'] = data_obesitas['konsumsi_sayuran'].replace('Kadang-kadang', 1)\n",
    "data_obesitas['konsumsi_sayuran'] = data_obesitas['konsumsi_sayuran'].replace('Tidak pernah', 0)\n",
    "\n",
    "data_obesitas['makan_berat'] = data_obesitas['makan_berat'].replace('Lebih 3x', 3)\n",
    "data_obesitas['makan_berat'] = data_obesitas['makan_berat'].replace('3x', 2)\n",
    "data_obesitas['makan_berat'] = data_obesitas['makan_berat'].replace('1-2x', 1)\n",
    "\n",
    "data_obesitas['ngemil'] = data_obesitas['ngemil'].replace('Selalu', 3)\n",
    "data_obesitas['ngemil'] = data_obesitas['ngemil'].replace('Sering', 2)\n",
    "data_obesitas['ngemil'] = data_obesitas['ngemil'].replace('Kadang-kadang', 1)\n",
    "data_obesitas['ngemil'] = data_obesitas['ngemil'].replace('Tidak pernah', 0)\n",
    "\n",
    "data_obesitas['merokok'] = data_obesitas['merokok'].replace('Ya', 1)\n",
    "data_obesitas['merokok'] = data_obesitas['merokok'].replace('Tidak', 0)\n",
    "\n",
    "data_obesitas['konsumsi_air_liter'] = data_obesitas['konsumsi_air_liter'].replace('Lebih 2 liter', 3)\n",
    "data_obesitas['konsumsi_air_liter'] = data_obesitas['konsumsi_air_liter'].replace('1-2 liter', 2)\n",
    "data_obesitas['konsumsi_air_liter'] = data_obesitas['konsumsi_air_liter'].replace('Kurang 1 liter', 1)\n",
    "\n",
    "data_obesitas['pemantauan_kalori'] = data_obesitas['pemantauan_kalori'].replace('Ya', 1)\n",
    "data_obesitas['pemantauan_kalori'] = data_obesitas['pemantauan_kalori'].replace('Tidak', 0)\n",
    "\n",
    "data_obesitas['aktifitas_fisik'] = data_obesitas['aktifitas_fisik'].replace('4-5 hari', 3)\n",
    "data_obesitas['aktifitas_fisik'] = data_obesitas['aktifitas_fisik'].replace('2-4 hari', 2)\n",
    "data_obesitas['aktifitas_fisik'] = data_obesitas['aktifitas_fisik'].replace('1-2 hari', 1)\n",
    "data_obesitas['aktifitas_fisik'] = data_obesitas['aktifitas_fisik'].replace('Tidak pernah', 0)\n",
    "\n",
    "data_obesitas['penggunaan_perangkat_teknologi'] = data_obesitas['penggunaan_perangkat_teknologi'].replace('Lebih 5 jam', 3)\n",
    "data_obesitas['penggunaan_perangkat_teknologi'] = data_obesitas['penggunaan_perangkat_teknologi'].replace('3-5 jam', 2)\n",
    "data_obesitas['penggunaan_perangkat_teknologi'] = data_obesitas['penggunaan_perangkat_teknologi'].replace('0-2 jam', 1)\n",
    "\n",
    "data_obesitas['konsumsi_alkohol'] = data_obesitas['konsumsi_alkohol'].replace('Selalu', 3)\n",
    "data_obesitas['konsumsi_alkohol'] = data_obesitas['konsumsi_alkohol'].replace('Sering', 2)\n",
    "data_obesitas['konsumsi_alkohol'] = data_obesitas['konsumsi_alkohol'].replace('Kadang-kadang', 1)\n",
    "data_obesitas['konsumsi_alkohol'] = data_obesitas['konsumsi_alkohol'].replace('Tidak pernah', 0)\n",
    "\n",
    "data_obesitas['transporasi_biasa_digunakan'] = data_obesitas['transporasi_biasa_digunakan'].replace('Mobil', 0)\n",
    "data_obesitas['transporasi_biasa_digunakan'] = data_obesitas['transporasi_biasa_digunakan'].replace('Sepeda motor', 1)\n",
    "data_obesitas['transporasi_biasa_digunakan'] = data_obesitas['transporasi_biasa_digunakan'].replace('Sepeda', 2)\n",
    "data_obesitas['transporasi_biasa_digunakan'] = data_obesitas['transporasi_biasa_digunakan'].replace('Transportasi umum', 3)\n",
    "data_obesitas['transporasi_biasa_digunakan'] = data_obesitas['transporasi_biasa_digunakan'].replace('Jalan kaki', 4)\n",
    "\n",
    "data_obesitas"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 379,
   "id": "219f15f1",
   "metadata": {},
   "outputs": [],
   "source": [
    "data_obesitas.to_csv('data_obesitas.csv', index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 380,
   "id": "d071e5ce",
   "metadata": {},
   "outputs": [],
   "source": [
    "data_obesitas = pd.read_csv('data_obesitas.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 381,
   "id": "c3a1720e",
   "metadata": {},
   "outputs": [
    {
     "ename": "KeyError",
     "evalue": "'obesity_class'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mKeyError\u001b[0m                                  Traceback (most recent call last)",
      "File \u001b[1;32m~\\anaconda3\\Lib\\site-packages\\pandas\\core\\indexes\\base.py:3802\u001b[0m, in \u001b[0;36mIndex.get_loc\u001b[1;34m(self, key, method, tolerance)\u001b[0m\n\u001b[0;32m   3801\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m-> 3802\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_engine\u001b[38;5;241m.\u001b[39mget_loc(casted_key)\n\u001b[0;32m   3803\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mKeyError\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m err:\n",
      "File \u001b[1;32m~\\anaconda3\\Lib\\site-packages\\pandas\\_libs\\index.pyx:138\u001b[0m, in \u001b[0;36mpandas._libs.index.IndexEngine.get_loc\u001b[1;34m()\u001b[0m\n",
      "File \u001b[1;32m~\\anaconda3\\Lib\\site-packages\\pandas\\_libs\\index.pyx:165\u001b[0m, in \u001b[0;36mpandas._libs.index.IndexEngine.get_loc\u001b[1;34m()\u001b[0m\n",
      "File \u001b[1;32mpandas\\_libs\\hashtable_class_helper.pxi:5745\u001b[0m, in \u001b[0;36mpandas._libs.hashtable.PyObjectHashTable.get_item\u001b[1;34m()\u001b[0m\n",
      "File \u001b[1;32mpandas\\_libs\\hashtable_class_helper.pxi:5753\u001b[0m, in \u001b[0;36mpandas._libs.hashtable.PyObjectHashTable.get_item\u001b[1;34m()\u001b[0m\n",
      "\u001b[1;31mKeyError\u001b[0m: 'obesity_class'",
      "\nThe above exception was the direct cause of the following exception:\n",
      "\u001b[1;31mKeyError\u001b[0m                                  Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[381], line 2\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[38;5;66;03m# cek balance kelas pada data training\u001b[39;00m\n\u001b[1;32m----> 2\u001b[0m distribusi_kelas \u001b[38;5;241m=\u001b[39m data_obesitas[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mobesity_class\u001b[39m\u001b[38;5;124m'\u001b[39m]\u001b[38;5;241m.\u001b[39mvalue_counts()\u001b[38;5;241m.\u001b[39mrename_axis(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mobesity_class\u001b[39m\u001b[38;5;124m'\u001b[39m)\u001b[38;5;241m.\u001b[39mreset_index(name\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mjumlah\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[0;32m      4\u001b[0m distribusi_kelas[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mobesity_class\u001b[39m\u001b[38;5;124m'\u001b[39m] \u001b[38;5;241m=\u001b[39m pd\u001b[38;5;241m.\u001b[39mCategorical(distribusi_kelas[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mobesity_class\u001b[39m\u001b[38;5;124m'\u001b[39m], categories\u001b[38;5;241m=\u001b[39murutan_obesitas, ordered\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m)\n\u001b[0;32m      5\u001b[0m distribusi_kelas \u001b[38;5;241m=\u001b[39m distribusi_kelas\u001b[38;5;241m.\u001b[39msort_values(by\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mobesity_class\u001b[39m\u001b[38;5;124m'\u001b[39m)\n",
      "File \u001b[1;32m~\\anaconda3\\Lib\\site-packages\\pandas\\core\\frame.py:3807\u001b[0m, in \u001b[0;36mDataFrame.__getitem__\u001b[1;34m(self, key)\u001b[0m\n\u001b[0;32m   3805\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mcolumns\u001b[38;5;241m.\u001b[39mnlevels \u001b[38;5;241m>\u001b[39m \u001b[38;5;241m1\u001b[39m:\n\u001b[0;32m   3806\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_getitem_multilevel(key)\n\u001b[1;32m-> 3807\u001b[0m indexer \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mcolumns\u001b[38;5;241m.\u001b[39mget_loc(key)\n\u001b[0;32m   3808\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m is_integer(indexer):\n\u001b[0;32m   3809\u001b[0m     indexer \u001b[38;5;241m=\u001b[39m [indexer]\n",
      "File \u001b[1;32m~\\anaconda3\\Lib\\site-packages\\pandas\\core\\indexes\\base.py:3804\u001b[0m, in \u001b[0;36mIndex.get_loc\u001b[1;34m(self, key, method, tolerance)\u001b[0m\n\u001b[0;32m   3802\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_engine\u001b[38;5;241m.\u001b[39mget_loc(casted_key)\n\u001b[0;32m   3803\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mKeyError\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m err:\n\u001b[1;32m-> 3804\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mKeyError\u001b[39;00m(key) \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01merr\u001b[39;00m\n\u001b[0;32m   3805\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mTypeError\u001b[39;00m:\n\u001b[0;32m   3806\u001b[0m     \u001b[38;5;66;03m# If we have a listlike key, _check_indexing_error will raise\u001b[39;00m\n\u001b[0;32m   3807\u001b[0m     \u001b[38;5;66;03m#  InvalidIndexError. Otherwise we fall through and re-raise\u001b[39;00m\n\u001b[0;32m   3808\u001b[0m     \u001b[38;5;66;03m#  the TypeError.\u001b[39;00m\n\u001b[0;32m   3809\u001b[0m     \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_check_indexing_error(key)\n",
      "\u001b[1;31mKeyError\u001b[0m: 'obesity_class'"
     ]
    }
   ],
   "source": [
    "# cek balance kelas pada data training\n",
    "distribusi_kelas = data_obesitas['obesity_class'].value_counts().rename_axis('obesity_class').reset_index(name='jumlah')\n",
    "\n",
    "distribusi_kelas['obesity_class'] = pd.Categorical(distribusi_kelas['obesity_class'], categories=urutan_obesitas, ordered=True)\n",
    "distribusi_kelas = distribusi_kelas.sort_values(by='obesity_class')\n",
    "distribusi_kelas"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b6b001d7",
   "metadata": {},
   "outputs": [],
   "source": [
    "plt.figure(figsize=(5, 5))\n",
    "colors = sns.color_palette('pastel')\n",
    "\n",
    "plt.pie(distribusi_kelas['jumlah'], labels=distribusi_kelas['obesity_class'], autopct='%1.1f%%', colors=colors)\n",
    "\n",
    "plt.title('Perbandingan Persentase Kelas Obesitas')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f5ed3a9d",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "35cad95e",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b07ba3ac",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ee9da759",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "283d8b86",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "28039798",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1da336ca",
   "metadata": {},
   "outputs": [],
   "source": [
    "Y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "47069d6e",
   "metadata": {},
   "outputs": [],
   "source": [
    "Y.value_counts()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2d9b6a61",
   "metadata": {},
   "source": [
    "### membagi data untuk data training (latih) dan data testing (uji) untuk model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1afe6d6a",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "from sklearn.model_selection import train_test_split\n",
    "X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size = test_size, stratify = Y, random_state = 0)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "51566153",
   "metadata": {},
   "source": [
    "### normalisasi"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "83c2bcf6",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "from sklearn.preprocessing import MinMaxScaler\n",
    "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": "code",
   "execution_count": null,
   "id": "4527c813",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "X_train.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b66ed396",
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "X_test"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0e4a2d88",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "X_test_nomalisasi"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b0f2f012",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "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": null,
   "id": "fd308107",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "Y_train.value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e3004d89",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "Y_test.value_counts()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b04bf0b5",
   "metadata": {},
   "source": [
    "# MODEL"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "49a748fb",
   "metadata": {},
   "source": [
    "### naive bayes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8d1a8f7e",
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "from sklearn.naive_bayes import GaussianNB\n",
    "klasifikasiNV = GaussianNB()\n",
    "start_time_NV = time.time()\n",
    "klasifikasiNV.fit(X_train_nomalisasi, Y_train)\n",
    "training_end_time_NV = time.time()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "061d628c",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "Y_predictNV = klasifikasiNV.predict(X_test_nomalisasi)\n",
    "Y_predictNV"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "43b9fc83",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "end_time_NV = time.time()\n",
    "prediction_end_time_NV = time.time()\n",
    "\n",
    "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": null,
   "id": "fc4babc5",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "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": null,
   "id": "6e32ae9e",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "from sklearn.metrics import accuracy_score\n",
    "akurasiNV = accuracy_score(Y_test, Y_predictNV)\n",
    "akurasiNV"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2cdf7d13",
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "from sklearn.metrics import classification_report\n",
    "evaluasiNV = classification_report(Y_test, Y_predictNV)\n",
    "print(evaluasiNV)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f8053804",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "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 = ['Insufficient_Weight', 'Normal_Weight', 'Overweight_Level_I', 'Overweight_Level_II', 'Obesity_Type_I',  'Obesity_Type_II', 'Obesity_Type_III']\n",
    "# urutan_baru = [0, 1, 2, 3, 4, 5, 6]\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": null,
   "id": "10291c03",
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "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=30, ha='right')\n",
    "heatmap.set_title(\"Confusion Matrix Heatmap\")\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d272f6b0",
   "metadata": {},
   "source": [
    "### k-nearest neighbor"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7fe29feb",
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "from sklearn.neighbors import KNeighborsClassifier\n",
    "# n_akurasi = []\n",
    "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,30):\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', akurasi)\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 2089:22')\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": null,
   "id": "050043ad",
   "metadata": {},
   "outputs": [],
   "source": [
    "# from sklearn.neighbors import KNeighborsClassifier\n",
    "# # n_akurasi = []\n",
    "\n",
    "# k_values = []\n",
    "# accuracy_values = []\n",
    "# precision_values = []\n",
    "# recall_values = []\n",
    "# f1_score_values = []\n",
    "# train_values = []\n",
    "# test_values = []\n",
    "\n",
    "# sns.set_style(\"whitegrid\")\n",
    "\n",
    "# for k in range(3,30):\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",
    "#     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",
    "#     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",
    "#     accuracy_values.append(akurasi)\n",
    "#     precision_values.append(presisi)\n",
    "#     recall_values.append(recal)\n",
    "#     f1_score_values.append(F1)\n",
    "#     train_values.append(train)\n",
    "#     test_values.append(test)\n",
    "\n",
    "# #   print('nilai K:',k, ', memiliki akurasi', akurasi)\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='Recall')\n",
    "# plt.plot(k_values, f1_score_values, marker='o', markersize=4, linestyle='-', color='#79C314', label='Skor F1')\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('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": null,
   "id": "aae6508f",
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.neighbors import KNeighborsClassifier\n",
    "# n_akurasi = []\n",
    "\n",
    "k_values = []\n",
    "train_values = []\n",
    "test_values = []\n",
    "\n",
    "sns.set_style(\"whitegrid\")\n",
    "\n",
    "for k in range(3,30):\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",
    "\n",
    "#   print('nilai K:',k, ', memiliki akurasi', akurasi)\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": null,
   "id": "400f1c0a",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "# menentukan nilai k di n_neighbors\n",
    "klasifikasiKNN = KNeighborsClassifier(n_neighbors = 6)\n",
    "start_time_KNN = time.time()\n",
    "klasifikasiKNN.fit(X_train_nomalisasi, Y_train)\n",
    "training_end_time_KNN = time.time()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a5912e94",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "Y_predictKNN = klasifikasiKNN.predict(X_test_nomalisasi)\n",
    "Y_predictKNN"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a4b263f8",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "end_time_KNN = time.time()\n",
    "prediction_end_time_KNN = time.time()\n",
    "\n",
    "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": null,
   "id": "3d9ea0ac",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "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": null,
   "id": "014fbfc2",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "from sklearn.metrics import accuracy_score\n",
    "akurasiKNN = accuracy_score(Y_test, Y_predictKNN)\n",
    "akurasiKNN"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8e414b00",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "from sklearn.metrics import classification_report\n",
    "evaluasiKNN = classification_report(Y_test, Y_predictKNN)\n",
    "print(evaluasiKNN)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0f1861ad",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "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": null,
   "id": "0b1e464a",
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "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=30, ha='right')\n",
    "heatmap.set_title(\"Confusion Matrix Heatmap\")\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "32a3e0d5",
   "metadata": {},
   "source": [
    "### Perbandingan hasil klasifikasi dari naive bayes dan k-nearest neighbor"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dc03cb22",
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "dataNV = dataX_testBaru.copy()\n",
    "dataKNN = dataX_testBaru.copy()\n",
    "data_NV_KNN = dataX_testBaru.copy()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "67094727",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "dataNV['klasifikasi_naive_bayes'] = Y_predictNV\n",
    "dataNV"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e8546523",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "dataKNN['klasifikasi_k_nearest_neighbor'] = Y_predictKNN\n",
    "dataKNN"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f6022148",
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "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": "2cef0fcf",
   "metadata": {},
   "source": [
    "### Visualisasi Data Distribusi Kelas Sebenarnya VS Klasifikasi"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "001d0748",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "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['obesity_class'], '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)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4e579ac6",
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "data_ringkasan"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fde0ae66",
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "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=30, ha='right')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "dd407271",
   "metadata": {},
   "source": [
    "### Pembuktian Distribusi Kelas"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d36487bd",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "kelas_obesitashasil = data_NV_KNN['obesity_class'].value_counts().rename_axis('obesity_class').reset_index(name='jumlah')\n",
    "kelas_obesitashasil['obesity_class'] = pd.Categorical(kelas_obesitashasil['obesity_class'], categories=urutan_obesitas, ordered=True)\n",
    "kelas_obesitashasil = kelas_obesitashasil.sort_values(by='obesity_class')\n",
    "kelas_obesitashasil"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "60542816",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "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": null,
   "id": "813fdd43",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "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": "b153fc2b",
   "metadata": {},
   "source": [
    "### download data hasil klasifikasi"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "387c2baf",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "# import openpyxl as xls\n",
    "# data_hasil_klasifikasi = data_hasil_klasifikasi.iloc[:, 1:]\n",
    "# excel_file = pd.ExcelWriter(\"data_hasil_klasifikasi.xlsx\")\n",
    "# data_NV_KNN.to_excel(excel_file)\n",
    "# excel_file.save()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1674c8e4",
   "metadata": {},
   "source": [
    "### download data ringkasan"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9dc6624e",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "# import openpyxl as xls\n",
    "# excel_file = pd.ExcelWriter(\"data_ringkasan.xlsx\")\n",
    "# data_ringkasan.to_excel(excel_file)\n",
    "# excel_file.save()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "52b053d2",
   "metadata": {},
   "source": [
    "## Perbandingan Hasil Klasifikasi"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9dd38980",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "dataperbandingan = pd.read_excel('dataset/perbandingan.xlsx')\n",
    "dataperbandingan"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7e0a6b2b",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "dataperbandingan_sorted = dataperbandingan.sort_index(ascending=False)\n",
    "dataperbandingan_sorted"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f040f11f",
   "metadata": {},
   "outputs": [],
   "source": [
    "sns.set_style(\"whitegrid\")\n",
    "plt.figure(figsize=(12, 5))\n",
    "\n",
    "colors = {'naive_bayes': '#FF9800', 'k_nearest_neighbor': '#F7C566'}\n",
    "\n",
    "sns.lineplot(x='latih_uji', y='akurasi', hue='model', data=dataperbandingan_sorted, markers=True, palette=colors)\n",
    "sns.scatterplot(x='latih_uji', y='akurasi', hue='model', data=dataperbandingan_sorted, 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": null,
   "id": "f43dc012",
   "metadata": {},
   "outputs": [],
   "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_sorted, markers=True, palette=colors)\n",
    "sns.scatterplot(x='latih_uji', y='presisi', hue='model', data=dataperbandingan_sorted, 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": null,
   "id": "74aa8ffc",
   "metadata": {},
   "outputs": [],
   "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_sorted, markers=True, palette=colors)\n",
    "sns.scatterplot(x='latih_uji', y='recal', hue='model', data=dataperbandingan_sorted, 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": null,
   "id": "b962f8e4",
   "metadata": {},
   "outputs": [],
   "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_sorted, markers=True, palette=colors)\n",
    "sns.scatterplot(x='latih_uji', y='F1', hue='model', data=dataperbandingan_sorted, 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": null,
   "id": "ce06755f",
   "metadata": {},
   "outputs": [],
   "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_sorted, markers=True, palette=colors)\n",
    "sns.scatterplot(x='latih_uji', y='w_latih', hue='model', data=dataperbandingan_sorted, 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": null,
   "id": "0ac79bdc",
   "metadata": {},
   "outputs": [],
   "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_sorted, markers=True, palette=colors)\n",
    "sns.scatterplot(x='latih_uji', y='w_uji', hue='model', data=dataperbandingan_sorted, 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": "16ecd0dd",
   "metadata": {},
   "source": [
    "### perbandingan hasil kinerja dalam setiap algoritma"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "440c701c",
   "metadata": {},
   "outputs": [],
   "source": [
    "NV = dataperbandingan_sorted[dataperbandingan_sorted['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": null,
   "id": "388bd25f",
   "metadata": {},
   "outputs": [],
   "source": [
    "KNN = dataperbandingan_sorted[dataperbandingan_sorted['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": "markdown",
   "id": "c37b949d",
   "metadata": {},
   "source": [
    "### perbanding waktu setiap algoritma"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "19d9d2e5",
   "metadata": {},
   "outputs": [],
   "source": [
    "# NV = dataperbandingan_sorted[dataperbandingan_sorted['model'] == 'naive_bayes']\n",
    "\n",
    "# sns.set_style(\"whitegrid\")\n",
    "# plt.figure(figsize=(12, 5))\n",
    "\n",
    "# plt.plot(NV['latih_uji'], NV['w_latih'], 'o-',  markersize=4, color = '#487DE7', label=\"waktu latih\")\n",
    "# plt.plot(NV['latih_uji'], NV['w_uji'], 'o-', markersize=4, color = '#70369D', label=\"waktu uji\")\n",
    "\n",
    "# plt.legend()\n",
    "# plt.grid(alpha=0.4)\n",
    "# plt.title(\"Waktu Palatihan Model Klasifikasi Naive Bayes Berdasarkan Rasio Data Latih dan Data Uji\")\n",
    "# plt.xlabel('Perbandingan Data Latih dan Data Uji')\n",
    "# plt.xticks(rotation=30, ha='right')\n",
    "# plt.ylabel('Waktu')\n",
    "# plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3acc6924",
   "metadata": {},
   "outputs": [],
   "source": [
    "# KNN = dataperbandingan_sorted[dataperbandingan_sorted['model'] == 'k_nearest_neighbor']\n",
    "\n",
    "# sns.set_style(\"whitegrid\")\n",
    "# plt.figure(figsize=(12, 5))\n",
    "\n",
    "# plt.plot(KNN['latih_uji'], KNN['w_latih'], 'o-',  markersize=4, color = '#487DE7', label=\"waktu latih\")\n",
    "# plt.plot(KNN['latih_uji'], KNN['w_uji'], 'o-', markersize=4, color = '#70369D', label=\"waktu uji\")\n",
    "\n",
    "# plt.legend()\n",
    "# plt.grid(alpha=0.4)\n",
    "# plt.title(\"Waktu Palatihan Model Klasifikasi K-Nearest Neighbor Berdasarkan Rasio Data Latih dan Data Uji\")\n",
    "# plt.xlabel('Perbandingan Data Latih dan Data Uji')\n",
    "# plt.xticks(rotation=30, ha='right')\n",
    "# plt.ylabel('Waktu')\n",
    "# plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f23fc57a",
   "metadata": {},
   "source": [
    "## Mengklasifikasikan Data Baru"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3e02e589",
   "metadata": {},
   "outputs": [],
   "source": [
    "Y_predictNV"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7f64b65d",
   "metadata": {},
   "outputs": [],
   "source": [
    "input_data = (0, 25, 1.61, 102.08, 1, 1, 2, 2, 1, 0, 2, 0, 0, 1, 1, 1)\n",
    "\n",
    "input_datas_numpy_array = np.array(input_data)\n",
    "\n",
    "input_data_reshape = input_datas_numpy_array.reshape(1, -1)\n",
    "\n",
    "normalisasi_data_baru = minmax.transform(input_data_reshape)\n",
    "\n",
    "klasifikasi = klasifikasiNV.predict(normalisasi_data_baru)\n",
    "klasifikasi"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3b4cb845",
   "metadata": {},
   "source": [
    "### Mengklasifikasikan Data Baru Sebelum Transformasi Dilakukan"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dd738765",
   "metadata": {},
   "outputs": [],
   "source": [
    "kolom = ['gender', 'age', 'height_meter', 'weight_kilogram', \n",
    "         'family_history_with_overweight', 'consumption_high_calorie', \n",
    "         'consumption_vegetables', 'heavy_meal', 'eat_food_in_between_meals', \n",
    "         'smoke', 'consumption_water_liter', 'food_calorie_monitoring', \n",
    "         'physical_activity', 'duration_technological_devices', \n",
    "         'consumption_alcohol', 'commonly_used_transportation',\n",
    "         'klasifikasi_naive_bayes', 'klasifikasi_k_nearest_neighbor']\n",
    "\n",
    "dataset_percobaan = pd.DataFrame(columns=kolom)\n",
    "dataset_percobaan"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "95d69fc1",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "\n",
    "def tambah_data(dataset, minmax, klasifikasiNV, klasifikasiKNN, **kwargs):\n",
    "    \"\"\"\n",
    "    Fungsi untuk menambahkan data baru ke dataset.\n",
    "\n",
    "    Args:\n",
    "    - dataset: DataFrame yang akan ditambahi data baru\n",
    "    - minmax: Objek MinMaxScaler yang digunakan untuk normalisasi\n",
    "    - klasifikasiNV: Objek model klasifikasi yang digunakan untuk prediksi\n",
    "    - **kwargs: Keyword arguments berisi nama kolom dan nilai-nilai untuk data baru\n",
    "\n",
    "    Returns:\n",
    "    - DataFrame baru setelah data baru ditambahkan\n",
    "    \"\"\"\n",
    "    # Buat DataFrame baru untuk data baru\n",
    "    new_data = pd.DataFrame(kwargs, index=[0])\n",
    "\n",
    "    # Konversi data kategorikal menjadi numerik (hanya untuk prediksi)\n",
    "    new_data_transform = new_data.copy()\n",
    "    \n",
    "    new_data_transform['gender'] = new_data_transform['gender'].replace({'Male': 1, 'Female': 0})\n",
    "    new_data_transform['family_history_with_overweight'] = new_data_transform['family_history_with_overweight'].replace({'yes': 1, 'no': 0})\n",
    "    new_data_transform['consumption_high_calorie'] = new_data_transform['consumption_high_calorie'].replace({'yes': 1, 'no': 0})\n",
    "    new_data_transform['consumption_vegetables'] = new_data_transform['consumption_vegetables'].replace({'Always': 2, 'Sometimes': 1, 'Never': 0})\n",
    "    new_data_transform['heavy_meal'] = new_data_transform['heavy_meal'].replace({'More than three': 3, 'Three': 2, 'Once to twice': 1})\n",
    "    new_data_transform['eat_food_in_between_meals'] = new_data_transform['eat_food_in_between_meals'].replace({'Always': 3, 'Frequently': 2, 'Sometimes': 1, 'no': 0})\n",
    "    new_data_transform['smoke'] = new_data_transform['smoke'].replace({'yes': 1, 'no': 0})\n",
    "    new_data_transform['consumption_water_liter'] = new_data_transform['consumption_water_liter'].replace({'More than 2 liter': 3, '1 - 2 liter': 2, 'Less than a liter': 1})\n",
    "    new_data_transform['food_calorie_monitoring'] = new_data_transform['food_calorie_monitoring'].replace({'yes': 1, 'no': 0})\n",
    "    new_data_transform['physical_activity'] = new_data_transform['physical_activity'].replace({'4 or 5 day': 3, '2 or 4 day': 2, '1 or 2 day': 1, 'naver': 0})\n",
    "    new_data_transform['duration_technological_devices'] = new_data_transform['duration_technological_devices'].replace({'More than 5 hours': 3, '3 - 5 hours': 2, '0 - 2 hours': 1})\n",
    "    new_data_transform['consumption_alcohol'] = new_data_transform['consumption_alcohol'].replace({'Always': 3, 'Frequently': 2, 'Sometimes': 1, 'no': 0})\n",
    "    new_data_transform['commonly_used_transportation'] = new_data_transform['commonly_used_transportation'].replace({'Walking': 0, 'Public_Transportation': 1, 'Bike': 2, 'Motorbike': 3, 'Automobile': 4})\n",
    "\n",
    "    # Normalisasi data baru\n",
    "    normalized_new_data = minmax.transform(new_data_transform)\n",
    "\n",
    "    # Prediksi klasifikasi untuk obesity_class\n",
    "    klasifikasiNV = klasifikasiNV.predict(normalized_new_data)\n",
    "    klasifikasiKNN = klasifikasiKNN.predict(normalized_new_data)\n",
    "\n",
    "    # Tambahkan kolom obesity_class ke data baru dengan hasil prediksi\n",
    "    new_data['klasifikasi_naive_bayes'] = klasifikasiNV\n",
    "    new_data['klasifikasi_k_nearest_neighbor'] = klasifikasiKNN\n",
    "\n",
    "    # Tambahkan data baru ke dataset\n",
    "    dataset = pd.concat([dataset, new_data], ignore_index=True)\n",
    "\n",
    "    return dataset\n",
    "\n",
    "# Contoh penggunaan\n",
    "dataset_percobaan = tambah_data(dataset_percobaan, minmax, klasifikasiNV, klasifikasiKNN,\n",
    "                                 gender=\"Female\",\n",
    "                                 age=25,\n",
    "                                 height_meter=1.61,  # (dalam bentuk meter)\n",
    "                                 weight_kilogram=102.08, \n",
    "                                 family_history_with_overweight=\"yes\",\n",
    "                                 consumption_high_calorie=\"yes\",\n",
    "                                 consumption_vegetables=\"Always\",\n",
    "                                 heavy_meal=\"Three\",\n",
    "                                 eat_food_in_between_meals=\"Sometimes\",\n",
    "                                 smoke=\"no\",\n",
    "                                 consumption_water_liter=\"1 - 2 liter\",\n",
    "                                 food_calorie_monitoring=\"no\",\n",
    "                                 physical_activity=\"naver\",\n",
    "                                 duration_technological_devices=\"0 - 2 hours\",\n",
    "                                 consumption_alcohol=\"Sometimes\",\n",
    "                                 commonly_used_transportation=\"Public_Transportation\")\n",
    "\n",
    "dataset_percobaan"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6eb64693",
   "metadata": {},
   "outputs": [],
   "source": [
    "dataset_percobaan = tambah_data(dataset_percobaan, minmax, klasifikasiNV, klasifikasiKNN,\n",
    "    gender=\"Female\",\n",
    "    age=21,\n",
    "    height_meter=1.74, # (dalam bentuk meter)\n",
    "    weight_kilogram=50.48,\n",
    "    family_history_with_overweight=\"yes\",\n",
    "    consumption_high_calorie=\"yes\",\n",
    "    consumption_vegetables=\"Always\", \n",
    "    heavy_meal=\"More than three\",\n",
    "    eat_food_in_between_meals=\"Frequently\", \n",
    "    smoke=\"no\",\n",
    "    consumption_water_liter=\"1 - 2 liter\",\n",
    "    food_calorie_monitoring=\"no\",\n",
    "    physical_activity=\"naver\",\n",
    "    duration_technological_devices=\"0 - 2 hours\", \n",
    "    consumption_alcohol=\"no\",\n",
    "    commonly_used_transportation=\"Public_Transportation\")\n",
    "\n",
    "dataset_percobaan"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "636cf960",
   "metadata": {},
   "outputs": [],
   "source": [
    "dataset_percobaan = tambah_data(dataset_percobaan, minmax, klasifikasiNV, klasifikasiKNN,\n",
    "    gender=\"Male\",\n",
    "    age=26,\n",
    "    height_meter=1.69, # (dalam bentuk meter)\n",
    "    weight_kilogram=103.18,\n",
    "    family_history_with_overweight=\"yes\",\n",
    "    consumption_high_calorie=\"yes\",\n",
    "    consumption_vegetables=\"Always\", \n",
    "    heavy_meal=\"Once to twice\",\n",
    "    eat_food_in_between_meals=\"Sometimes\", \n",
    "    smoke=\"no\",\n",
    "    consumption_water_liter=\"1 - 2 liter\",\n",
    "    food_calorie_monitoring=\"no\",\n",
    "    physical_activity=\"naver\",\n",
    "    duration_technological_devices=\"0 - 2 hours\", \n",
    "    consumption_alcohol=\"no\",\n",
    "    commonly_used_transportation=\"Public_Transportation\")\n",
    "\n",
    "dataset_percobaan"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6fd52818",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "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.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
