{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "05655d17",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-04-30T05:48:18.933696Z",
     "start_time": "2023-04-30T05:48:18.922669Z"
    },
    "execution": {
     "iopub.execute_input": "2026-10-25T07:29:42.437649Z",
     "iopub.status.busy": "2026-10-25T07:29:42.437034Z",
     "iopub.status.idle": "2026-10-25T07:29:44.965097Z",
     "shell.execute_reply": "2026-10-25T07:29:44.964086Z"
    }
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import os\n",
    "\n",
    "from sklearn.preprocessing import LabelEncoder\n",
    "from sklearn.tree import DecisionTreeRegressor\n",
    "from sklearn.metrics import mean_squared_error, r2_score"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "8a21b9a0",
   "metadata": {},
   "source": [
    "# 데이터 불러오기"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "dc9e9fa4",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-04-30T05:27:54.761163Z",
     "start_time": "2023-04-30T05:27:54.567258Z"
    },
    "execution": {
     "iopub.execute_input": "2026-10-25T07:29:44.969773Z",
     "iopub.status.busy": "2026-10-25T07:29:44.968989Z",
     "iopub.status.idle": "2026-10-25T07:29:45.129571Z",
     "shell.execute_reply": "2026-10-25T07:29:45.128572Z"
    }
   },
   "outputs": [],
   "source": [
    "# data load\n",
    "# 모델링에 사용할 데이터를 로드해옵니다.\n",
    "train = pd.read_csv('./train.csv')\n",
    "test = pd.read_csv('./test.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "212f860c",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-04-30T05:27:55.575217Z",
     "start_time": "2023-04-30T05:27:55.526908Z"
    },
    "execution": {
     "iopub.execute_input": "2026-10-25T07:29:45.133804Z",
     "iopub.status.busy": "2026-10-25T07:29:45.133384Z",
     "iopub.status.idle": "2026-10-25T07:29:45.169252Z",
     "shell.execute_reply": "2026-10-25T07:29:45.167754Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 58627 entries, 0 to 58626\n",
      "Data columns (total 10 columns):\n",
      " #   Column        Non-Null Count  Dtype  \n",
      "---  ------        --------------  -----  \n",
      " 0   brand         58627 non-null  object \n",
      " 1   model         58627 non-null  object \n",
      " 2   year          58627 non-null  int64  \n",
      " 3   transmission  58627 non-null  object \n",
      " 4   mileage       57849 non-null  float64\n",
      " 5   fuelType      58627 non-null  object \n",
      " 6   tax           53515 non-null  float64\n",
      " 7   mpg           53035 non-null  float64\n",
      " 8   engineSize    58627 non-null  float64\n",
      " 9   price         58627 non-null  int64  \n",
      "dtypes: float64(4), int64(2), object(4)\n",
      "memory usage: 4.5+ MB\n"
     ]
    }
   ],
   "source": [
    "# train data에서 결측치가 보입니다.\n",
    "train.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "b35c8e6a",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-04-30T05:28:52.224843Z",
     "start_time": "2023-04-30T05:28:52.166317Z"
    },
    "execution": {
     "iopub.execute_input": "2026-10-25T07:29:45.172631Z",
     "iopub.status.busy": "2026-10-25T07:29:45.172157Z",
     "iopub.status.idle": "2026-10-25T07:29:45.211382Z",
     "shell.execute_reply": "2026-10-25T07:29:45.210270Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "brand           0\n",
      "model           0\n",
      "year            0\n",
      "transmission    0\n",
      "mileage         0\n",
      "fuelType        0\n",
      "tax             0\n",
      "mpg             0\n",
      "engineSize      0\n",
      "price           0\n",
      "dtype: int64\n"
     ]
    }
   ],
   "source": [
    "# 결측치를 모두 제거합니다.\n",
    "train = train.dropna()\n",
    "print(train.isnull().sum())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "2071b84f",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-04-30T05:40:53.163736Z",
     "start_time": "2023-04-30T05:40:53.144732Z"
    },
    "execution": {
     "iopub.execute_input": "2026-10-25T07:29:45.214909Z",
     "iopub.status.busy": "2026-10-25T07:29:45.214473Z",
     "iopub.status.idle": "2026-10-25T07:29:45.228247Z",
     "shell.execute_reply": "2026-10-25T07:29:45.227187Z"
    }
   },
   "outputs": [],
   "source": [
    "# 독립변수로 설정할 train_x에서는 종속변수를 제거합니다.\n",
    "train_x = train.drop(['price'], axis = 1)\n",
    "# train_y 변수를 종속변수로 사용하기 위해 price 데이터를 지정하였습니다.\n",
    "train_y = train['price']\n",
    "\n",
    "# test_x에서는 분석에 활용하지 않는 id 데이터를 제거합니다.\n",
    "test_x = test.drop('id', axis = 1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "e9e9cbcb",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-25T07:29:45.232158Z",
     "iopub.status.busy": "2026-10-25T07:29:45.231686Z",
     "iopub.status.idle": "2026-10-25T07:29:45.239654Z",
     "shell.execute_reply": "2026-10-25T07:29:45.238402Z"
    }
   },
   "outputs": [],
   "source": [
    "df_brand = pd.read_csv('./brand_model.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "8dd848a1",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-25T07:29:45.243094Z",
     "iopub.status.busy": "2026-10-25T07:29:45.242695Z",
     "iopub.status.idle": "2026-10-25T07:29:45.266985Z",
     "shell.execute_reply": "2026-10-25T07:29:45.265807Z"
    }
   },
   "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>brand</th>\n",
       "      <th>model</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>audi</td>\n",
       "      <td>A1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>audi</td>\n",
       "      <td>A2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>audi</td>\n",
       "      <td>A3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>audi</td>\n",
       "      <td>A4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>audi</td>\n",
       "      <td>A5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>190</th>\n",
       "      <td>vw</td>\n",
       "      <td>Tiguan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>191</th>\n",
       "      <td>vw</td>\n",
       "      <td>Tiguan Allspace</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>192</th>\n",
       "      <td>vw</td>\n",
       "      <td>Touareg</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>193</th>\n",
       "      <td>vw</td>\n",
       "      <td>Touran</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>194</th>\n",
       "      <td>vw</td>\n",
       "      <td>Up</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>195 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    brand             model\n",
       "0    audi                A1\n",
       "1    audi                A2\n",
       "2    audi                A3\n",
       "3    audi                A4\n",
       "4    audi                A5\n",
       "..    ...               ...\n",
       "190    vw            Tiguan\n",
       "191    vw   Tiguan Allspace\n",
       "192    vw           Touareg\n",
       "193    vw            Touran\n",
       "194    vw                Up\n",
       "\n",
       "[195 rows x 2 columns]"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_brand"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "630fced8",
   "metadata": {},
   "source": [
    "# 인코딩"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "2e6c2219",
   "metadata": {},
   "source": [
    "범주형 변수에서 train의 class와 test의 class가 같은지, 다른지 확인\n",
    "\n",
    "--> 같으면 그대로 진행\n",
    "\n",
    "--> 다르면 두 가지 경우가 발생\n"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "56ff1adf",
   "metadata": {},
   "source": [
    "1. 범주형 변수의 class가 정확히 주어진 경우\n",
    "2. 범주형 변수의 class가 정확히 주어지지 않은 경우"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "36f86135",
   "metadata": {},
   "source": [
    "1의 경우에는 정확히 주어진 class를 가지고 인코더에 fit을 진행 후 train, test에 transform을 진행\n",
    "\n",
    "2의 경우에는 train에는 없지만 test의 있는 class를 Unknown(모른다)라고 라벨링 후 인코더에 fit을 진행 후 train, test에 transform을 진행"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "9c124b44",
   "metadata": {},
   "source": [
    "여기서는 train의 class와 test의 class가 다른 변수가 'model' 뿐이고, 또한 'model'의 class가 'brand_model.csv'로 주어져 있기 때문에 1의 경우에만 고려하면 됨."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "d03bfec0",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-25T07:29:45.270357Z",
     "iopub.status.busy": "2026-10-25T07:29:45.269850Z",
     "iopub.status.idle": "2026-10-25T07:29:45.318074Z",
     "shell.execute_reply": "2026-10-25T07:29:45.316973Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "model : {'180', ' Kadjar', ' Escort', '200', ' A2', ' Streetka', '220', '230', ' Veloster', ' Ranger'}\n",
      "brand : 없음\n",
      "transmission : 없음\n",
      "fuelType : 없음\n"
     ]
    }
   ],
   "source": [
    "# 인코딩을 진행할 범주형 변수에서 train의 class와 test의 class가 같은지, 다른지 확인\n",
    "object_features = ['model', 'brand', 'transmission', 'fuelType']\n",
    "\n",
    "for feature in object_features:\n",
    "    # train set에 있는 클래스 확인\n",
    "    train_classes = set(train_x[feature])\n",
    "\n",
    "    # test set에만 있는 클래스 확인\n",
    "    test_classes = set(test_x[feature]) - train_classes\n",
    "    if test_classes:\n",
    "        print(f'{feature} : {test_classes}')\n",
    "    else:\n",
    "        print(f'{feature} : 없음')\n",
    "    "
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "4d54ee9e",
   "metadata": {},
   "source": [
    "## label encoding"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "f4c21794",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-25T07:29:45.322053Z",
     "iopub.status.busy": "2026-10-25T07:29:45.321330Z",
     "iopub.status.idle": "2026-10-25T07:29:45.367093Z",
     "shell.execute_reply": "2026-10-25T07:29:45.365503Z"
    }
   },
   "outputs": [],
   "source": [
    "# 인코딩을 진행할 범주형 변수의 class가 정확히 주어진 경우(brand_model.csv 파일 존재)는 다음과 같이 사용\n",
    "from sklearn.preprocessing import LabelEncoder\n",
    "object_features = ['brand', 'model']\n",
    "\n",
    "for feature in object_features:\n",
    "    le = LabelEncoder()\n",
    "    le = le.fit(df_brand[feature].unique()) # 각 범주형 변수의 주어진 class에 대해 fit\n",
    "    \n",
    "    train_x[feature] = le.transform(train_x[feature]) # train_x에 적용\n",
    "    test_x[feature] = le.transform(test_x[feature]) # test_x에 적용"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "0278abe7",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-25T07:29:45.371125Z",
     "iopub.status.busy": "2026-10-25T07:29:45.370368Z",
     "iopub.status.idle": "2026-10-25T07:29:45.435933Z",
     "shell.execute_reply": "2026-10-25T07:29:45.434853Z"
    }
   },
   "outputs": [],
   "source": [
    "# 범주형 변수의 class가 정확히 주어지지 않을 경우는 다음과 같이 사용\n",
    "object_features = ['transmission', 'fuelType']\n",
    "\n",
    "for feature in object_features:\n",
    "    # train set에 있는 클래스 확인\n",
    "    train_classes = set(train_x[feature])\n",
    "\n",
    "    # test set에만 있는 클래스 확인\n",
    "    test_classes = set(test_x[feature]) - train_classes\n",
    "    \n",
    "    if len(test_classes) != 0: # train에서의 class와 test에서의 class가 다른 경우\n",
    "        test_x.loc[test_x[feature].isin(test_classes), feature] = 'Unknown' # test에만 있는 class를 unknown으로 치환\n",
    "        le = LabelEncoder()\n",
    "        le = le.fit(train_x[feature])\n",
    "        train_x[feature] = le.transform(train_x[feature])\n",
    "        le.classes_ = np.append(le.classes_, 'Unknown') # label encoder의 classes에 Unknown 추가 후 test set을 transform\n",
    "        test_x[feature] = le.transform(test_x[feature])\n",
    "        print(f'{feature} 컬럼은 test set에만 있는 클래스 {test_classes}를 포함하고 있습니다.')\n",
    "        \n",
    "    else: # train에서의 class와 test에서의 class가 같은 경우\n",
    "        le = LabelEncoder()\n",
    "        le = le.fit(train_x[feature])\n",
    "        train_x[feature] = le.transform(train_x[feature])\n",
    "        test_x[feature] = le.transform(test_x[feature])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "a945d911",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-25T07:29:45.440270Z",
     "iopub.status.busy": "2026-10-25T07:29:45.439531Z",
     "iopub.status.idle": "2026-10-25T07:29:45.458501Z",
     "shell.execute_reply": "2026-10-25T07:29:45.457471Z"
    }
   },
   "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>brand</th>\n",
       "      <th>model</th>\n",
       "      <th>year</th>\n",
       "      <th>transmission</th>\n",
       "      <th>mileage</th>\n",
       "      <th>fuelType</th>\n",
       "      <th>tax</th>\n",
       "      <th>mpg</th>\n",
       "      <th>engineSize</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>3</td>\n",
       "      <td>83</td>\n",
       "      <td>2015</td>\n",
       "      <td>0</td>\n",
       "      <td>18078.0</td>\n",
       "      <td>0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>67.3</td>\n",
       "      <td>1.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>4</td>\n",
       "      <td>8</td>\n",
       "      <td>2018</td>\n",
       "      <td>0</td>\n",
       "      <td>4350.0</td>\n",
       "      <td>0</td>\n",
       "      <td>145.0</td>\n",
       "      <td>68.9</td>\n",
       "      <td>2.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>6</td>\n",
       "      <td>170</td>\n",
       "      <td>2011</td>\n",
       "      <td>1</td>\n",
       "      <td>74488.0</td>\n",
       "      <td>4</td>\n",
       "      <td>200.0</td>\n",
       "      <td>41.5</td>\n",
       "      <td>1.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>32</td>\n",
       "      <td>2019</td>\n",
       "      <td>0</td>\n",
       "      <td>608.0</td>\n",
       "      <td>4</td>\n",
       "      <td>145.0</td>\n",
       "      <td>42.2</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>5</td>\n",
       "      <td>59</td>\n",
       "      <td>2019</td>\n",
       "      <td>1</td>\n",
       "      <td>3972.0</td>\n",
       "      <td>4</td>\n",
       "      <td>145.0</td>\n",
       "      <td>52.3</td>\n",
       "      <td>1.0</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",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58622</th>\n",
       "      <td>8</td>\n",
       "      <td>165</td>\n",
       "      <td>2017</td>\n",
       "      <td>1</td>\n",
       "      <td>33610.0</td>\n",
       "      <td>4</td>\n",
       "      <td>20.0</td>\n",
       "      <td>64.2</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58623</th>\n",
       "      <td>6</td>\n",
       "      <td>182</td>\n",
       "      <td>2013</td>\n",
       "      <td>1</td>\n",
       "      <td>57140.0</td>\n",
       "      <td>4</td>\n",
       "      <td>125.0</td>\n",
       "      <td>51.4</td>\n",
       "      <td>1.3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58624</th>\n",
       "      <td>7</td>\n",
       "      <td>52</td>\n",
       "      <td>2017</td>\n",
       "      <td>1</td>\n",
       "      <td>9832.0</td>\n",
       "      <td>4</td>\n",
       "      <td>150.0</td>\n",
       "      <td>55.4</td>\n",
       "      <td>1.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58625</th>\n",
       "      <td>8</td>\n",
       "      <td>115</td>\n",
       "      <td>2017</td>\n",
       "      <td>1</td>\n",
       "      <td>28984.0</td>\n",
       "      <td>0</td>\n",
       "      <td>145.0</td>\n",
       "      <td>83.1</td>\n",
       "      <td>1.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58626</th>\n",
       "      <td>2</td>\n",
       "      <td>55</td>\n",
       "      <td>2016</td>\n",
       "      <td>3</td>\n",
       "      <td>11321.0</td>\n",
       "      <td>4</td>\n",
       "      <td>160.0</td>\n",
       "      <td>44.8</td>\n",
       "      <td>1.5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>47781 rows × 9 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       brand  model  year  transmission  mileage  fuelType    tax   mpg  \\\n",
       "0          3     83  2015             0  18078.0         0   20.0  67.3   \n",
       "1          4      8  2018             0   4350.0         0  145.0  68.9   \n",
       "3          6    170  2011             1  74488.0         4  200.0  41.5   \n",
       "4          4     32  2019             0    608.0         4  145.0  42.2   \n",
       "5          5     59  2019             1   3972.0         4  145.0  52.3   \n",
       "...      ...    ...   ...           ...      ...       ...    ...   ...   \n",
       "58622      8    165  2017             1  33610.0         4   20.0  64.2   \n",
       "58623      6    182  2013             1  57140.0         4  125.0  51.4   \n",
       "58624      7     52  2017             1   9832.0         4  150.0  55.4   \n",
       "58625      8    115  2017             1  28984.0         0  145.0  83.1   \n",
       "58626      2     55  2016             3  11321.0         4  160.0  44.8   \n",
       "\n",
       "       engineSize  \n",
       "0             1.6  \n",
       "1             2.1  \n",
       "3             1.6  \n",
       "4             2.0  \n",
       "5             1.0  \n",
       "...           ...  \n",
       "58622         1.0  \n",
       "58623         1.3  \n",
       "58624         1.4  \n",
       "58625         1.4  \n",
       "58626         1.5  \n",
       "\n",
       "[47781 rows x 9 columns]"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train_x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "c99df722",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-25T07:29:45.462300Z",
     "iopub.status.busy": "2026-10-25T07:29:45.461580Z",
     "iopub.status.idle": "2026-10-25T07:29:45.477055Z",
     "shell.execute_reply": "2026-10-25T07:29:45.475879Z"
    }
   },
   "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>brand</th>\n",
       "      <th>model</th>\n",
       "      <th>year</th>\n",
       "      <th>transmission</th>\n",
       "      <th>mileage</th>\n",
       "      <th>fuelType</th>\n",
       "      <th>tax</th>\n",
       "      <th>mpg</th>\n",
       "      <th>engineSize</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>4</td>\n",
       "      <td>32</td>\n",
       "      <td>2019</td>\n",
       "      <td>3</td>\n",
       "      <td>14271</td>\n",
       "      <td>4</td>\n",
       "      <td>145</td>\n",
       "      <td>46.3</td>\n",
       "      <td>1.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>61</td>\n",
       "      <td>2019</td>\n",
       "      <td>1</td>\n",
       "      <td>13451</td>\n",
       "      <td>4</td>\n",
       "      <td>145</td>\n",
       "      <td>58.9</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>164</td>\n",
       "      <td>2016</td>\n",
       "      <td>1</td>\n",
       "      <td>58264</td>\n",
       "      <td>0</td>\n",
       "      <td>30</td>\n",
       "      <td>61.7</td>\n",
       "      <td>1.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>2015</td>\n",
       "      <td>3</td>\n",
       "      <td>6147</td>\n",
       "      <td>4</td>\n",
       "      <td>145</td>\n",
       "      <td>47.9</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>11</td>\n",
       "      <td>2019</td>\n",
       "      <td>1</td>\n",
       "      <td>7000</td>\n",
       "      <td>0</td>\n",
       "      <td>145</td>\n",
       "      <td>51.4</td>\n",
       "      <td>1.6</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",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>39080</th>\n",
       "      <td>3</td>\n",
       "      <td>164</td>\n",
       "      <td>2016</td>\n",
       "      <td>1</td>\n",
       "      <td>48868</td>\n",
       "      <td>0</td>\n",
       "      <td>30</td>\n",
       "      <td>61.7</td>\n",
       "      <td>1.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>39081</th>\n",
       "      <td>6</td>\n",
       "      <td>33</td>\n",
       "      <td>2019</td>\n",
       "      <td>0</td>\n",
       "      <td>8300</td>\n",
       "      <td>2</td>\n",
       "      <td>135</td>\n",
       "      <td>74.3</td>\n",
       "      <td>1.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>39082</th>\n",
       "      <td>4</td>\n",
       "      <td>54</td>\n",
       "      <td>2019</td>\n",
       "      <td>0</td>\n",
       "      <td>16916</td>\n",
       "      <td>0</td>\n",
       "      <td>145</td>\n",
       "      <td>65.7</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>39083</th>\n",
       "      <td>1</td>\n",
       "      <td>5</td>\n",
       "      <td>2014</td>\n",
       "      <td>0</td>\n",
       "      <td>27782</td>\n",
       "      <td>0</td>\n",
       "      <td>160</td>\n",
       "      <td>50.4</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>39084</th>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>2017</td>\n",
       "      <td>0</td>\n",
       "      <td>29989</td>\n",
       "      <td>0</td>\n",
       "      <td>150</td>\n",
       "      <td>49.6</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>39085 rows × 9 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       brand  model  year  transmission  mileage  fuelType  tax   mpg  \\\n",
       "0          4     32  2019             3    14271         4  145  46.3   \n",
       "1          2     61  2019             1    13451         4  145  58.9   \n",
       "2          3    164  2016             1    58264         0   30  61.7   \n",
       "3          1      2  2015             3     6147         4  145  47.9   \n",
       "4          0     11  2019             1     7000         0  145  51.4   \n",
       "...      ...    ...   ...           ...      ...       ...  ...   ...   \n",
       "39080      3    164  2016             1    48868         0   30  61.7   \n",
       "39081      6     33  2019             0     8300         2  135  74.3   \n",
       "39082      4     54  2019             0    16916         0  145  65.7   \n",
       "39083      1      5  2014             0    27782         0  160  50.4   \n",
       "39084      1      3  2017             0    29989         0  150  49.6   \n",
       "\n",
       "       engineSize  \n",
       "0             1.5  \n",
       "1             1.0  \n",
       "2             1.7  \n",
       "3             2.0  \n",
       "4             1.6  \n",
       "...           ...  \n",
       "39080         1.7  \n",
       "39081         1.8  \n",
       "39082         2.0  \n",
       "39083         3.0  \n",
       "39084         3.0  \n",
       "\n",
       "[39085 rows x 9 columns]"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test_x"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "146028de",
   "metadata": {},
   "source": [
    "## Onehot encoding\n"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "56c5ea7a",
   "metadata": {},
   "source": [
    "범주형 변수에 대해 get_dummies 변수를 쓰게되면 train에 있는 class랑, test에 있는 class가 다를 경우에는 변수 개수가 달라짐\n",
    "\n",
    "따라서 label encoding처럼 OneHotEncoding 객채를 생성 후 fit, transform을 해줘야함\n",
    "\n",
    "만약 train에 있는 class 와 test에 있는 class가 같다면 get_dummies를 사용해도 무방"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "00974e0e",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-25T07:29:45.480652Z",
     "iopub.status.busy": "2026-10-25T07:29:45.479850Z",
     "iopub.status.idle": "2026-10-25T07:29:45.485793Z",
     "shell.execute_reply": "2026-10-25T07:29:45.484801Z"
    }
   },
   "outputs": [],
   "source": [
    "# from sklearn.preprocessing import OneHotEncoder\n",
    "# # train에서의 class와 test에서의 class가 다른 경우 OneHotEncoder 사용\n",
    "# object_features = ['model']\n",
    "\n",
    "# for feature in object_features:\n",
    "#     ohe = OneHotEncoder()\n",
    "#     ohe = ohe.fit(pd.DataFrame(df_brand[feature].unique()))\n",
    "\n",
    "#     # train 데이터 onehot encoding\n",
    "#     temp_train = ohe.transform(pd.DataFrame(train_x[feature]))\n",
    "#     temp_train = temp_train.toarray()\n",
    "#     feature_names = ohe.get_feature_names_out(input_features=[feature])\n",
    "#     temp_train = pd.DataFrame(temp_train, columns=feature_names)\n",
    "#     train_x.reset_index(drop=True, inplace=True)\n",
    "#     train_x = pd.concat([train_x, temp_train], axis=1)\n",
    "#     train_x = train_x.drop(feature, axis=1)\n",
    "\n",
    "\n",
    "#     # test 데이터 onehot encoding\n",
    "#     temp_test = ohe.transform(pd.DataFrame(test_x[feature]))\n",
    "#     temp_test = temp_test.toarray()\n",
    "#     feature_names = ohe.get_feature_names_out(input_features=[feature])\n",
    "#     temp_test = pd.DataFrame(temp_test, columns=feature_names)\n",
    "#     test_x = pd.concat([test_x, temp_test], axis=1)\n",
    "#     test_x = test_x.drop(feature, axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "15a189c4",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-25T07:29:45.488929Z",
     "iopub.status.busy": "2026-10-25T07:29:45.488469Z",
     "iopub.status.idle": "2026-10-25T07:29:45.492940Z",
     "shell.execute_reply": "2026-10-25T07:29:45.492006Z"
    }
   },
   "outputs": [],
   "source": [
    "# # train에서의 class와 test에서의 class가 같은 경우 get_dummies 사용\n",
    "# object_features = ['brand', 'transmission', 'fuelType']\n",
    "\n",
    "# train_x = pd.get_dummies(train_x, columns=object_features)\n",
    "# test_x = pd.get_dummies(test_x, columns=object_features)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "fa7d048b",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-25T07:29:45.496051Z",
     "iopub.status.busy": "2026-10-25T07:29:45.495438Z",
     "iopub.status.idle": "2026-10-25T07:29:45.501381Z",
     "shell.execute_reply": "2026-10-25T07:29:45.500212Z"
    }
   },
   "outputs": [],
   "source": [
    "# train_x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "7ec9ca78",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-25T07:29:45.505008Z",
     "iopub.status.busy": "2026-10-25T07:29:45.504332Z",
     "iopub.status.idle": "2026-10-25T07:29:45.509071Z",
     "shell.execute_reply": "2026-10-25T07:29:45.508102Z"
    }
   },
   "outputs": [],
   "source": [
    "# test_x"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "5aafc6f1",
   "metadata": {},
   "source": [
    "# 모델 구축"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "e2da2230",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-04-30T05:41:30.403224Z",
     "start_time": "2023-04-30T05:41:30.391205Z"
    },
    "execution": {
     "iopub.execute_input": "2026-10-25T07:29:45.512232Z",
     "iopub.status.busy": "2026-10-25T07:29:45.511578Z",
     "iopub.status.idle": "2026-10-25T07:29:45.516882Z",
     "shell.execute_reply": "2026-10-25T07:29:45.515694Z"
    }
   },
   "outputs": [],
   "source": [
    "# 회귀모델 정의\n",
    "model = DecisionTreeRegressor(random_state = 84)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "263b73b2",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-04-30T05:41:31.884125Z",
     "start_time": "2023-04-30T05:41:31.468951Z"
    },
    "execution": {
     "iopub.execute_input": "2026-10-25T07:29:45.520279Z",
     "iopub.status.busy": "2026-10-25T07:29:45.519688Z",
     "iopub.status.idle": "2026-10-25T07:29:45.935204Z",
     "shell.execute_reply": "2026-10-25T07:29:45.934083Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style>#sk-container-id-1 {\n",
       "  /* Definition of color scheme common for light and dark mode */\n",
       "  --sklearn-color-text: #000;\n",
       "  --sklearn-color-text-muted: #666;\n",
       "  --sklearn-color-line: gray;\n",
       "  /* Definition of color scheme for unfitted estimators */\n",
       "  --sklearn-color-unfitted-level-0: #fff5e6;\n",
       "  --sklearn-color-unfitted-level-1: #f6e4d2;\n",
       "  --sklearn-color-unfitted-level-2: #ffe0b3;\n",
       "  --sklearn-color-unfitted-level-3: chocolate;\n",
       "  /* Definition of color scheme for fitted estimators */\n",
       "  --sklearn-color-fitted-level-0: #f0f8ff;\n",
       "  --sklearn-color-fitted-level-1: #d4ebff;\n",
       "  --sklearn-color-fitted-level-2: #b3dbfd;\n",
       "  --sklearn-color-fitted-level-3: cornflowerblue;\n",
       "\n",
       "  /* Specific color for light theme */\n",
       "  --sklearn-color-text-on-default-background: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, black)));\n",
       "  --sklearn-color-background: var(--sg-background-color, var(--theme-background, var(--jp-layout-color0, white)));\n",
       "  --sklearn-color-border-box: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, black)));\n",
       "  --sklearn-color-icon: #696969;\n",
       "\n",
       "  @media (prefers-color-scheme: dark) {\n",
       "    /* Redefinition of color scheme for dark theme */\n",
       "    --sklearn-color-text-on-default-background: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, white)));\n",
       "    --sklearn-color-background: var(--sg-background-color, var(--theme-background, var(--jp-layout-color0, #111)));\n",
       "    --sklearn-color-border-box: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, white)));\n",
       "    --sklearn-color-icon: #878787;\n",
       "  }\n",
       "}\n",
       "\n",
       "#sk-container-id-1 {\n",
       "  color: var(--sklearn-color-text);\n",
       "}\n",
       "\n",
       "#sk-container-id-1 pre {\n",
       "  padding: 0;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 input.sk-hidden--visually {\n",
       "  border: 0;\n",
       "  clip: rect(1px 1px 1px 1px);\n",
       "  clip: rect(1px, 1px, 1px, 1px);\n",
       "  height: 1px;\n",
       "  margin: -1px;\n",
       "  overflow: hidden;\n",
       "  padding: 0;\n",
       "  position: absolute;\n",
       "  width: 1px;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-dashed-wrapped {\n",
       "  border: 1px dashed var(--sklearn-color-line);\n",
       "  margin: 0 0.4em 0.5em 0.4em;\n",
       "  box-sizing: border-box;\n",
       "  padding-bottom: 0.4em;\n",
       "  background-color: var(--sklearn-color-background);\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-container {\n",
       "  /* jupyter's `normalize.less` sets `[hidden] { display: none; }`\n",
       "     but bootstrap.min.css set `[hidden] { display: none !important; }`\n",
       "     so we also need the `!important` here to be able to override the\n",
       "     default hidden behavior on the sphinx rendered scikit-learn.org.\n",
       "     See: https://github.com/scikit-learn/scikit-learn/issues/21755 */\n",
       "  display: inline-block !important;\n",
       "  position: relative;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-text-repr-fallback {\n",
       "  display: none;\n",
       "}\n",
       "\n",
       "div.sk-parallel-item,\n",
       "div.sk-serial,\n",
       "div.sk-item {\n",
       "  /* draw centered vertical line to link estimators */\n",
       "  background-image: linear-gradient(var(--sklearn-color-text-on-default-background), var(--sklearn-color-text-on-default-background));\n",
       "  background-size: 2px 100%;\n",
       "  background-repeat: no-repeat;\n",
       "  background-position: center center;\n",
       "}\n",
       "\n",
       "/* Parallel-specific style estimator block */\n",
       "\n",
       "#sk-container-id-1 div.sk-parallel-item::after {\n",
       "  content: \"\";\n",
       "  width: 100%;\n",
       "  border-bottom: 2px solid var(--sklearn-color-text-on-default-background);\n",
       "  flex-grow: 1;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-parallel {\n",
       "  display: flex;\n",
       "  align-items: stretch;\n",
       "  justify-content: center;\n",
       "  background-color: var(--sklearn-color-background);\n",
       "  position: relative;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-parallel-item {\n",
       "  display: flex;\n",
       "  flex-direction: column;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-parallel-item:first-child::after {\n",
       "  align-self: flex-end;\n",
       "  width: 50%;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-parallel-item:last-child::after {\n",
       "  align-self: flex-start;\n",
       "  width: 50%;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-parallel-item:only-child::after {\n",
       "  width: 0;\n",
       "}\n",
       "\n",
       "/* Serial-specific style estimator block */\n",
       "\n",
       "#sk-container-id-1 div.sk-serial {\n",
       "  display: flex;\n",
       "  flex-direction: column;\n",
       "  align-items: center;\n",
       "  background-color: var(--sklearn-color-background);\n",
       "  padding-right: 1em;\n",
       "  padding-left: 1em;\n",
       "}\n",
       "\n",
       "\n",
       "/* Toggleable style: style used for estimator/Pipeline/ColumnTransformer box that is\n",
       "clickable and can be expanded/collapsed.\n",
       "- Pipeline and ColumnTransformer use this feature and define the default style\n",
       "- Estimators will overwrite some part of the style using the `sk-estimator` class\n",
       "*/\n",
       "\n",
       "/* Pipeline and ColumnTransformer style (default) */\n",
       "\n",
       "#sk-container-id-1 div.sk-toggleable {\n",
       "  /* Default theme specific background. It is overwritten whether we have a\n",
       "  specific estimator or a Pipeline/ColumnTransformer */\n",
       "  background-color: var(--sklearn-color-background);\n",
       "}\n",
       "\n",
       "/* Toggleable label */\n",
       "#sk-container-id-1 label.sk-toggleable__label {\n",
       "  cursor: pointer;\n",
       "  display: flex;\n",
       "  width: 100%;\n",
       "  margin-bottom: 0;\n",
       "  padding: 0.5em;\n",
       "  box-sizing: border-box;\n",
       "  text-align: center;\n",
       "  align-items: start;\n",
       "  justify-content: space-between;\n",
       "  gap: 0.5em;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 label.sk-toggleable__label .caption {\n",
       "  font-size: 0.6rem;\n",
       "  font-weight: lighter;\n",
       "  color: var(--sklearn-color-text-muted);\n",
       "}\n",
       "\n",
       "#sk-container-id-1 label.sk-toggleable__label-arrow:before {\n",
       "  /* Arrow on the left of the label */\n",
       "  content: \"▸\";\n",
       "  float: left;\n",
       "  margin-right: 0.25em;\n",
       "  color: var(--sklearn-color-icon);\n",
       "}\n",
       "\n",
       "#sk-container-id-1 label.sk-toggleable__label-arrow:hover:before {\n",
       "  color: var(--sklearn-color-text);\n",
       "}\n",
       "\n",
       "/* Toggleable content - dropdown */\n",
       "\n",
       "#sk-container-id-1 div.sk-toggleable__content {\n",
       "  display: none;\n",
       "  text-align: left;\n",
       "  /* unfitted */\n",
       "  background-color: var(--sklearn-color-unfitted-level-0);\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-toggleable__content.fitted {\n",
       "  /* fitted */\n",
       "  background-color: var(--sklearn-color-fitted-level-0);\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-toggleable__content pre {\n",
       "  margin: 0.2em;\n",
       "  border-radius: 0.25em;\n",
       "  color: var(--sklearn-color-text);\n",
       "  /* unfitted */\n",
       "  background-color: var(--sklearn-color-unfitted-level-0);\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-toggleable__content.fitted pre {\n",
       "  /* unfitted */\n",
       "  background-color: var(--sklearn-color-fitted-level-0);\n",
       "}\n",
       "\n",
       "#sk-container-id-1 input.sk-toggleable__control:checked~div.sk-toggleable__content {\n",
       "  /* Expand drop-down */\n",
       "  display: block;\n",
       "  width: 100%;\n",
       "  overflow: visible;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {\n",
       "  content: \"▾\";\n",
       "}\n",
       "\n",
       "/* Pipeline/ColumnTransformer-specific style */\n",
       "\n",
       "#sk-container-id-1 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
       "  color: var(--sklearn-color-text);\n",
       "  background-color: var(--sklearn-color-unfitted-level-2);\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-label.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
       "  background-color: var(--sklearn-color-fitted-level-2);\n",
       "}\n",
       "\n",
       "/* Estimator-specific style */\n",
       "\n",
       "/* Colorize estimator box */\n",
       "#sk-container-id-1 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
       "  /* unfitted */\n",
       "  background-color: var(--sklearn-color-unfitted-level-2);\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-estimator.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
       "  /* fitted */\n",
       "  background-color: var(--sklearn-color-fitted-level-2);\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-label label.sk-toggleable__label,\n",
       "#sk-container-id-1 div.sk-label label {\n",
       "  /* The background is the default theme color */\n",
       "  color: var(--sklearn-color-text-on-default-background);\n",
       "}\n",
       "\n",
       "/* On hover, darken the color of the background */\n",
       "#sk-container-id-1 div.sk-label:hover label.sk-toggleable__label {\n",
       "  color: var(--sklearn-color-text);\n",
       "  background-color: var(--sklearn-color-unfitted-level-2);\n",
       "}\n",
       "\n",
       "/* Label box, darken color on hover, fitted */\n",
       "#sk-container-id-1 div.sk-label.fitted:hover label.sk-toggleable__label.fitted {\n",
       "  color: var(--sklearn-color-text);\n",
       "  background-color: var(--sklearn-color-fitted-level-2);\n",
       "}\n",
       "\n",
       "/* Estimator label */\n",
       "\n",
       "#sk-container-id-1 div.sk-label label {\n",
       "  font-family: monospace;\n",
       "  font-weight: bold;\n",
       "  display: inline-block;\n",
       "  line-height: 1.2em;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-label-container {\n",
       "  text-align: center;\n",
       "}\n",
       "\n",
       "/* Estimator-specific */\n",
       "#sk-container-id-1 div.sk-estimator {\n",
       "  font-family: monospace;\n",
       "  border: 1px dotted var(--sklearn-color-border-box);\n",
       "  border-radius: 0.25em;\n",
       "  box-sizing: border-box;\n",
       "  margin-bottom: 0.5em;\n",
       "  /* unfitted */\n",
       "  background-color: var(--sklearn-color-unfitted-level-0);\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-estimator.fitted {\n",
       "  /* fitted */\n",
       "  background-color: var(--sklearn-color-fitted-level-0);\n",
       "}\n",
       "\n",
       "/* on hover */\n",
       "#sk-container-id-1 div.sk-estimator:hover {\n",
       "  /* unfitted */\n",
       "  background-color: var(--sklearn-color-unfitted-level-2);\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-estimator.fitted:hover {\n",
       "  /* fitted */\n",
       "  background-color: var(--sklearn-color-fitted-level-2);\n",
       "}\n",
       "\n",
       "/* Specification for estimator info (e.g. \"i\" and \"?\") */\n",
       "\n",
       "/* Common style for \"i\" and \"?\" */\n",
       "\n",
       ".sk-estimator-doc-link,\n",
       "a:link.sk-estimator-doc-link,\n",
       "a:visited.sk-estimator-doc-link {\n",
       "  float: right;\n",
       "  font-size: smaller;\n",
       "  line-height: 1em;\n",
       "  font-family: monospace;\n",
       "  background-color: var(--sklearn-color-background);\n",
       "  border-radius: 1em;\n",
       "  height: 1em;\n",
       "  width: 1em;\n",
       "  text-decoration: none !important;\n",
       "  margin-left: 0.5em;\n",
       "  text-align: center;\n",
       "  /* unfitted */\n",
       "  border: var(--sklearn-color-unfitted-level-1) 1pt solid;\n",
       "  color: var(--sklearn-color-unfitted-level-1);\n",
       "}\n",
       "\n",
       ".sk-estimator-doc-link.fitted,\n",
       "a:link.sk-estimator-doc-link.fitted,\n",
       "a:visited.sk-estimator-doc-link.fitted {\n",
       "  /* fitted */\n",
       "  border: var(--sklearn-color-fitted-level-1) 1pt solid;\n",
       "  color: var(--sklearn-color-fitted-level-1);\n",
       "}\n",
       "\n",
       "/* On hover */\n",
       "div.sk-estimator:hover .sk-estimator-doc-link:hover,\n",
       ".sk-estimator-doc-link:hover,\n",
       "div.sk-label-container:hover .sk-estimator-doc-link:hover,\n",
       ".sk-estimator-doc-link:hover {\n",
       "  /* unfitted */\n",
       "  background-color: var(--sklearn-color-unfitted-level-3);\n",
       "  color: var(--sklearn-color-background);\n",
       "  text-decoration: none;\n",
       "}\n",
       "\n",
       "div.sk-estimator.fitted:hover .sk-estimator-doc-link.fitted:hover,\n",
       ".sk-estimator-doc-link.fitted:hover,\n",
       "div.sk-label-container:hover .sk-estimator-doc-link.fitted:hover,\n",
       ".sk-estimator-doc-link.fitted:hover {\n",
       "  /* fitted */\n",
       "  background-color: var(--sklearn-color-fitted-level-3);\n",
       "  color: var(--sklearn-color-background);\n",
       "  text-decoration: none;\n",
       "}\n",
       "\n",
       "/* Span, style for the box shown on hovering the info icon */\n",
       ".sk-estimator-doc-link span {\n",
       "  display: none;\n",
       "  z-index: 9999;\n",
       "  position: relative;\n",
       "  font-weight: normal;\n",
       "  right: .2ex;\n",
       "  padding: .5ex;\n",
       "  margin: .5ex;\n",
       "  width: min-content;\n",
       "  min-width: 20ex;\n",
       "  max-width: 50ex;\n",
       "  color: var(--sklearn-color-text);\n",
       "  box-shadow: 2pt 2pt 4pt #999;\n",
       "  /* unfitted */\n",
       "  background: var(--sklearn-color-unfitted-level-0);\n",
       "  border: .5pt solid var(--sklearn-color-unfitted-level-3);\n",
       "}\n",
       "\n",
       ".sk-estimator-doc-link.fitted span {\n",
       "  /* fitted */\n",
       "  background: var(--sklearn-color-fitted-level-0);\n",
       "  border: var(--sklearn-color-fitted-level-3);\n",
       "}\n",
       "\n",
       ".sk-estimator-doc-link:hover span {\n",
       "  display: block;\n",
       "}\n",
       "\n",
       "/* \"?\"-specific style due to the `<a>` HTML tag */\n",
       "\n",
       "#sk-container-id-1 a.estimator_doc_link {\n",
       "  float: right;\n",
       "  font-size: 1rem;\n",
       "  line-height: 1em;\n",
       "  font-family: monospace;\n",
       "  background-color: var(--sklearn-color-background);\n",
       "  border-radius: 1rem;\n",
       "  height: 1rem;\n",
       "  width: 1rem;\n",
       "  text-decoration: none;\n",
       "  /* unfitted */\n",
       "  color: var(--sklearn-color-unfitted-level-1);\n",
       "  border: var(--sklearn-color-unfitted-level-1) 1pt solid;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 a.estimator_doc_link.fitted {\n",
       "  /* fitted */\n",
       "  border: var(--sklearn-color-fitted-level-1) 1pt solid;\n",
       "  color: var(--sklearn-color-fitted-level-1);\n",
       "}\n",
       "\n",
       "/* On hover */\n",
       "#sk-container-id-1 a.estimator_doc_link:hover {\n",
       "  /* unfitted */\n",
       "  background-color: var(--sklearn-color-unfitted-level-3);\n",
       "  color: var(--sklearn-color-background);\n",
       "  text-decoration: none;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 a.estimator_doc_link.fitted:hover {\n",
       "  /* fitted */\n",
       "  background-color: var(--sklearn-color-fitted-level-3);\n",
       "}\n",
       "\n",
       ".estimator-table summary {\n",
       "    padding: .5rem;\n",
       "    font-family: monospace;\n",
       "    cursor: pointer;\n",
       "}\n",
       "\n",
       ".estimator-table details[open] {\n",
       "    padding-left: 0.1rem;\n",
       "    padding-right: 0.1rem;\n",
       "    padding-bottom: 0.3rem;\n",
       "}\n",
       "\n",
       ".estimator-table .parameters-table {\n",
       "    margin-left: auto !important;\n",
       "    margin-right: auto !important;\n",
       "}\n",
       "\n",
       ".estimator-table .parameters-table tr:nth-child(odd) {\n",
       "    background-color: #fff;\n",
       "}\n",
       "\n",
       ".estimator-table .parameters-table tr:nth-child(even) {\n",
       "    background-color: #f6f6f6;\n",
       "}\n",
       "\n",
       ".estimator-table .parameters-table tr:hover {\n",
       "    background-color: #e0e0e0;\n",
       "}\n",
       "\n",
       ".estimator-table table td {\n",
       "    border: 1px solid rgba(106, 105, 104, 0.232);\n",
       "}\n",
       "\n",
       ".user-set td {\n",
       "    color:rgb(255, 94, 0);\n",
       "    text-align: left;\n",
       "}\n",
       "\n",
       ".user-set td.value pre {\n",
       "    color:rgb(255, 94, 0) !important;\n",
       "    background-color: transparent !important;\n",
       "}\n",
       "\n",
       ".default td {\n",
       "    color: black;\n",
       "    text-align: left;\n",
       "}\n",
       "\n",
       ".user-set td i,\n",
       ".default td i {\n",
       "    color: black;\n",
       "}\n",
       "\n",
       ".copy-paste-icon {\n",
       "    background-image: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA0NDggNTEyIj48IS0tIUZvbnQgQXdlc29tZSBGcmVlIDYuNy4yIGJ5IEBmb250YXdlc29tZSAtIGh0dHBzOi8vZm9udGF3ZXNvbWUuY29tIExpY2Vuc2UgLSBodHRwczovL2ZvbnRhd2Vzb21lLmNvbS9saWNlbnNlL2ZyZWUgQ29weXJpZ2h0IDIwMjUgRm9udGljb25zLCBJbmMuLS0+PHBhdGggZD0iTTIwOCAwTDMzMi4xIDBjMTIuNyAwIDI0LjkgNS4xIDMzLjkgMTQuMWw2Ny45IDY3LjljOSA5IDE0LjEgMjEuMiAxNC4xIDMzLjlMNDQ4IDMzNmMwIDI2LjUtMjEuNSA0OC00OCA0OGwtMTkyIDBjLTI2LjUgMC00OC0yMS41LTQ4LTQ4bDAtMjg4YzAtMjYuNSAyMS41LTQ4IDQ4LTQ4ek00OCAxMjhsODAgMCAwIDY0LTY0IDAgMCAyNTYgMTkyIDAgMC0zMiA2NCAwIDAgNDhjMCAyNi41LTIxLjUgNDgtNDggNDhMNDggNTEyYy0yNi41IDAtNDgtMjEuNS00OC00OEwwIDE3NmMwLTI2LjUgMjEuNS00OCA0OC00OHoiLz48L3N2Zz4=);\n",
       "    background-repeat: no-repeat;\n",
       "    background-size: 14px 14px;\n",
       "    background-position: 0;\n",
       "    display: inline-block;\n",
       "    width: 14px;\n",
       "    height: 14px;\n",
       "    cursor: pointer;\n",
       "}\n",
       "</style><body><div id=\"sk-container-id-1\" class=\"sk-top-container\"><div class=\"sk-text-repr-fallback\"><pre>DecisionTreeRegressor(random_state=84)</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 fitted 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 fitted sk-toggleable__label-arrow\"><div><div>DecisionTreeRegressor</div></div><div><a class=\"sk-estimator-doc-link fitted\" rel=\"noreferrer\" target=\"_blank\" href=\"https://scikit-learn.org/1.7/modules/generated/sklearn.tree.DecisionTreeRegressor.html\">?<span>Documentation for DecisionTreeRegressor</span></a><span class=\"sk-estimator-doc-link fitted\">i<span>Fitted</span></span></div></label><div class=\"sk-toggleable__content fitted\" data-param-prefix=\"\">\n",
       "        <div class=\"estimator-table\">\n",
       "            <details>\n",
       "                <summary>Parameters</summary>\n",
       "                <table class=\"parameters-table\">\n",
       "                  <tbody>\n",
       "                    \n",
       "        <tr class=\"default\">\n",
       "            <td><i class=\"copy-paste-icon\"\n",
       "                 onclick=\"copyToClipboard('criterion',\n",
       "                          this.parentElement.nextElementSibling)\"\n",
       "            ></i></td>\n",
       "            <td class=\"param\">criterion&nbsp;</td>\n",
       "            <td class=\"value\">&#x27;squared_error&#x27;</td>\n",
       "        </tr>\n",
       "    \n",
       "\n",
       "        <tr class=\"default\">\n",
       "            <td><i class=\"copy-paste-icon\"\n",
       "                 onclick=\"copyToClipboard('splitter',\n",
       "                          this.parentElement.nextElementSibling)\"\n",
       "            ></i></td>\n",
       "            <td class=\"param\">splitter&nbsp;</td>\n",
       "            <td class=\"value\">&#x27;best&#x27;</td>\n",
       "        </tr>\n",
       "    \n",
       "\n",
       "        <tr class=\"default\">\n",
       "            <td><i class=\"copy-paste-icon\"\n",
       "                 onclick=\"copyToClipboard('max_depth',\n",
       "                          this.parentElement.nextElementSibling)\"\n",
       "            ></i></td>\n",
       "            <td class=\"param\">max_depth&nbsp;</td>\n",
       "            <td class=\"value\">None</td>\n",
       "        </tr>\n",
       "    \n",
       "\n",
       "        <tr class=\"default\">\n",
       "            <td><i class=\"copy-paste-icon\"\n",
       "                 onclick=\"copyToClipboard('min_samples_split',\n",
       "                          this.parentElement.nextElementSibling)\"\n",
       "            ></i></td>\n",
       "            <td class=\"param\">min_samples_split&nbsp;</td>\n",
       "            <td class=\"value\">2</td>\n",
       "        </tr>\n",
       "    \n",
       "\n",
       "        <tr class=\"default\">\n",
       "            <td><i class=\"copy-paste-icon\"\n",
       "                 onclick=\"copyToClipboard('min_samples_leaf',\n",
       "                          this.parentElement.nextElementSibling)\"\n",
       "            ></i></td>\n",
       "            <td class=\"param\">min_samples_leaf&nbsp;</td>\n",
       "            <td class=\"value\">1</td>\n",
       "        </tr>\n",
       "    \n",
       "\n",
       "        <tr class=\"default\">\n",
       "            <td><i class=\"copy-paste-icon\"\n",
       "                 onclick=\"copyToClipboard('min_weight_fraction_leaf',\n",
       "                          this.parentElement.nextElementSibling)\"\n",
       "            ></i></td>\n",
       "            <td class=\"param\">min_weight_fraction_leaf&nbsp;</td>\n",
       "            <td class=\"value\">0.0</td>\n",
       "        </tr>\n",
       "    \n",
       "\n",
       "        <tr class=\"default\">\n",
       "            <td><i class=\"copy-paste-icon\"\n",
       "                 onclick=\"copyToClipboard('max_features',\n",
       "                          this.parentElement.nextElementSibling)\"\n",
       "            ></i></td>\n",
       "            <td class=\"param\">max_features&nbsp;</td>\n",
       "            <td class=\"value\">None</td>\n",
       "        </tr>\n",
       "    \n",
       "\n",
       "        <tr class=\"user-set\">\n",
       "            <td><i class=\"copy-paste-icon\"\n",
       "                 onclick=\"copyToClipboard('random_state',\n",
       "                          this.parentElement.nextElementSibling)\"\n",
       "            ></i></td>\n",
       "            <td class=\"param\">random_state&nbsp;</td>\n",
       "            <td class=\"value\">84</td>\n",
       "        </tr>\n",
       "    \n",
       "\n",
       "        <tr class=\"default\">\n",
       "            <td><i class=\"copy-paste-icon\"\n",
       "                 onclick=\"copyToClipboard('max_leaf_nodes',\n",
       "                          this.parentElement.nextElementSibling)\"\n",
       "            ></i></td>\n",
       "            <td class=\"param\">max_leaf_nodes&nbsp;</td>\n",
       "            <td class=\"value\">None</td>\n",
       "        </tr>\n",
       "    \n",
       "\n",
       "        <tr class=\"default\">\n",
       "            <td><i class=\"copy-paste-icon\"\n",
       "                 onclick=\"copyToClipboard('min_impurity_decrease',\n",
       "                          this.parentElement.nextElementSibling)\"\n",
       "            ></i></td>\n",
       "            <td class=\"param\">min_impurity_decrease&nbsp;</td>\n",
       "            <td class=\"value\">0.0</td>\n",
       "        </tr>\n",
       "    \n",
       "\n",
       "        <tr class=\"default\">\n",
       "            <td><i class=\"copy-paste-icon\"\n",
       "                 onclick=\"copyToClipboard('ccp_alpha',\n",
       "                          this.parentElement.nextElementSibling)\"\n",
       "            ></i></td>\n",
       "            <td class=\"param\">ccp_alpha&nbsp;</td>\n",
       "            <td class=\"value\">0.0</td>\n",
       "        </tr>\n",
       "    \n",
       "\n",
       "        <tr class=\"default\">\n",
       "            <td><i class=\"copy-paste-icon\"\n",
       "                 onclick=\"copyToClipboard('monotonic_cst',\n",
       "                          this.parentElement.nextElementSibling)\"\n",
       "            ></i></td>\n",
       "            <td class=\"param\">monotonic_cst&nbsp;</td>\n",
       "            <td class=\"value\">None</td>\n",
       "        </tr>\n",
       "    \n",
       "                  </tbody>\n",
       "                </table>\n",
       "            </details>\n",
       "        </div>\n",
       "    </div></div></div></div></div><script>function copyToClipboard(text, element) {\n",
       "    // Get the parameter prefix from the closest toggleable content\n",
       "    const toggleableContent = element.closest('.sk-toggleable__content');\n",
       "    const paramPrefix = toggleableContent ? toggleableContent.dataset.paramPrefix : '';\n",
       "    const fullParamName = paramPrefix ? `${paramPrefix}${text}` : text;\n",
       "\n",
       "    const originalStyle = element.style;\n",
       "    const computedStyle = window.getComputedStyle(element);\n",
       "    const originalWidth = computedStyle.width;\n",
       "    const originalHTML = element.innerHTML.replace('Copied!', '');\n",
       "\n",
       "    navigator.clipboard.writeText(fullParamName)\n",
       "        .then(() => {\n",
       "            element.style.width = originalWidth;\n",
       "            element.style.color = 'green';\n",
       "            element.innerHTML = \"Copied!\";\n",
       "\n",
       "            setTimeout(() => {\n",
       "                element.innerHTML = originalHTML;\n",
       "                element.style = originalStyle;\n",
       "            }, 2000);\n",
       "        })\n",
       "        .catch(err => {\n",
       "            console.error('Failed to copy:', err);\n",
       "            element.style.color = 'red';\n",
       "            element.innerHTML = \"Failed!\";\n",
       "            setTimeout(() => {\n",
       "                element.innerHTML = originalHTML;\n",
       "                element.style = originalStyle;\n",
       "            }, 2000);\n",
       "        });\n",
       "    return false;\n",
       "}\n",
       "\n",
       "document.querySelectorAll('.fa-regular.fa-copy').forEach(function(element) {\n",
       "    const toggleableContent = element.closest('.sk-toggleable__content');\n",
       "    const paramPrefix = toggleableContent ? toggleableContent.dataset.paramPrefix : '';\n",
       "    const paramName = element.parentElement.nextElementSibling.textContent.trim();\n",
       "    const fullParamName = paramPrefix ? `${paramPrefix}${paramName}` : paramName;\n",
       "\n",
       "    element.setAttribute('title', fullParamName);\n",
       "});\n",
       "</script></body>"
      ],
      "text/plain": [
       "DecisionTreeRegressor(random_state=84)"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 모델 학습\n",
    "model.fit(train_x, train_y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "db53b882",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-04-30T05:51:35.133569Z",
     "start_time": "2023-04-30T05:51:35.077558Z"
    },
    "execution": {
     "iopub.execute_input": "2026-10-25T07:29:45.938282Z",
     "iopub.status.busy": "2026-10-25T07:29:45.937911Z",
     "iopub.status.idle": "2026-10-25T07:29:45.976246Z",
     "shell.execute_reply": "2026-10-25T07:29:45.975079Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "RMSE : 162.17621870535754\n",
      "R2 : 0.9997269779539487\n"
     ]
    }
   ],
   "source": [
    "# 모델 성과 평가 --> 이건 학습에 사용한 데이터로 또 평가를 진행해서 성능이 너무 좋게 나옴\n",
    "preds_train = model.predict(train_x)\n",
    "print(\"RMSE :\", np.sqrt(mean_squared_error(train_y, preds_train)))\n",
    "print(\"R2 :\", r2_score(train_y, preds_train))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "2d061e0a",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-04-30T05:44:47.140967Z",
     "start_time": "2023-04-30T05:44:47.090960Z"
    },
    "execution": {
     "iopub.execute_input": "2026-10-25T07:29:45.980121Z",
     "iopub.status.busy": "2026-10-25T07:29:45.979646Z",
     "iopub.status.idle": "2026-10-25T07:29:46.008942Z",
     "shell.execute_reply": "2026-10-25T07:29:46.007732Z"
    }
   },
   "outputs": [],
   "source": [
    "# 추론\n",
    "preds = model.predict(test_x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "c150da00",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-04-30T05:44:48.603186Z",
     "start_time": "2023-04-30T05:44:48.571937Z"
    },
    "execution": {
     "iopub.execute_input": "2026-10-25T07:29:46.012930Z",
     "iopub.status.busy": "2026-10-25T07:29:46.012431Z",
     "iopub.status.idle": "2026-10-25T07:29:46.030996Z",
     "shell.execute_reply": "2026-10-25T07:29:46.030107Z"
    }
   },
   "outputs": [],
   "source": [
    "# 제출\n",
    "submission = pd.read_csv('./sample_submission.csv')\n",
    "submission['price'] = preds"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "3e0265ee",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-25T07:29:46.035212Z",
     "iopub.status.busy": "2026-10-25T07:29:46.034523Z",
     "iopub.status.idle": "2026-10-25T07:29:46.047370Z",
     "shell.execute_reply": "2026-10-25T07:29:46.046457Z"
    }
   },
   "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>id</th>\n",
       "      <th>price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>19799.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>15400.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>12995.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>12330.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>18000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>39080</th>\n",
       "      <td>39080</td>\n",
       "      <td>11950.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>39081</th>\n",
       "      <td>39081</td>\n",
       "      <td>23990.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>39082</th>\n",
       "      <td>39082</td>\n",
       "      <td>24000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>39083</th>\n",
       "      <td>39083</td>\n",
       "      <td>16999.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>39084</th>\n",
       "      <td>39084</td>\n",
       "      <td>24999.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>39085 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "          id    price\n",
       "0          0  19799.0\n",
       "1          1  15400.0\n",
       "2          2  12995.0\n",
       "3          3  12330.0\n",
       "4          4  18000.0\n",
       "...      ...      ...\n",
       "39080  39080  11950.0\n",
       "39081  39081  23990.0\n",
       "39082  39082  24000.0\n",
       "39083  39083  16999.0\n",
       "39084  39084  24999.0\n",
       "\n",
       "[39085 rows x 2 columns]"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "submission"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "08469bb7",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-25T07:29:46.051154Z",
     "iopub.status.busy": "2026-10-25T07:29:46.050507Z",
     "iopub.status.idle": "2026-10-25T07:29:46.121633Z",
     "shell.execute_reply": "2026-10-25T07:29:46.120788Z"
    }
   },
   "outputs": [],
   "source": [
    "submission.to_csv('./submit.csv', index = False)"
   ]
  }
 ],
 "metadata": {
  "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"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
