{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"### Sapceshipe Titanic ML \n - 필요한 라이브러리 불러오기\n - 데이터 불러오기\n - EDA 수행 (결측치, dtype)\n - 데이터 전처리 (결측값 처리/제거, 불필요 컬럼삭제, encoding 등)\n - 데이터 분할 (train - val - test , train과 test의 데이터 분포도 일치여부 확인)\n - 학습모델 선정 및 검증 (과적합여부등)\n - hyper parameter tunning (optuna활용)\n - submission 제출","metadata":{}},{"cell_type":"markdown","source":"### 1. 라이브러리 불러오기","metadata":{}},{"cell_type":"code","source":"# 라이브러리 불러오기 (데이터 분석 및 시각화)\nimport numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport seaborn as sns\n\n# 라이브러리 불러오기 (머신러닝 모델)\nfrom sklearn.ensemble import RandomForestRegressor\nfrom lightgbm.sklearn import LGBMRegressor\n\n# hyper-parameter tuning\nimport optuna","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-07-22T04:30:01.877905Z","iopub.execute_input":"2022-07-22T04:30:01.878323Z","iopub.status.idle":"2022-07-22T04:30:04.168561Z","shell.execute_reply.started":"2022-07-22T04:30:01.878287Z","shell.execute_reply":"2022-07-22T04:30:04.167459Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### 2. 데이터 불러오기","metadata":{}},{"cell_type":"code","source":"#데이터 불러오기\ntrain = pd.read_csv(\"../input/spaceship-titanic/train.csv\")\ntest = pd.read_csv(\"../input/spaceship-titanic/test.csv\")\nsubmission = pd.read_csv(\"../input/spaceship-titanic/sample_submission.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-07-22T04:51:50.397777Z","iopub.execute_input":"2022-07-22T04:51:50.398350Z","iopub.status.idle":"2022-07-22T04:51:50.448059Z","shell.execute_reply.started":"2022-07-22T04:51:50.398316Z","shell.execute_reply":"2022-07-22T04:51:50.447253Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### 3 EDA수행\n- 데이터 사이즈 체크\n- 결측치 여부\n- dtype이 object인 column확","metadata":{}},{"cell_type":"code","source":"# 데이터 사이즈 체크\ntrain.info() #8693 x 14 컬럼\ntest.info() # 4277 x 13 컬\n\nprint(train.shape, test.shape)\n\ntrain.head()\n\ntrain.describe() #수치형데이터의 중앙값은 모두  0","metadata":{"execution":{"iopub.status.busy":"2022-07-22T04:30:09.123022Z","iopub.execute_input":"2022-07-22T04:30:09.123577Z","iopub.status.idle":"2022-07-22T04:30:09.198544Z","shell.execute_reply.started":"2022-07-22T04:30:09.123545Z","shell.execute_reply":"2022-07-22T04:30:09.197402Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()\n#Name과 PassengerID는 제외\n#카테고리 피쳐에 대한 분포도 확인\n#Age는 나이대별로 또는 구간별로 Tranported 분포가 다른지 확인\n#VIP도 분포 확인\n#수치형 비용에 대해서는 상관관계 분석하여 불필요 컬럼 삭제","metadata":{"execution":{"iopub.status.busy":"2022-07-22T04:30:21.713746Z","iopub.execute_input":"2022-07-22T04:30:21.714158Z","iopub.status.idle":"2022-07-22T04:30:21.735166Z","shell.execute_reply.started":"2022-07-22T04:30:21.714123Z","shell.execute_reply":"2022-07-22T04:30:21.734021Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 컬럼별 결측치 개수 확인\ntrain.isnull().sum()\ntest.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-22T04:30:31.371429Z","iopub.execute_input":"2022-07-22T04:30:31.371846Z","iopub.status.idle":"2022-07-22T04:30:31.389041Z","shell.execute_reply.started":"2022-07-22T04:30:31.371811Z","shell.execute_reply":"2022-07-22T04:30:31.388194Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# correlation matrix를 heatmap으로 시각화.\ncorr = train.drop(columns=[\"PassengerId\"]).corr()\nplt.figure(figsize=(8, 8))\nsns.heatmap(corr, annot=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-22T04:30:33.518666Z","iopub.execute_input":"2022-07-22T04:30:33.519578Z","iopub.status.idle":"2022-07-22T04:30:33.994405Z","shell.execute_reply.started":"2022-07-22T04:30:33.519541Z","shell.execute_reply":"2022-07-22T04:30:33.991740Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('Unique HomePlanet:', train.HomePlanet.unique(), '\\nUnique Destination:', train.Destination.unique())","metadata":{"execution":{"iopub.status.busy":"2022-07-22T04:30:53.127823Z","iopub.execute_input":"2022-07-22T04:30:53.128238Z","iopub.status.idle":"2022-07-22T04:30:53.135459Z","shell.execute_reply.started":"2022-07-22T04:30:53.128200Z","shell.execute_reply":"2022-07-22T04:30:53.134319Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('Unique HomePlanet:', test.HomePlanet.unique(), '\\nUnique Destination:', test.Destination.unique())","metadata":{"execution":{"iopub.status.busy":"2022-07-22T04:30:54.159699Z","iopub.execute_input":"2022-07-22T04:30:54.160116Z","iopub.status.idle":"2022-07-22T04:30:54.167778Z","shell.execute_reply.started":"2022-07-22T04:30:54.160078Z","shell.execute_reply":"2022-07-22T04:30:54.166632Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Categorical features\ncat_features=['HomePlanet', 'CryoSleep', 'Destination', 'VIP']\n\n# Plot categorical features\nfig=plt.figure(figsize=(8,13))\nfor i, var_name in enumerate(cat_features):\n    ax=fig.add_subplot(4,1,i+1)\n    sns.countplot(data=train, x=var_name, axes=ax, hue='Transported')\n    ax.set_title(var_name)\nfig.tight_layout()\nplt.show()\n\n# VIP컬럼은 transported비중이 거의 50:50이라 변별력이 없어보임","metadata":{"execution":{"iopub.status.busy":"2022-07-22T04:30:56.942143Z","iopub.execute_input":"2022-07-22T04:30:56.942548Z","iopub.status.idle":"2022-07-22T04:30:57.567743Z","shell.execute_reply.started":"2022-07-22T04:30:56.942516Z","shell.execute_reply":"2022-07-22T04:30:57.566615Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Age분포도 확\nsns.histplot(data=train, x=\"Age\", bins=20, hue=\"Transported\", multiple=\"stack\")\n\n#나이가 어릴수록 Transported될 확율이 높음","metadata":{"execution":{"iopub.status.busy":"2022-07-22T04:52:08.769715Z","iopub.execute_input":"2022-07-22T04:52:08.770111Z","iopub.status.idle":"2022-07-22T04:52:09.084054Z","shell.execute_reply.started":"2022-07-22T04:52:08.770077Z","shell.execute_reply":"2022-07-22T04:52:09.083040Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### 4. 데이터 전처리","metadata":{}},{"cell_type":"code","source":"train['Expense']=train.RoomService + train.FoodCourt + train.ShoppingMall + train.Spa + train.VRDeck\ntest['Expense']=test.RoomService + test.FoodCourt + test.ShoppingMall + test.Spa + test.VRDeck","metadata":{"execution":{"iopub.status.busy":"2022-07-22T04:53:27.827607Z","iopub.execute_input":"2022-07-22T04:53:27.828006Z","iopub.status.idle":"2022-07-22T04:53:27.839321Z","shell.execute_reply.started":"2022-07-22T04:53:27.827974Z","shell.execute_reply":"2022-07-22T04:53:27.837867Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Cabin 값 데이터 나누기\ntrain.Cabin.str.split('/',expand = True)\ntrain['Cabin_Deck'] = train.Cabin.str.split('/',expand = True)[0]\ntrain['Cabin_Side'] = train.Cabin.str.split('/',expand = True)[2]\ntrain\n\n# Test에도 적용\ntest.Cabin.str.split('/',expand = True)\ntest['Cabin_Deck'] = test.Cabin.str.split('/',expand = True)[0]\ntest['Cabin_Side'] = test.Cabin.str.split('/',expand = True)[2]\ntest","metadata":{"execution":{"iopub.status.busy":"2022-07-22T04:53:28.941000Z","iopub.execute_input":"2022-07-22T04:53:28.941356Z","iopub.status.idle":"2022-07-22T04:53:29.026238Z","shell.execute_reply.started":"2022-07-22T04:53:28.941327Z","shell.execute_reply":"2022-07-22T04:53:29.025043Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Plot categorical features\nfig=plt.figure(figsize=(8,13))\nfor i, var_name in enumerate(['Cabin_Deck','Cabin_Side']):\n    ax=fig.add_subplot(4,1,i+1)\n    sns.countplot(data=train, x=var_name, axes=ax, hue='Transported')\n    ax.set_title(var_name)\nfig.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-22T04:53:31.222044Z","iopub.execute_input":"2022-07-22T04:53:31.222403Z","iopub.status.idle":"2022-07-22T04:53:31.620972Z","shell.execute_reply.started":"2022-07-22T04:53:31.222375Z","shell.execute_reply":"2022-07-22T04:53:31.620013Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# # New features - training set\ntrain['Age_group']=np.nan\ntrain.loc[train['Age']<=12,'Age_group']='Age_0-12'\ntrain.loc[(train['Age']>12) & (train['Age']<18),'Age_group']='Age_13-17'\ntrain.loc[(train['Age']>=18) & (train['Age']<=25),'Age_group']='Age_18-25'\ntrain.loc[(train['Age']>25) & (train['Age']<=30),'Age_group']='Age_26-30'\ntrain.loc[(train['Age']>30) & (train['Age']<=50),'Age_group']='Age_31-50'\ntrain.loc[train['Age']>50,'Age_group']='Age_51+'\n\n# # New features - test set\ntest['Age_group']=np.nan\ntest.loc[test['Age']<=12,'Age_group']='Age_0-12'\ntest.loc[(test['Age']>12) & (test['Age']<18),'Age_group']='Age_13-17'\ntest.loc[(test['Age']>=18) & (test['Age']<=25),'Age_group']='Age_18-25'\ntest.loc[(test['Age']>25) & (test['Age']<=30),'Age_group']='Age_26-30'\ntest.loc[(test['Age']>30) & (test['Age']<=50),'Age_group']='Age_31-50'\ntest.loc[test['Age']>50,'Age_group']='Age_51+'","metadata":{"execution":{"iopub.status.busy":"2022-07-22T04:53:31.771059Z","iopub.execute_input":"2022-07-22T04:53:31.771437Z","iopub.status.idle":"2022-07-22T04:53:31.793830Z","shell.execute_reply.started":"2022-07-22T04:53:31.771405Z","shell.execute_reply":"2022-07-22T04:53:31.793034Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 불필요 컬럼 삭제\n\ntrain = train.drop(columns=[\"Name\", \"PassengerId\", \"VIP\", \"Cabin\", \"Age\",'RoomService','FoodCourt','ShoppingMall', 'Spa','VRDeck' ])\ntest = test.drop(columns=[\"Name\",\"PassengerId\", \"VIP\",\"Cabin\", \"Age\",'RoomService','FoodCourt','ShoppingMall', 'Spa','VRDeck'])","metadata":{"execution":{"iopub.status.busy":"2022-07-22T04:53:32.449787Z","iopub.execute_input":"2022-07-22T04:53:32.450362Z","iopub.status.idle":"2022-07-22T04:53:32.459919Z","shell.execute_reply.started":"2022-07-22T04:53:32.450325Z","shell.execute_reply":"2022-07-22T04:53:32.459185Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 결측치 컬럼 확인\nprint(train.columns[train.isnull().any()])  ","metadata":{"execution":{"iopub.status.busy":"2022-07-22T04:53:33.367069Z","iopub.execute_input":"2022-07-22T04:53:33.367758Z","iopub.status.idle":"2022-07-22T04:53:33.377201Z","shell.execute_reply.started":"2022-07-22T04:53:33.367721Z","shell.execute_reply":"2022-07-22T04:53:33.376156Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 결측치 처리\n # 카테고리는 최빈값 / 수치형은 중위값\nfor col in train.columns:\n    if train[col].dtype == 'object':\n        train[col] = train[col].fillna(train[col].mode()[0])  # 최빈값으로 처리 \n        test[col] = test[col].fillna(train[col].mode()[0])    # 최빈값으로 처리 \n    elif train[col].dtype == 'float64':\n        train[col] = train[col].fillna(train[col].median())  #중위값으로 처리 \n        test[col] = test[col].fillna(train[col].median())    #중위값으로 처리 ","metadata":{"execution":{"iopub.status.busy":"2022-07-22T04:53:33.798934Z","iopub.execute_input":"2022-07-22T04:53:33.800009Z","iopub.status.idle":"2022-07-22T04:53:33.826858Z","shell.execute_reply.started":"2022-07-22T04:53:33.799936Z","shell.execute_reply":"2022-07-22T04:53:33.825961Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 결측치 확인\nprint(train.columns[train.isnull().any()]) ","metadata":{"execution":{"iopub.status.busy":"2022-07-22T04:53:35.438311Z","iopub.execute_input":"2022-07-22T04:53:35.438736Z","iopub.status.idle":"2022-07-22T04:53:35.448240Z","shell.execute_reply.started":"2022-07-22T04:53:35.438701Z","shell.execute_reply":"2022-07-22T04:53:35.447346Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 데이터 타입이 object인 것은 ont hot encoding 진\ntrain.info()","metadata":{"execution":{"iopub.status.busy":"2022-07-22T04:53:35.637575Z","iopub.execute_input":"2022-07-22T04:53:35.638256Z","iopub.status.idle":"2022-07-22T04:53:35.655289Z","shell.execute_reply.started":"2022-07-22T04:53:35.638217Z","shell.execute_reply":"2022-07-22T04:53:35.654291Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cat_features = ['HomePlanet','Destination','Cabin_Deck','Cabin_Side', 'Age_group']\ntrain = pd.get_dummies(data=train, columns=cat_features)\ntrain","metadata":{"execution":{"iopub.status.busy":"2022-07-22T04:53:35.854669Z","iopub.execute_input":"2022-07-22T04:53:35.855751Z","iopub.status.idle":"2022-07-22T04:53:35.889641Z","shell.execute_reply.started":"2022-07-22T04:53:35.855700Z","shell.execute_reply":"2022-07-22T04:53:35.888526Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test = pd.get_dummies(data=test, columns=cat_features)\ntrain.shape , test.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-22T04:53:39.238520Z","iopub.execute_input":"2022-07-22T04:53:39.238861Z","iopub.status.idle":"2022-07-22T04:53:39.256287Z","shell.execute_reply.started":"2022-07-22T04:53:39.238824Z","shell.execute_reply":"2022-07-22T04:53:39.255364Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.columns","metadata":{"execution":{"iopub.status.busy":"2022-07-22T04:53:41.337090Z","iopub.execute_input":"2022-07-22T04:53:41.337967Z","iopub.status.idle":"2022-07-22T04:53:41.344524Z","shell.execute_reply.started":"2022-07-22T04:53:41.337904Z","shell.execute_reply":"2022-07-22T04:53:41.343688Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.columns","metadata":{"execution":{"iopub.status.busy":"2022-07-22T04:53:48.413428Z","iopub.execute_input":"2022-07-22T04:53:48.413776Z","iopub.status.idle":"2022-07-22T04:53:48.420255Z","shell.execute_reply.started":"2022-07-22T04:53:48.413748Z","shell.execute_reply":"2022-07-22T04:53:48.419467Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### 5. 데이터 분할","metadata":{}},{"cell_type":"code","source":"#2. Data Split \nfrom sklearn.model_selection import train_test_split\n\nX = train.drop(columns=\"Transported\")\ny = train.Transported\n\nX_train, X_val, y_train, y_val = train_test_split(X, y, test_size=0.2, random_state=44)\nprint(X_train.shape, X_val.shape, y_train.shape, y_val.shape)","metadata":{"execution":{"iopub.status.busy":"2022-07-22T04:54:05.763895Z","iopub.execute_input":"2022-07-22T04:54:05.764297Z","iopub.status.idle":"2022-07-22T04:54:05.777820Z","shell.execute_reply.started":"2022-07-22T04:54:05.764265Z","shell.execute_reply":"2022-07-22T04:54:05.776861Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### 6. 모델 학습","metadata":{}},{"cell_type":"code","source":"from sklearn.ensemble import RandomForestClassifier\n\n\n#6-1. 모델 학습 \nclf = RandomForestClassifier(max_depth=5, random_state=42)\n\n\nclf.fit(X_train, y_train) # training\n","metadata":{"execution":{"iopub.status.busy":"2022-07-22T04:54:10.360511Z","iopub.execute_input":"2022-07-22T04:54:10.361688Z","iopub.status.idle":"2022-07-22T04:54:10.658500Z","shell.execute_reply.started":"2022-07-22T04:54:10.361650Z","shell.execute_reply":"2022-07-22T04:54:10.657412Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#6-2 모델 평가\nfrom sklearn.metrics import accuracy_score\n\npred = clf.predict(X_train)\npred2 = clf.predict(X_val)\n\nprint(\"Training Acc : %.4f\" % accuracy_score(y_train, pred))\nprint(\"Validation Acc : %.4f\" % accuracy_score(y_val, pred2))","metadata":{"execution":{"iopub.status.busy":"2022-07-22T04:54:13.527634Z","iopub.execute_input":"2022-07-22T04:54:13.527998Z","iopub.status.idle":"2022-07-22T04:54:13.640657Z","shell.execute_reply.started":"2022-07-22T04:54:13.527938Z","shell.execute_reply":"2022-07-22T04:54:13.639902Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### 6. 하이퍼파리미터 튜닝","metadata":{}},{"cell_type":"code","source":"def objective2(trial):\n\n    # tuning을 할 Hyper-parameter를 정의합니다.\n    n_estimators = trial.suggest_int('n_estimators', 50, 200)\n    max_depth = trial.suggest_int('max_depth', 3, 11)  # rules of thumb : sqrt(# of features)\n    max_features = trial.suggest_float('max_features', 0.7, 0.9)\n    # 정의된 Hyper-parameter를 돌릴 모델을 정의합니다.\n    clf2 = RandomForestClassifier(n_estimators=n_estimators,\n                                max_depth=max_depth,\n                                max_features=max_features)\n    \n    # 학습\n    clf2.fit(X_train, y_train)\n    pred3 = clf2.predict(X_train)\n    \n    # 성능 평가\n    ACC = accuracy_score(y_train, pred3)\n\n    return ACC\n\nstudy = optuna.create_study(direction='maximize')\nstudy.optimize(objective2, n_trials=100)","metadata":{"execution":{"iopub.status.busy":"2022-07-22T04:54:24.655462Z","iopub.execute_input":"2022-07-22T04:54:24.655852Z","iopub.status.idle":"2022-07-22T04:56:38.219127Z","shell.execute_reply.started":"2022-07-22T04:54:24.655817Z","shell.execute_reply":"2022-07-22T04:56:38.217924Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"optuna.visualization.plot_optimization_history(study)","metadata":{"execution":{"iopub.status.busy":"2022-07-22T04:57:12.660153Z","iopub.execute_input":"2022-07-22T04:57:12.660507Z","iopub.status.idle":"2022-07-22T04:57:12.814738Z","shell.execute_reply.started":"2022-07-22T04:57:12.660479Z","shell.execute_reply":"2022-07-22T04:57:12.813749Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"optuna.visualization.plot_param_importances(study)","metadata":{"execution":{"iopub.status.busy":"2022-07-22T04:57:17.652572Z","iopub.execute_input":"2022-07-22T04:57:17.652939Z","iopub.status.idle":"2022-07-22T04:57:19.599646Z","shell.execute_reply.started":"2022-07-22T04:57:17.652909Z","shell.execute_reply":"2022-07-22T04:57:19.598727Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"final_rf = RandomForestClassifier(**study.best_params)\nfinal_rf.fit(X, y)\n\nprint(\"\\n\\nBest params for RandomForestClassifier\" , final_rf.get_params())","metadata":{"execution":{"iopub.status.busy":"2022-07-22T04:57:23.042516Z","iopub.execute_input":"2022-07-22T04:57:23.042866Z","iopub.status.idle":"2022-07-22T04:57:24.228891Z","shell.execute_reply.started":"2022-07-22T04:57:23.042837Z","shell.execute_reply":"2022-07-22T04:57:24.227768Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred3 = final_rf.predict(X_train)\npred4 = final_rf.predict(X_val)\n\nprint(\"Training Acc : %.4f\" % accuracy_score(y_train, pred3))\nprint(\"Val Acc : %.4f\" % accuracy_score(y_val, pred4))\n","metadata":{"execution":{"iopub.status.busy":"2022-07-22T04:57:26.461790Z","iopub.execute_input":"2022-07-22T04:57:26.462203Z","iopub.status.idle":"2022-07-22T04:57:26.633871Z","shell.execute_reply.started":"2022-07-22T04:57:26.462168Z","shell.execute_reply":"2022-07-22T04:57:26.632710Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### 7. Submission","metadata":{}},{"cell_type":"code","source":"#pediction \nX_test = test\nresult = final_rf.predict(X_test)\nresult","metadata":{"execution":{"iopub.status.busy":"2022-07-22T04:58:27.540578Z","iopub.execute_input":"2022-07-22T04:58:27.540982Z","iopub.status.idle":"2022-07-22T04:58:27.630385Z","shell.execute_reply.started":"2022-07-22T04:58:27.540933Z","shell.execute_reply":"2022-07-22T04:58:27.629585Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission[\"Transported\"] = result \nsubmission","metadata":{"execution":{"iopub.status.busy":"2022-07-22T04:58:29.464875Z","iopub.execute_input":"2022-07-22T04:58:29.465517Z","iopub.status.idle":"2022-07-22T04:58:29.480330Z","shell.execute_reply.started":"2022-07-22T04:58:29.465469Z","shell.execute_reply":"2022-07-22T04:58:29.479212Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission.reset_index(drop=True).to_csv(\"submission.csv\", index=False)","metadata":{"execution":{"iopub.status.busy":"2022-07-22T04:58:32.587420Z","iopub.execute_input":"2022-07-22T04:58:32.587766Z","iopub.status.idle":"2022-07-22T04:58:32.600889Z","shell.execute_reply.started":"2022-07-22T04:58:32.587739Z","shell.execute_reply":"2022-07-22T04:58:32.599808Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}