{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "hJXTuhosawEo"
   },
   "source": [
    "##1. 분석 준비"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Requirement already satisfied: pandas in c:\\users\\pc\\anaconda3\\lib\\site-packages (0.25.1)\n",
      "Requirement already satisfied: numpy>=1.13.3 in c:\\users\\pc\\anaconda3\\lib\\site-packages (from pandas) (1.16.5)\n",
      "Requirement already satisfied: pytz>=2017.2 in c:\\users\\pc\\anaconda3\\lib\\site-packages (from pandas) (2019.2)\n",
      "Requirement already satisfied: python-dateutil>=2.6.1 in c:\\users\\pc\\anaconda3\\lib\\site-packages (from pandas) (2.8.0)\n",
      "Requirement already satisfied: six>=1.5 in c:\\users\\pc\\anaconda3\\lib\\site-packages (from python-dateutil>=2.6.1->pandas) (1.12.0)\n"
     ]
    }
   ],
   "source": [
    "!pip install pandas"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 866
    },
    "executionInfo": {
     "elapsed": 882,
     "status": "ok",
     "timestamp": 1684657824160,
     "user": {
      "displayName": "꾬은주",
      "userId": "05623544279730996499"
     },
     "user_tz": -540
    },
    "id": "B7BRn1VQao1x",
    "outputId": "41865b57-6915-42af-9d1b-5f11b8701a02"
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\pc\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:21: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
      "Try using .loc[row_indexer,col_indexer] = value instead\n",
      "\n",
      "See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
      "C:\\Users\\pc\\Anaconda3\\lib\\site-packages\\pandas\\core\\frame.py:4102: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame\n",
      "\n",
      "See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
      "  errors=errors,\n",
      "C:\\Users\\pc\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:26: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
      "Try using .loc[row_indexer,col_indexer] = value instead\n",
      "\n",
      "See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
      "C:\\Users\\pc\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:29: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
      "Try using .loc[row_indexer,col_indexer] = value instead\n",
      "\n",
      "See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>survived</th>\n",
       "      <th>pclass</th>\n",
       "      <th>sex</th>\n",
       "      <th>age</th>\n",
       "      <th>title</th>\n",
       "      <th>fare</th>\n",
       "      <th>num_family</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>22.0</td>\n",
       "      <td>0</td>\n",
       "      <td>3.625000</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>38.0</td>\n",
       "      <td>0</td>\n",
       "      <td>35.641650</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>26.0</td>\n",
       "      <td>0</td>\n",
       "      <td>7.925000</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>35.0</td>\n",
       "      <td>0</td>\n",
       "      <td>26.550000</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>35.0</td>\n",
       "      <td>0</td>\n",
       "      <td>8.050000</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\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",
       "      <td>150</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>51.0</td>\n",
       "      <td>1</td>\n",
       "      <td>12.525000</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>151</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>22.0</td>\n",
       "      <td>0</td>\n",
       "      <td>33.300000</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>152</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>55.5</td>\n",
       "      <td>0</td>\n",
       "      <td>8.050000</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>153</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>40.5</td>\n",
       "      <td>0</td>\n",
       "      <td>4.833333</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>155</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>51.0</td>\n",
       "      <td>0</td>\n",
       "      <td>30.689600</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>126 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     survived  pclass  sex   age  title       fare  num_family\n",
       "0           0       3    1  22.0      0   3.625000           2\n",
       "1           1       1    0  38.0      0  35.641650           2\n",
       "2           1       3    0  26.0      0   7.925000           1\n",
       "3           1       1    0  35.0      0  26.550000           2\n",
       "4           0       3    1  35.0      0   8.050000           1\n",
       "..        ...     ...  ...   ...    ...        ...         ...\n",
       "150         0       2    1  51.0      1  12.525000           1\n",
       "151         1       1    0  22.0      0  33.300000           2\n",
       "152         0       3    1  55.5      0   8.050000           1\n",
       "153         0       3    1  40.5      0   4.833333           3\n",
       "155         0       1    1  51.0      0  30.689600           2\n",
       "\n",
       "[126 rows x 7 columns]"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "url='https://raw.githubusercontent.com/sehakflower/data/main/titanic.csv'\n",
    "titanic_df= pd.read_csv(url,sep='\\t')\n",
    "\n",
    "# 컬럼명을 소문자로 바꾸기\n",
    "new_columns=['passengerId', 'survived', 'pclass', 'name', 'sex', 'age', 'sibsp', 'parch',\n",
    "'ticket', 'fare', 'cabin', 'embarked']\n",
    "titanic_df.columns=new_columns\n",
    "\n",
    "# 필요한 컬럼만 가져오기\n",
    "titanic_df1=titanic_df[['survived', 'pclass', 'name', 'sex', 'age', 'sibsp', 'parch', 'fare']]\n",
    "\n",
    "# 1. sex열을 gender로 바꾸고 여성은 0, 남성은 1로 바꾸기\n",
    "tmp=[]\n",
    "for each in titanic_df1['sex']:\n",
    "  if each=='female':\n",
    "    tmp.append(0)\n",
    "  else:\n",
    "    tmp.append(1)\n",
    "\n",
    "titanic_df1['gender']=tmp\n",
    "titanic_df1.drop(columns='sex', inplace=True) # sex 열 삭제하기\n",
    "\n",
    "# 2. 호칭을 숫자형으로 바꾸기\n",
    "condition=lambda x: x.split(',')[1].split('.')[0].strip()\n",
    "titanic_df1['title']=titanic_df1['name'].map(condition) # name에서 호칭만 가져오기\n",
    "Special=['Master', 'Don', 'Rev'] # 3개 호칭을 title 열의 Special로 대체\n",
    "for each in Special:\n",
    "  titanic_df1['title']=titanic_df1['title'].replace(each, 'Special')\n",
    "\n",
    "titanic_df1=titanic_df1.drop('name', axis=1) # 사용하지 않는 name 열 삭제하기\n",
    "\n",
    "# 숫자형으로 만드는 함수 만들기\n",
    "def convert_title(x):\n",
    "  if x==\"Special\":\n",
    "    return 1\n",
    "  else:\n",
    "    return 0\n",
    "\n",
    "titanic_df1[\"special_title\"]=titanic_df1[\"title\"].apply(convert_title)\n",
    "# special_title 열 만들어서 special은 1, 나머지는 0으로 바꾸기\n",
    "titanic_df1.drop('title', axis=1, inplace=True) # title 열 삭제하기\n",
    "# 3. sibpar 열 만들어 동반자 수 더한 값 넣기\n",
    "titanic_df1['sibpar']=titanic_df1['sibsp']+titanic_df1['parch']\n",
    "titanic_df1.drop(['sibsp','parch'], axis =1, inplace=True)\n",
    "# 사용하지 않는 sibsp, parch 열 삭제하기\n",
    "# 4. avgfare 열 만들어 1인당 평균 탑승 요금 넣기\n",
    "titanic_df1['avgfare']=titanic_df1['fare']/titanic_df1['sibpar']\n",
    "titanic_df1['n_family']=titanic_df1['sibpar']+1\n",
    "# n_family 열 만들어 동반자에 1을 더하여 0으로 나누어지지 않도록 함\n",
    "titanic_df1['avgfare']=titanic_df1['fare']/titanic_df1['n_family'] # 1인당 평균 탑승 요금\n",
    "titanic_df1=titanic_df1.drop(['fare','sibpar'], axis=1) # 필요 없는 열 삭제하기\n",
    "# 5. 최종 분석 데이터 컬럼명만 추출하기\n",
    "titanic_df1.rename(columns={'gender':'sex', 'special_title':'title', 'avgfare':'fare', 'n_family':'num_family'}, inplace=True) # 컬럼명 변경하기\n",
    "titanic_df1=titanic_df1[['survived', 'pclass', 'sex', 'age', 'title', 'fare', 'num_family']]\n",
    "# 컬럼 순서 다시 정하기\n",
    "titanic_df1=titanic_df1.dropna()\n",
    "# age에는 NaN 값이 있으므로 이를 삭제한 데이터를 분석에 사용\n",
    "titanic_df1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "executionInfo": {
     "elapsed": 7,
     "status": "ok",
     "timestamp": 1684657843479,
     "user": {
      "displayName": "꾬은주",
      "userId": "05623544279730996499"
     },
     "user_tz": -540
    },
    "id": "eMwmApFmbpKE",
    "outputId": "2e9dd082-5f5e-43b2-ea3d-f50aad1afb43"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "numpy.ndarray"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "raw=titanic_df1\n",
    "np_raw=raw.values\n",
    "type(np_raw)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "executionInfo": {
     "elapsed": 8,
     "status": "ok",
     "timestamp": 1684657853311,
     "user": {
      "displayName": "꾬은주",
      "userId": "05623544279730996499"
     },
     "user_tz": -540
    },
    "id": "5n0qTqvSbrY5",
    "outputId": "ee4eabe7-40b6-4d95-f1ec-bd9d252f5c46"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(100, 100, 26, 26)"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train=np_raw[:100]\n",
    "test=np_raw[100:]\n",
    "y_train = [i[0] for i in train]\n",
    "X_train = [j[1:] for j in train]\n",
    "y_test = [i[0] for i in test]\n",
    "X_test = [j[1:] for j in test]\n",
    "len(X_train),len(y_train), len(y_test),len(X_test)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "cpOoi83Wbuae"
   },
   "source": [
    "##2. 의사결정나무"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Requirement already satisfied: scikit-learn in c:\\python311\\lib\\site-packages (1.2.2)\n",
      "Requirement already satisfied: numpy>=1.17.3 in c:\\python311\\lib\\site-packages (from scikit-learn) (1.24.2)\n",
      "Requirement already satisfied: scipy>=1.3.2 in c:\\python311\\lib\\site-packages (from scikit-learn) (1.10.1)\n",
      "Requirement already satisfied: joblib>=1.1.1 in c:\\python311\\lib\\site-packages (from scikit-learn) (1.2.0)\n",
      "Requirement already satisfied: threadpoolctl>=2.0.0 in c:\\python311\\lib\\site-packages (from scikit-learn) (3.1.0)\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\n",
      "[notice] A new release of pip available: 22.3 -> 23.1.2\n",
      "[notice] To update, run: C:\\Python311\\python.exe -m pip install --upgrade pip\n"
     ]
    }
   ],
   "source": [
    "!pip3 install -U scikit-learn"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "executionInfo": {
     "elapsed": 2522,
     "status": "ok",
     "timestamp": 1684657906947,
     "user": {
      "displayName": "꾬은주",
      "userId": "05623544279730996499"
     },
     "user_tz": -540
    },
    "id": "KVfNPnApbySV",
    "outputId": "99942da2-e429-4e8c-a045-d21a210b027e",
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Score:0.84\n",
      "Score:0.8846153846153846\n"
     ]
    }
   ],
   "source": [
    "from sklearn.tree import DecisionTreeClassifier\n",
    "model=DecisionTreeClassifier(criterion='entropy',max_depth=3,min_samples_leaf=5).fit(X_train, y_train)\n",
    "model.fit(X_train, y_train)\n",
    "DecisionTreeClassifier(criterion='entropy', max_depth=3, min_samples_leaf=5)\n",
    "print('Score:{}'.format(model.score(X_train, y_train)))\n",
    "print('Score:{}'.format(model.score(X_test, y_test)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Requirement already satisfied: graphviz in c:\\users\\pc\\anaconda3\\lib\\site-packages (0.20.1)\n"
     ]
    }
   ],
   "source": [
    "!pip install graphviz"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 아래 코드가 실행되지 않는다면?\n",
    "\n",
    "1. 다음 경로에서 파일을 다운받고 설치하면 됩니다.  \n",
    "https://graphviz.org/download/   \n",
    "여기서는 graphviz-8.0.5 (64-bit) EXE installer [sha256] 항목을 설치하였다. \n",
    "\n",
    "2.아나콘다설치후 주피터노트북을 실행한다면 아나콘다 프롬프트쉘에서 conda install python-graphviz 입력하여 실행한다.\n",
    "\n",
    "3. 환경변수에서 path도 함께 설정해주어야 합니다.   \n",
    "(1) 윈도우 검색란에 '환경'이라고 검색하고 Enter를 누르면 시스템 속성 대화상자가 나타난다.  \n",
    "(2) 하단의 [환경변수] 단추를 클릭하고 상단 목록에서 [path]항목을 선택한후 [편집] 단추를 클릭한다.   \n",
    "(3) 환경변수 편집 대화상자가 나타나면 [새로 만들기] 단추를 눌러 다음의 두 개의 경로를 추가한후 확인을 클릭한다.     \n",
    "\n",
    "pc에 대한 사용자 변수창 path변수에 아래를 추가한다.\n",
    "> C:\\Program Files\\Graphviz\\bin    \n",
    "\n",
    "시스템 변수창 path에 아래를 추가한다.\n",
    "> C:\\Program Files\\Graphviz\\bin\\dot.exe    \n",
    "\n",
    "(4) 저장후 주피터 노트북을 재실행한 후 코드를 실행하면 오류 없이 잘 실행되는 것을 확인할수 있다. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 618
    },
    "executionInfo": {
     "elapsed": 1335,
     "status": "ok",
     "timestamp": 1684657919883,
     "user": {
      "displayName": "꾬은주",
      "userId": "05623544279730996499"
     },
     "user_tz": -540
    },
    "id": "G5QdS5-rb7oN",
    "outputId": "6da9f7f6-afc3-4ecf-ed75-ccb9164d5dcb"
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Generated by graphviz version 2.50.0 (0)\n",
       " -->\n",
       "<!-- Title: Tree Pages: 1 -->\n",
       "<svg width=\"981pt\" height=\"433pt\"\n",
       " viewBox=\"0.00 0.00 980.50 433.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       "<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 429)\">\n",
       "<title>Tree</title>\n",
       "<polygon fill=\"white\" stroke=\"transparent\" points=\"-4,4 -4,-429 976.5,-429 976.5,4 -4,4\"/>\n",
       "<!-- 0 -->\n",
       "<g id=\"node1\" class=\"node\">\n",
       "<title>0</title>\n",
       "<path fill=\"#f2c29f\" stroke=\"black\" d=\"M501.5,-425C501.5,-425 414.5,-425 414.5,-425 408.5,-425 402.5,-419 402.5,-413 402.5,-413 402.5,-354 402.5,-354 402.5,-348 408.5,-342 414.5,-342 414.5,-342 501.5,-342 501.5,-342 507.5,-342 513.5,-348 513.5,-354 513.5,-354 513.5,-413 513.5,-413 513.5,-419 507.5,-425 501.5,-425\"/>\n",
       "<text text-anchor=\"middle\" x=\"458\" y=\"-409.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">sex &lt;= 0.5</text>\n",
       "<text text-anchor=\"middle\" x=\"458\" y=\"-394.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">entropy = 0.925</text>\n",
       "<text text-anchor=\"middle\" x=\"458\" y=\"-379.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 100</text>\n",
       "<text text-anchor=\"middle\" x=\"458\" y=\"-364.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value = [66, 34]</text>\n",
       "<text text-anchor=\"middle\" x=\"458\" y=\"-349.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">class = 0</text>\n",
       "</g>\n",
       "<!-- 1 -->\n",
       "<g id=\"node2\" class=\"node\">\n",
       "<title>1</title>\n",
       "<path fill=\"#98ccf2\" stroke=\"black\" d=\"M437,-306C437,-306 351,-306 351,-306 345,-306 339,-300 339,-294 339,-294 339,-235 339,-235 339,-229 345,-223 351,-223 351,-223 437,-223 437,-223 443,-223 449,-229 449,-235 449,-235 449,-294 449,-294 449,-300 443,-306 437,-306\"/>\n",
       "<text text-anchor=\"middle\" x=\"394\" y=\"-290.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">pclass &lt;= 2.5</text>\n",
       "<text text-anchor=\"middle\" x=\"394\" y=\"-275.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">entropy = 0.91</text>\n",
       "<text text-anchor=\"middle\" x=\"394\" y=\"-260.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 40</text>\n",
       "<text text-anchor=\"middle\" x=\"394\" y=\"-245.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value = [13, 27]</text>\n",
       "<text text-anchor=\"middle\" x=\"394\" y=\"-230.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">class = 1</text>\n",
       "</g>\n",
       "<!-- 0&#45;&gt;1 -->\n",
       "<g id=\"edge1\" class=\"edge\">\n",
       "<title>0&#45;&gt;1</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M435.8,-341.91C431.03,-333.2 425.94,-323.9 421.02,-314.89\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"424.03,-313.11 416.17,-306.02 417.89,-316.47 424.03,-313.11\"/>\n",
       "<text text-anchor=\"middle\" x=\"409.14\" y=\"-326.31\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">True</text>\n",
       "</g>\n",
       "<!-- 8 -->\n",
       "<g id=\"node9\" class=\"node\">\n",
       "<title>8</title>\n",
       "<path fill=\"#e89253\" stroke=\"black\" d=\"M623,-306C623,-306 543,-306 543,-306 537,-306 531,-300 531,-294 531,-294 531,-235 531,-235 531,-229 537,-223 543,-223 543,-223 623,-223 623,-223 629,-223 635,-229 635,-235 635,-235 635,-294 635,-294 635,-300 629,-306 623,-306\"/>\n",
       "<text text-anchor=\"middle\" x=\"583\" y=\"-290.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">fare &lt;= 9.25</text>\n",
       "<text text-anchor=\"middle\" x=\"583\" y=\"-275.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">entropy = 0.52</text>\n",
       "<text text-anchor=\"middle\" x=\"583\" y=\"-260.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 60</text>\n",
       "<text text-anchor=\"middle\" x=\"583\" y=\"-245.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value = [53, 7]</text>\n",
       "<text text-anchor=\"middle\" x=\"583\" y=\"-230.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">class = 0</text>\n",
       "</g>\n",
       "<!-- 0&#45;&gt;8 -->\n",
       "<g id=\"edge8\" class=\"edge\">\n",
       "<title>0&#45;&gt;8</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M501.37,-341.91C511.35,-332.56 522.06,-322.54 532.33,-312.93\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"534.8,-315.41 539.71,-306.02 530.02,-310.3 534.8,-315.41\"/>\n",
       "<text text-anchor=\"middle\" x=\"538.88\" y=\"-327.31\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">False</text>\n",
       "</g>\n",
       "<!-- 2 -->\n",
       "<g id=\"node3\" class=\"node\">\n",
       "<title>2</title>\n",
       "<path fill=\"#45a3e7\" stroke=\"black\" d=\"M216.5,-187C216.5,-187 129.5,-187 129.5,-187 123.5,-187 117.5,-181 117.5,-175 117.5,-175 117.5,-116 117.5,-116 117.5,-110 123.5,-104 129.5,-104 129.5,-104 216.5,-104 216.5,-104 222.5,-104 228.5,-110 228.5,-116 228.5,-116 228.5,-175 228.5,-175 228.5,-181 222.5,-187 216.5,-187\"/>\n",
       "<text text-anchor=\"middle\" x=\"173\" y=\"-171.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">fare &lt;= 11.0</text>\n",
       "<text text-anchor=\"middle\" x=\"173\" y=\"-156.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">entropy = 0.323</text>\n",
       "<text text-anchor=\"middle\" x=\"173\" y=\"-141.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 17</text>\n",
       "<text text-anchor=\"middle\" x=\"173\" y=\"-126.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value = [1, 16]</text>\n",
       "<text text-anchor=\"middle\" x=\"173\" y=\"-111.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">class = 1</text>\n",
       "</g>\n",
       "<!-- 1&#45;&gt;2 -->\n",
       "<g id=\"edge2\" class=\"edge\">\n",
       "<title>1&#45;&gt;2</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M338.8,-234.28C308.07,-218.01 269.64,-197.66 237.52,-180.66\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"239.12,-177.54 228.64,-175.96 235.84,-183.73 239.12,-177.54\"/>\n",
       "</g>\n",
       "<!-- 5 -->\n",
       "<g id=\"node6\" class=\"node\">\n",
       "<title>5</title>\n",
       "<path fill=\"#fdf5ef\" stroke=\"black\" d=\"M437.5,-187C437.5,-187 350.5,-187 350.5,-187 344.5,-187 338.5,-181 338.5,-175 338.5,-175 338.5,-116 338.5,-116 338.5,-110 344.5,-104 350.5,-104 350.5,-104 437.5,-104 437.5,-104 443.5,-104 449.5,-110 449.5,-116 449.5,-116 449.5,-175 449.5,-175 449.5,-181 443.5,-187 437.5,-187\"/>\n",
       "<text text-anchor=\"middle\" x=\"394\" y=\"-171.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">age &lt;= 18.5</text>\n",
       "<text text-anchor=\"middle\" x=\"394\" y=\"-156.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">entropy = 0.999</text>\n",
       "<text text-anchor=\"middle\" x=\"394\" y=\"-141.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 23</text>\n",
       "<text text-anchor=\"middle\" x=\"394\" y=\"-126.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value = [12, 11]</text>\n",
       "<text text-anchor=\"middle\" x=\"394\" y=\"-111.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">class = 0</text>\n",
       "</g>\n",
       "<!-- 1&#45;&gt;5 -->\n",
       "<g id=\"edge5\" class=\"edge\">\n",
       "<title>1&#45;&gt;5</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M394,-222.91C394,-214.65 394,-205.86 394,-197.3\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"397.5,-197.02 394,-187.02 390.5,-197.02 397.5,-197.02\"/>\n",
       "</g>\n",
       "<!-- 3 -->\n",
       "<g id=\"node4\" class=\"node\">\n",
       "<title>3</title>\n",
       "<path fill=\"#61b1ea\" stroke=\"black\" d=\"M92,-68C92,-68 12,-68 12,-68 6,-68 0,-62 0,-56 0,-56 0,-12 0,-12 0,-6 6,0 12,0 12,0 92,0 92,0 98,0 104,-6 104,-12 104,-12 104,-56 104,-56 104,-62 98,-68 92,-68\"/>\n",
       "<text text-anchor=\"middle\" x=\"52\" y=\"-52.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">entropy = 0.65</text>\n",
       "<text text-anchor=\"middle\" x=\"52\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 6</text>\n",
       "<text text-anchor=\"middle\" x=\"52\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value = [1, 5]</text>\n",
       "<text text-anchor=\"middle\" x=\"52\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">class = 1</text>\n",
       "</g>\n",
       "<!-- 2&#45;&gt;3 -->\n",
       "<g id=\"edge3\" class=\"edge\">\n",
       "<title>2&#45;&gt;3</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M127.94,-103.73C117.66,-94.42 106.75,-84.54 96.49,-75.26\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"98.56,-72.41 88.8,-68.3 93.86,-77.6 98.56,-72.41\"/>\n",
       "</g>\n",
       "<!-- 4 -->\n",
       "<g id=\"node5\" class=\"node\">\n",
       "<title>4</title>\n",
       "<path fill=\"#399de5\" stroke=\"black\" d=\"M211.5,-68C211.5,-68 134.5,-68 134.5,-68 128.5,-68 122.5,-62 122.5,-56 122.5,-56 122.5,-12 122.5,-12 122.5,-6 128.5,0 134.5,0 134.5,0 211.5,0 211.5,0 217.5,0 223.5,-6 223.5,-12 223.5,-12 223.5,-56 223.5,-56 223.5,-62 217.5,-68 211.5,-68\"/>\n",
       "<text text-anchor=\"middle\" x=\"173\" y=\"-52.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">entropy = 0.0</text>\n",
       "<text text-anchor=\"middle\" x=\"173\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 11</text>\n",
       "<text text-anchor=\"middle\" x=\"173\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value = [0, 11]</text>\n",
       "<text text-anchor=\"middle\" x=\"173\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">class = 1</text>\n",
       "</g>\n",
       "<!-- 2&#45;&gt;4 -->\n",
       "<g id=\"edge4\" class=\"edge\">\n",
       "<title>2&#45;&gt;4</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M173,-103.73C173,-95.52 173,-86.86 173,-78.56\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"176.5,-78.3 173,-68.3 169.5,-78.3 176.5,-78.3\"/>\n",
       "</g>\n",
       "<!-- 6 -->\n",
       "<g id=\"node7\" class=\"node\">\n",
       "<title>6</title>\n",
       "<path fill=\"#f2c09c\" stroke=\"black\" d=\"M340.5,-68C340.5,-68 253.5,-68 253.5,-68 247.5,-68 241.5,-62 241.5,-56 241.5,-56 241.5,-12 241.5,-12 241.5,-6 247.5,0 253.5,0 253.5,0 340.5,0 340.5,0 346.5,0 352.5,-6 352.5,-12 352.5,-12 352.5,-56 352.5,-56 352.5,-62 346.5,-68 340.5,-68\"/>\n",
       "<text text-anchor=\"middle\" x=\"297\" y=\"-52.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">entropy = 0.918</text>\n",
       "<text text-anchor=\"middle\" x=\"297\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 12</text>\n",
       "<text text-anchor=\"middle\" x=\"297\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value = [8, 4]</text>\n",
       "<text text-anchor=\"middle\" x=\"297\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">class = 0</text>\n",
       "</g>\n",
       "<!-- 5&#45;&gt;6 -->\n",
       "<g id=\"edge6\" class=\"edge\">\n",
       "<title>5&#45;&gt;6</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M357.88,-103.73C349.8,-94.61 341.23,-84.93 333.15,-75.81\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"335.75,-73.46 326.5,-68.3 330.51,-78.11 335.75,-73.46\"/>\n",
       "</g>\n",
       "<!-- 7 -->\n",
       "<g id=\"node8\" class=\"node\">\n",
       "<title>7</title>\n",
       "<path fill=\"#aad5f4\" stroke=\"black\" d=\"M469.5,-68C469.5,-68 382.5,-68 382.5,-68 376.5,-68 370.5,-62 370.5,-56 370.5,-56 370.5,-12 370.5,-12 370.5,-6 376.5,0 382.5,0 382.5,0 469.5,0 469.5,0 475.5,0 481.5,-6 481.5,-12 481.5,-12 481.5,-56 481.5,-56 481.5,-62 475.5,-68 469.5,-68\"/>\n",
       "<text text-anchor=\"middle\" x=\"426\" y=\"-52.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">entropy = 0.946</text>\n",
       "<text text-anchor=\"middle\" x=\"426\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 11</text>\n",
       "<text text-anchor=\"middle\" x=\"426\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value = [4, 7]</text>\n",
       "<text text-anchor=\"middle\" x=\"426\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">class = 1</text>\n",
       "</g>\n",
       "<!-- 5&#45;&gt;7 -->\n",
       "<g id=\"edge7\" class=\"edge\">\n",
       "<title>5&#45;&gt;7</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M405.92,-103.73C408.37,-95.34 410.96,-86.47 413.43,-78.01\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"416.82,-78.88 416.27,-68.3 410.1,-76.92 416.82,-78.88\"/>\n",
       "</g>\n",
       "<!-- 9 -->\n",
       "<g id=\"node10\" class=\"node\">\n",
       "<title>9</title>\n",
       "<path fill=\"#e6853f\" stroke=\"black\" d=\"M626.5,-187C626.5,-187 539.5,-187 539.5,-187 533.5,-187 527.5,-181 527.5,-175 527.5,-175 527.5,-116 527.5,-116 527.5,-110 533.5,-104 539.5,-104 539.5,-104 626.5,-104 626.5,-104 632.5,-104 638.5,-110 638.5,-116 638.5,-116 638.5,-175 638.5,-175 638.5,-181 632.5,-187 626.5,-187\"/>\n",
       "<text text-anchor=\"middle\" x=\"583\" y=\"-171.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">title &lt;= 0.5</text>\n",
       "<text text-anchor=\"middle\" x=\"583\" y=\"-156.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">entropy = 0.201</text>\n",
       "<text text-anchor=\"middle\" x=\"583\" y=\"-141.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 32</text>\n",
       "<text text-anchor=\"middle\" x=\"583\" y=\"-126.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value = [31, 1]</text>\n",
       "<text text-anchor=\"middle\" x=\"583\" y=\"-111.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">class = 0</text>\n",
       "</g>\n",
       "<!-- 8&#45;&gt;9 -->\n",
       "<g id=\"edge9\" class=\"edge\">\n",
       "<title>8&#45;&gt;9</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M583,-222.91C583,-214.65 583,-205.86 583,-197.3\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"586.5,-197.02 583,-187.02 579.5,-197.02 586.5,-197.02\"/>\n",
       "</g>\n",
       "<!-- 12 -->\n",
       "<g id=\"node13\" class=\"node\">\n",
       "<title>12</title>\n",
       "<path fill=\"#eca36f\" stroke=\"black\" d=\"M838,-187C838,-187 758,-187 758,-187 752,-187 746,-181 746,-175 746,-175 746,-116 746,-116 746,-110 752,-104 758,-104 758,-104 838,-104 838,-104 844,-104 850,-110 850,-116 850,-116 850,-175 850,-175 850,-181 844,-187 838,-187\"/>\n",
       "<text text-anchor=\"middle\" x=\"798\" y=\"-171.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">age &lt;= 34.5</text>\n",
       "<text text-anchor=\"middle\" x=\"798\" y=\"-156.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">entropy = 0.75</text>\n",
       "<text text-anchor=\"middle\" x=\"798\" y=\"-141.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 28</text>\n",
       "<text text-anchor=\"middle\" x=\"798\" y=\"-126.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value = [22, 6]</text>\n",
       "<text text-anchor=\"middle\" x=\"798\" y=\"-111.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">class = 0</text>\n",
       "</g>\n",
       "<!-- 8&#45;&gt;12 -->\n",
       "<g id=\"edge12\" class=\"edge\">\n",
       "<title>8&#45;&gt;12</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M635.05,-235.18C665.72,-218.49 704.68,-197.28 736.82,-179.79\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"738.58,-182.82 745.69,-174.97 735.23,-176.67 738.58,-182.82\"/>\n",
       "</g>\n",
       "<!-- 10 -->\n",
       "<g id=\"node11\" class=\"node\">\n",
       "<title>10</title>\n",
       "<path fill=\"#e58139\" stroke=\"black\" d=\"M590,-68C590,-68 512,-68 512,-68 506,-68 500,-62 500,-56 500,-56 500,-12 500,-12 500,-6 506,0 512,0 512,0 590,0 590,0 596,0 602,-6 602,-12 602,-12 602,-56 602,-56 602,-62 596,-68 590,-68\"/>\n",
       "<text text-anchor=\"middle\" x=\"551\" y=\"-52.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">entropy = 0.0</text>\n",
       "<text text-anchor=\"middle\" x=\"551\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 26</text>\n",
       "<text text-anchor=\"middle\" x=\"551\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value = [26, 0]</text>\n",
       "<text text-anchor=\"middle\" x=\"551\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">class = 0</text>\n",
       "</g>\n",
       "<!-- 9&#45;&gt;10 -->\n",
       "<g id=\"edge10\" class=\"edge\">\n",
       "<title>9&#45;&gt;10</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M571.08,-103.73C568.63,-95.34 566.04,-86.47 563.57,-78.01\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"566.9,-76.92 560.73,-68.3 560.18,-78.88 566.9,-76.92\"/>\n",
       "</g>\n",
       "<!-- 11 -->\n",
       "<g id=\"node12\" class=\"node\">\n",
       "<title>11</title>\n",
       "<path fill=\"#ea9a61\" stroke=\"black\" d=\"M712,-68C712,-68 632,-68 632,-68 626,-68 620,-62 620,-56 620,-56 620,-12 620,-12 620,-6 626,0 632,0 632,0 712,0 712,0 718,0 724,-6 724,-12 724,-12 724,-56 724,-56 724,-62 718,-68 712,-68\"/>\n",
       "<text text-anchor=\"middle\" x=\"672\" y=\"-52.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">entropy = 0.65</text>\n",
       "<text text-anchor=\"middle\" x=\"672\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 6</text>\n",
       "<text text-anchor=\"middle\" x=\"672\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value = [5, 1]</text>\n",
       "<text text-anchor=\"middle\" x=\"672\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">class = 0</text>\n",
       "</g>\n",
       "<!-- 9&#45;&gt;11 -->\n",
       "<g id=\"edge11\" class=\"edge\">\n",
       "<title>9&#45;&gt;11</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M616.14,-103.73C623.48,-94.7 631.26,-85.12 638.61,-76.08\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"641.34,-78.27 644.93,-68.3 635.91,-73.85 641.34,-78.27\"/>\n",
       "</g>\n",
       "<!-- 13 -->\n",
       "<g id=\"node14\" class=\"node\">\n",
       "<title>13</title>\n",
       "<path fill=\"#f3c6a5\" stroke=\"black\" d=\"M841.5,-68C841.5,-68 754.5,-68 754.5,-68 748.5,-68 742.5,-62 742.5,-56 742.5,-56 742.5,-12 742.5,-12 742.5,-6 748.5,0 754.5,0 754.5,0 841.5,0 841.5,0 847.5,0 853.5,-6 853.5,-12 853.5,-12 853.5,-56 853.5,-56 853.5,-62 847.5,-68 841.5,-68\"/>\n",
       "<text text-anchor=\"middle\" x=\"798\" y=\"-52.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">entropy = 0.937</text>\n",
       "<text text-anchor=\"middle\" x=\"798\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 17</text>\n",
       "<text text-anchor=\"middle\" x=\"798\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value = [11, 6]</text>\n",
       "<text text-anchor=\"middle\" x=\"798\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">class = 0</text>\n",
       "</g>\n",
       "<!-- 12&#45;&gt;13 -->\n",
       "<g id=\"edge13\" class=\"edge\">\n",
       "<title>12&#45;&gt;13</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M798,-103.73C798,-95.52 798,-86.86 798,-78.56\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"801.5,-78.3 798,-68.3 794.5,-78.3 801.5,-78.3\"/>\n",
       "</g>\n",
       "<!-- 14 -->\n",
       "<g id=\"node15\" class=\"node\">\n",
       "<title>14</title>\n",
       "<path fill=\"#e58139\" stroke=\"black\" d=\"M960.5,-68C960.5,-68 883.5,-68 883.5,-68 877.5,-68 871.5,-62 871.5,-56 871.5,-56 871.5,-12 871.5,-12 871.5,-6 877.5,0 883.5,0 883.5,0 960.5,0 960.5,0 966.5,0 972.5,-6 972.5,-12 972.5,-12 972.5,-56 972.5,-56 972.5,-62 966.5,-68 960.5,-68\"/>\n",
       "<text text-anchor=\"middle\" x=\"922\" y=\"-52.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">entropy = 0.0</text>\n",
       "<text text-anchor=\"middle\" x=\"922\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 11</text>\n",
       "<text text-anchor=\"middle\" x=\"922\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value = [11, 0]</text>\n",
       "<text text-anchor=\"middle\" x=\"922\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">class = 0</text>\n",
       "</g>\n",
       "<!-- 12&#45;&gt;14 -->\n",
       "<g id=\"edge14\" class=\"edge\">\n",
       "<title>12&#45;&gt;14</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M844.17,-103.73C854.81,-94.33 866.12,-84.35 876.72,-74.99\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"879.11,-77.54 884.29,-68.3 874.48,-72.3 879.11,-77.54\"/>\n",
       "</g>\n",
       "</g>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<graphviz.sources.Source at 0x2717e60b0c8>"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from sklearn.tree import export_graphviz\n",
    "export_graphviz(\n",
    " model,\n",
    " out_file=\"titanic.dot\",\n",
    " feature_names=['pclass', 'sex', 'age', 'title', 'fare', 'num_family'],\n",
    " class_names=['0','1'],\n",
    " rounded=True,\n",
    " filled=True\n",
    ")\n",
    "import graphviz\n",
    "with open(\"titanic.dot\") as f:\n",
    " dot_graph=f.read()\n",
    "dot=graphviz.Source(dot_graph)\n",
    "dot.format='png'\n",
    "dot.render(filename='titanic_tree', directory='image/decision_trees', cleanup=True)\n",
    "dot"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "executionInfo": {
     "elapsed": 8,
     "status": "ok",
     "timestamp": 1684657933757,
     "user": {
      "displayName": "꾬은주",
      "userId": "05623544279730996499"
     },
     "user_tz": -540
    },
    "id": "3V2K18wsb_Ky",
    "outputId": "4044cdaa-d704-40be-b994-fc778d1c448c"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Test Accuracy is  88.46153846153845\n"
     ]
    }
   ],
   "source": [
    "from sklearn.metrics import accuracy_score\n",
    "y_pred=model.predict(X_test)\n",
    "print(\"Test Accuracy is \", accuracy_score(y_test, y_pred)*100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "executionInfo": {
     "elapsed": 8,
     "status": "ok",
     "timestamp": 1684657942901,
     "user": {
      "displayName": "꾬은주",
      "userId": "05623544279730996499"
     },
     "user_tz": -540
    },
    "id": "eeJ9Cd6wcBL4",
    "outputId": "0f10ed55-6a8b-47cc-c6ae-4728890026ce"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[18,  1],\n",
       "       [ 2,  5]], dtype=int64)"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from sklearn.metrics import confusion_matrix\n",
    "confusion_matrix(y_test, y_pred)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "executionInfo": {
     "elapsed": 3,
     "status": "ok",
     "timestamp": 1684657954007,
     "user": {
      "displayName": "꾬은주",
      "userId": "05623544279730996499"
     },
     "user_tz": -540
    },
    "id": "EVW8xWPicEM3"
   },
   "outputs": [],
   "source": [
    "feature_names=['pclass', 'sex', 'age', 'title', 'fare', 'num_family']\n",
    "Tom=[1,1,33,1,50,4]\n",
    "Jane=[2,0,50,0,8,1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "executionInfo": {
     "elapsed": 347,
     "status": "ok",
     "timestamp": 1684657963059,
     "user": {
      "displayName": "꾬은주",
      "userId": "05623544279730996499"
     },
     "user_tz": -540
    },
    "id": "XS1G6lcAcGFV",
    "outputId": "0d361db1-037b-420a-f3a1-27c6223fb3a7"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.64705882, 0.35294118]])"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model.predict_proba([Tom])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "executionInfo": {
     "elapsed": 8,
     "status": "ok",
     "timestamp": 1684657974866,
     "user": {
      "displayName": "꾬은주",
      "userId": "05623544279730996499"
     },
     "user_tz": -540
    },
    "id": "0sIlr7V0cJH7",
    "outputId": "b7868ca5-8a27-4c9d-86aa-a8241b9c0b33"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.16666667, 0.83333333]])"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model.predict_proba([Jane])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "P90VdrAfcMc4"
   },
   "source": [
    "##3. 로지스틱 회귀분석\n",
    "### 표준화하지 않은 데이터 이용하기"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "executionInfo": {
     "elapsed": 8,
     "status": "ok",
     "timestamp": 1684658008245,
     "user": {
      "displayName": "꾬은주",
      "userId": "05623544279730996499"
     },
     "user_tz": -540
    },
    "id": "SGGbHKpycRD2",
    "outputId": "8bbaee1f-ab79-4f0c-d447-cb9f371c070d"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.78"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from sklearn.linear_model import LogisticRegression\n",
    "log_reg=LogisticRegression(random_state=13, solver='liblinear', C=10.)\n",
    "log_reg.fit(X_train, y_train)\n",
    "LogisticRegression(C=10.0, random_state=13, solver='liblinear')\n",
    "from sklearn.metrics import accuracy_score\n",
    "pred=log_reg.predict(X_train)\n",
    "accuracy_score(y_train, pred)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "executionInfo": {
     "elapsed": 7,
     "status": "ok",
     "timestamp": 1684658018028,
     "user": {
      "displayName": "꾬은주",
      "userId": "05623544279730996499"
     },
     "user_tz": -540
    },
    "id": "ald4a5pScToi",
    "outputId": "a2f978b9-12b2-44ed-cc75-a091be5bd1c7"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.8846153846153846"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pred = log_reg.predict(X_test)\n",
    "accuracy_score(y_test, pred)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "executionInfo": {
     "elapsed": 4,
     "status": "ok",
     "timestamp": 1684658028838,
     "user": {
      "displayName": "꾬은주",
      "userId": "05623544279730996499"
     },
     "user_tz": -540
    },
    "id": "dqkFylC6cWjc",
    "outputId": "cf731f5f-1289-4ad7-87e6-f340c4f72edb"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[18,  1],\n",
       "       [ 2,  5]], dtype=int64)"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from sklearn.metrics import confusion_matrix\n",
    "confusion_matrix(y_test, pred)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "-SCFgEmUcYmG"
   },
   "source": [
    "###표준화한 데이터 이용하기"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Collecting seaborn\n",
      "  Downloading seaborn-0.12.2-py3-none-any.whl (293 kB)\n",
      "     ------------------------------------- 293.3/293.3 KB 17.7 MB/s eta 0:00:00\n",
      "Requirement already satisfied: pandas>=0.25 in c:\\python\\lib\\site-packages (from seaborn) (1.5.2)\n",
      "Requirement already satisfied: numpy!=1.24.0,>=1.17 in c:\\python\\lib\\site-packages (from seaborn) (1.23.5)\n",
      "Requirement already satisfied: matplotlib!=3.6.1,>=3.1 in c:\\python\\lib\\site-packages (from seaborn) (3.6.2)\n",
      "Requirement already satisfied: python-dateutil>=2.7 in c:\\python\\lib\\site-packages (from matplotlib!=3.6.1,>=3.1->seaborn) (2.8.2)\n",
      "Requirement already satisfied: cycler>=0.10 in c:\\python\\lib\\site-packages (from matplotlib!=3.6.1,>=3.1->seaborn) (0.11.0)\n",
      "Requirement already satisfied: pillow>=6.2.0 in c:\\python\\lib\\site-packages (from matplotlib!=3.6.1,>=3.1->seaborn) (9.3.0)\n",
      "Requirement already satisfied: kiwisolver>=1.0.1 in c:\\python\\lib\\site-packages (from matplotlib!=3.6.1,>=3.1->seaborn) (1.4.4)\n",
      "Requirement already satisfied: contourpy>=1.0.1 in c:\\python\\lib\\site-packages (from matplotlib!=3.6.1,>=3.1->seaborn) (1.0.6)\n",
      "Requirement already satisfied: packaging>=20.0 in c:\\python\\lib\\site-packages (from matplotlib!=3.6.1,>=3.1->seaborn) (22.0)\n",
      "Requirement already satisfied: pyparsing>=2.2.1 in c:\\python\\lib\\site-packages (from matplotlib!=3.6.1,>=3.1->seaborn) (3.0.9)\n",
      "Requirement already satisfied: fonttools>=4.22.0 in c:\\python\\lib\\site-packages (from matplotlib!=3.6.1,>=3.1->seaborn) (4.38.0)\n",
      "Requirement already satisfied: pytz>=2020.1 in c:\\python\\lib\\site-packages (from pandas>=0.25->seaborn) (2022.6)\n",
      "Requirement already satisfied: six>=1.5 in c:\\python\\lib\\site-packages (from python-dateutil>=2.7->matplotlib!=3.6.1,>=3.1->seaborn) (1.16.0)\n",
      "Installing collected packages: seaborn\n",
      "Successfully installed seaborn-0.12.2\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "WARNING: You are using pip version 22.0.4; however, version 23.1.2 is available.\n",
      "You should consider upgrading via the 'C:\\python\\python.exe -m pip install --upgrade pip' command.\n"
     ]
    }
   ],
   "source": [
    "!pip install seaborn"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 448
    },
    "executionInfo": {
     "elapsed": 589,
     "status": "ok",
     "timestamp": 1684658046257,
     "user": {
      "displayName": "꾬은주",
      "userId": "05623544279730996499"
     },
     "user_tz": -540
    },
    "id": "YXTjRs21camo",
    "outputId": "061f957e-2b6a-4a95-ab56-9c2eeaca85a8"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<AxesSubplot: >"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 18964 characters]\n",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import seaborn as sns\n",
    "sns.boxplot(data=titanic_df1[['pclass', 'sex', 'age', 'title', 'fare', 'num_family']])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 206
    },
    "executionInfo": {
     "elapsed": 4,
     "status": "ok",
     "timestamp": 1684658059942,
     "user": {
      "displayName": "꾬은주",
      "userId": "05623544279730996499"
     },
     "user_tz": -540
    },
    "id": "_eADF-Ticc_5",
    "outputId": "7fc6eb86-768c-416f-b687-9803f9d386f6"
   },
   "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>survived</th>\n",
       "      <th>pclass</th>\n",
       "      <th>sex</th>\n",
       "      <th>age</th>\n",
       "      <th>title</th>\n",
       "      <th>fare</th>\n",
       "      <th>num_family</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>-0.694516</td>\n",
       "      <td>0.814941</td>\n",
       "      <td>0.771321</td>\n",
       "      <td>-0.421929</td>\n",
       "      <td>-0.29361</td>\n",
       "      <td>-0.707577</td>\n",
       "      <td>-0.096803</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1.439851</td>\n",
       "      <td>-1.659337</td>\n",
       "      <td>-1.296476</td>\n",
       "      <td>0.677291</td>\n",
       "      <td>-0.29361</td>\n",
       "      <td>1.041150</td>\n",
       "      <td>-0.096803</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1.439851</td>\n",
       "      <td>0.814941</td>\n",
       "      <td>-1.296476</td>\n",
       "      <td>-0.147124</td>\n",
       "      <td>-0.29361</td>\n",
       "      <td>-0.472714</td>\n",
       "      <td>-0.677621</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1.439851</td>\n",
       "      <td>-1.659337</td>\n",
       "      <td>-1.296476</td>\n",
       "      <td>0.471187</td>\n",
       "      <td>-0.29361</td>\n",
       "      <td>0.544571</td>\n",
       "      <td>-0.096803</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>-0.694516</td>\n",
       "      <td>0.814941</td>\n",
       "      <td>0.771321</td>\n",
       "      <td>0.471187</td>\n",
       "      <td>-0.29361</td>\n",
       "      <td>-0.465886</td>\n",
       "      <td>-0.677621</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   survived    pclass       sex       age    title      fare  num_family\n",
       "0 -0.694516  0.814941  0.771321 -0.421929 -0.29361 -0.707577   -0.096803\n",
       "1  1.439851 -1.659337 -1.296476  0.677291 -0.29361  1.041150   -0.096803\n",
       "2  1.439851  0.814941 -1.296476 -0.147124 -0.29361 -0.472714   -0.677621\n",
       "3  1.439851 -1.659337 -1.296476  0.471187 -0.29361  0.544571   -0.096803\n",
       "4 -0.694516  0.814941  0.771321  0.471187 -0.29361 -0.465886   -0.677621"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X=titanic_df1\n",
    "from sklearn.preprocessing import MinMaxScaler, StandardScaler\n",
    "MMS=MinMaxScaler()\n",
    "SS=StandardScaler()\n",
    "SS.fit(X)\n",
    "MMS.fit(X)\n",
    "X_ss=SS.transform(X)\n",
    "X_mms=MMS.transform(X)\n",
    "X_ss_pd=pd.DataFrame(X_ss, columns=X.columns)\n",
    "X_mms_pd=pd.DataFrame(X_mms, columns=X.columns)\n",
    "X_ss_pd.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 206
    },
    "executionInfo": {
     "elapsed": 6,
     "status": "ok",
     "timestamp": 1684658068619,
     "user": {
      "displayName": "꾬은주",
      "userId": "05623544279730996499"
     },
     "user_tz": -540
    },
    "id": "aPC2IuL5cgcf",
    "outputId": "251d38ca-8855-4c7e-94f3-e8fcda20b218"
   },
   "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>survived</th>\n",
       "      <th>pclass</th>\n",
       "      <th>sex</th>\n",
       "      <th>age</th>\n",
       "      <th>title</th>\n",
       "      <th>fare</th>\n",
       "      <th>num_family</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.301696</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.020329</td>\n",
       "      <td>0.142857</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.529714</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.281416</td>\n",
       "      <td>0.142857</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.358700</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.055394</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.486960</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.207276</td>\n",
       "      <td>0.142857</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.486960</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.056413</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   survived  pclass  sex       age  title      fare  num_family\n",
       "0       0.0     1.0  1.0  0.301696    0.0  0.020329    0.142857\n",
       "1       1.0     0.0  0.0  0.529714    0.0  0.281416    0.142857\n",
       "2       1.0     1.0  0.0  0.358700    0.0  0.055394    0.000000\n",
       "3       1.0     0.0  0.0  0.486960    0.0  0.207276    0.142857\n",
       "4       0.0     1.0  1.0  0.486960    0.0  0.056413    0.000000"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X_mms_pd.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 448
    },
    "executionInfo": {
     "elapsed": 1096,
     "status": "ok",
     "timestamp": 1684658077596,
     "user": {
      "displayName": "꾬은주",
      "userId": "05623544279730996499"
     },
     "user_tz": -540
    },
    "id": "UYK56Zskcicd",
    "outputId": "6910d2c0-e8ac-4159-bc85-1a393b804970"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<AxesSubplot: >"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 19844 characters]\n",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "sns.boxplot(data=X_mms_pd[['pclass','sex','age','title','fare','num_family']])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 448
    },
    "executionInfo": {
     "elapsed": 917,
     "status": "ok",
     "timestamp": 1684658092453,
     "user": {
      "displayName": "꾬은주",
      "userId": "05623544279730996499"
     },
     "user_tz": -540
    },
    "id": "XG9-FUtjclzN",
    "outputId": "bcc53873-628c-4e00-e7f7-9162b57ab149"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<AxesSubplot: >"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 18168 characters]\n",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "sns.boxplot(data=X_ss_pd[['pclass', 'sex', 'age', 'title', 'fare', 'num_family']])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 206
    },
    "executionInfo": {
     "elapsed": 366,
     "status": "ok",
     "timestamp": 1684658102295,
     "user": {
      "displayName": "꾬은주",
      "userId": "05623544279730996499"
     },
     "user_tz": -540
    },
    "id": "NaKDA4B5coHz",
    "outputId": "b08c6ac4-aad8-45a7-b74b-7d2a4c4b7501"
   },
   "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>pclass</th>\n",
       "      <th>sex</th>\n",
       "      <th>age</th>\n",
       "      <th>title</th>\n",
       "      <th>fare</th>\n",
       "      <th>num_family</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>22.0</td>\n",
       "      <td>0</td>\n",
       "      <td>3.62500</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>38.0</td>\n",
       "      <td>0</td>\n",
       "      <td>35.64165</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>26.0</td>\n",
       "      <td>0</td>\n",
       "      <td>7.92500</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>35.0</td>\n",
       "      <td>0</td>\n",
       "      <td>26.55000</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>35.0</td>\n",
       "      <td>0</td>\n",
       "      <td>8.05000</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   pclass  sex   age  title      fare  num_family\n",
       "0       3    1  22.0      0   3.62500           2\n",
       "1       1    0  38.0      0  35.64165           2\n",
       "2       3    0  26.0      0   7.92500           1\n",
       "3       1    0  35.0      0  26.55000           2\n",
       "4       3    1  35.0      0   8.05000           1"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y=raw['survived']\n",
    "X=raw.drop(['survived'], axis=1)\n",
    "X.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "executionInfo": {
     "elapsed": 404,
     "status": "ok",
     "timestamp": 1684658109196,
     "user": {
      "displayName": "꾬은주",
      "userId": "05623544279730996499"
     },
     "user_tz": -540
    },
    "id": "X_tS6dwscqdj",
    "outputId": "69752b6a-1d66-4efa-bd7b-9d60fc5a9cf8"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    0\n",
       "1    1\n",
       "2    1\n",
       "3    1\n",
       "4    0\n",
       "Name: survived, dtype: int64"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "executionInfo": {
     "elapsed": 2,
     "status": "ok",
     "timestamp": 1684658120475,
     "user": {
      "displayName": "꾬은주",
      "userId": "05623544279730996499"
     },
     "user_tz": -540
    },
    "id": "QkNw7mQvcsyU"
   },
   "outputs": [],
   "source": [
    "from sklearn.model_selection import train_test_split\n",
    "X_train, X_test, y_train, y_test=\\\n",
    "train_test_split(X, y, test_size=0.2, random_state=13)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "executionInfo": {
     "elapsed": 2,
     "status": "ok",
     "timestamp": 1684658128236,
     "user": {
      "displayName": "꾬은주",
      "userId": "05623544279730996499"
     },
     "user_tz": -540
    },
    "id": "CSZ1GgY8cubi",
    "outputId": "82900858-a890-4cfb-aec1-3410e167fb09"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(array([0, 1], dtype=int64), array([66, 34], dtype=int64))"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import numpy as np\n",
    "np.unique(y_train, return_counts=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "executionInfo": {
     "elapsed": 381,
     "status": "ok",
     "timestamp": 1684658137849,
     "user": {
      "displayName": "꾬은주",
      "userId": "05623544279730996499"
     },
     "user_tz": -540
    },
    "id": "cNkmjLObcxOZ"
   },
   "outputs": [],
   "source": [
    "X_out=X_mms_pd\n",
    "X_train, X_test, y_train, y_test=\\\n",
    "train_test_split(X_out, y, test_size=0.2, random_state=13)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 75
    },
    "executionInfo": {
     "elapsed": 350,
     "status": "ok",
     "timestamp": 1684658147823,
     "user": {
      "displayName": "꾬은주",
      "userId": "05623544279730996499"
     },
     "user_tz": -540
    },
    "id": "DB_mA5L0czL0",
    "outputId": "85497454-f752-4b46-eb07-10c2399818d7"
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style>#sk-container-id-1 {color: black;background-color: white;}#sk-container-id-1 pre{padding: 0;}#sk-container-id-1 div.sk-toggleable {background-color: white;}#sk-container-id-1 label.sk-toggleable__label {cursor: pointer;display: block;width: 100%;margin-bottom: 0;padding: 0.3em;box-sizing: border-box;text-align: center;}#sk-container-id-1 label.sk-toggleable__label-arrow:before {content: \"▸\";float: left;margin-right: 0.25em;color: #696969;}#sk-container-id-1 label.sk-toggleable__label-arrow:hover:before {color: black;}#sk-container-id-1 div.sk-estimator:hover label.sk-toggleable__label-arrow:before {color: black;}#sk-container-id-1 div.sk-toggleable__content {max-height: 0;max-width: 0;overflow: hidden;text-align: left;background-color: #f0f8ff;}#sk-container-id-1 div.sk-toggleable__content pre {margin: 0.2em;color: black;border-radius: 0.25em;background-color: #f0f8ff;}#sk-container-id-1 input.sk-toggleable__control:checked~div.sk-toggleable__content {max-height: 200px;max-width: 100%;overflow: auto;}#sk-container-id-1 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {content: \"▾\";}#sk-container-id-1 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-1 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-1 input.sk-hidden--visually {border: 0;clip: rect(1px 1px 1px 1px);clip: rect(1px, 1px, 1px, 1px);height: 1px;margin: -1px;overflow: hidden;padding: 0;position: absolute;width: 1px;}#sk-container-id-1 div.sk-estimator {font-family: monospace;background-color: #f0f8ff;border: 1px dotted black;border-radius: 0.25em;box-sizing: border-box;margin-bottom: 0.5em;}#sk-container-id-1 div.sk-estimator:hover {background-color: #d4ebff;}#sk-container-id-1 div.sk-parallel-item::after {content: \"\";width: 100%;border-bottom: 1px solid gray;flex-grow: 1;}#sk-container-id-1 div.sk-label:hover label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-1 div.sk-serial::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: 0;}#sk-container-id-1 div.sk-serial {display: flex;flex-direction: column;align-items: center;background-color: white;padding-right: 0.2em;padding-left: 0.2em;position: relative;}#sk-container-id-1 div.sk-item {position: relative;z-index: 1;}#sk-container-id-1 div.sk-parallel {display: flex;align-items: stretch;justify-content: center;background-color: white;position: relative;}#sk-container-id-1 div.sk-item::before, #sk-container-id-1 div.sk-parallel-item::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: -1;}#sk-container-id-1 div.sk-parallel-item {display: flex;flex-direction: column;z-index: 1;position: relative;background-color: white;}#sk-container-id-1 div.sk-parallel-item:first-child::after {align-self: flex-end;width: 50%;}#sk-container-id-1 div.sk-parallel-item:last-child::after {align-self: flex-start;width: 50%;}#sk-container-id-1 div.sk-parallel-item:only-child::after {width: 0;}#sk-container-id-1 div.sk-dashed-wrapped {border: 1px dashed gray;margin: 0 0.4em 0.5em 0.4em;box-sizing: border-box;padding-bottom: 0.4em;background-color: white;}#sk-container-id-1 div.sk-label label {font-family: monospace;font-weight: bold;display: inline-block;line-height: 1.2em;}#sk-container-id-1 div.sk-label-container {text-align: center;}#sk-container-id-1 div.sk-container {/* jupyter's `normalize.less` sets `[hidden] { display: none; }` but bootstrap.min.css set `[hidden] { display: none !important; }` so we also need the `!important` here to be able to override the default hidden behavior on the sphinx rendered scikit-learn.org. See: https://github.com/scikit-learn/scikit-learn/issues/21755 */display: inline-block !important;position: relative;}#sk-container-id-1 div.sk-text-repr-fallback {display: none;}</style><div id=\"sk-container-id-1\" class=\"sk-top-container\"><div class=\"sk-text-repr-fallback\"><pre>LogisticRegression(C=10.0, random_state=13, solver=&#x27;liblinear&#x27;)</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br />On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class=\"sk-container\" hidden><div class=\"sk-item\"><div class=\"sk-estimator sk-toggleable\"><input class=\"sk-toggleable__control sk-hidden--visually\" id=\"sk-estimator-id-1\" type=\"checkbox\" checked><label for=\"sk-estimator-id-1\" class=\"sk-toggleable__label sk-toggleable__label-arrow\">LogisticRegression</label><div class=\"sk-toggleable__content\"><pre>LogisticRegression(C=10.0, random_state=13, solver=&#x27;liblinear&#x27;)</pre></div></div></div></div></div>"
      ],
      "text/plain": [
       "LogisticRegression(C=10.0, random_state=13, solver='liblinear')"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "log_reg=LogisticRegression(random_state=13, solver='liblinear', C=10.)\n",
    "log_reg.fit(X_train, y_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "executionInfo": {
     "elapsed": 6,
     "status": "ok",
     "timestamp": 1684658158578,
     "user": {
      "displayName": "꾬은주",
      "userId": "05623544279730996499"
     },
     "user_tz": -540
    },
    "id": "AFUTsF9gc05M",
    "outputId": "f54bbe0c-03db-4f56-c901-397807f44fa2"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.0"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pred=log_reg.predict(X_test)\n",
    "accuracy_score(y_test, pred)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "executionInfo": {
     "elapsed": 4,
     "status": "ok",
     "timestamp": 1684658170607,
     "user": {
      "displayName": "꾬은주",
      "userId": "05623544279730996499"
     },
     "user_tz": -540
    },
    "id": "EWtiRJ8yc42B",
    "outputId": "f54ece93-a626-488e-88a5-2bf89bb82300"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.0"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X_out=X_ss_pd\n",
    "X_train, X_test, y_train, y_test=\\\n",
    "train_test_split(X_out, y, test_size=0.2, random_state=13)\n",
    "log_reg=LogisticRegression(random_state=13, solver='liblinear', C=10.)\n",
    "log_reg.fit(X_train, y_train)\n",
    "pred=log_reg.predict(X_test)\n",
    "accuracy_score(y_test, pred)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "executionInfo": {
     "elapsed": 322,
     "status": "ok",
     "timestamp": 1684658178391,
     "user": {
      "displayName": "꾬은주",
      "userId": "05623544279730996499"
     },
     "user_tz": -540
    },
    "id": "nQHcTVdbc7N-",
    "outputId": "8f2fbd24-af81-4aad-806b-d00120443462"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 4.73666302e+00, -2.53303155e-01, -5.08052874e-01,\n",
       "        -1.93453169e-01,  3.13171381e-02,  2.68954893e-03,\n",
       "        -1.70331998e-01]])"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "log_reg.coef_"
   ]
  }
 ],
 "metadata": {
  "colab": {
   "authorship_tag": "ABX9TyMVw3AG/uUDp0guKbn8m2sI",
   "provenance": []
  },
  "kernelspec": {
   "display_name": "Python 3",
   "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.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
