{"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":"# this notebook is very simple xgboost\n# rarely feature engineering ","metadata":{}},{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-06-28T05:53:10.784714Z","iopub.execute_input":"2022-06-28T05:53:10.785427Z","iopub.status.idle":"2022-06-28T05:53:10.820412Z","shell.execute_reply.started":"2022-06-28T05:53:10.785248Z","shell.execute_reply":"2022-06-28T05:53:10.819451Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = pd.read_csv('/kaggle/input/spaceship-titanic/train.csv')\ntest = pd.read_csv('/kaggle/input/spaceship-titanic/test.csv')\nsubmission = pd.read_csv('/kaggle/input/spaceship-titanic/sample_submission.csv')","metadata":{"execution":{"iopub.status.busy":"2022-06-28T05:53:10.823967Z","iopub.execute_input":"2022-06-28T05:53:10.824353Z","iopub.status.idle":"2022-06-28T05:53:10.92083Z","shell.execute_reply.started":"2022-06-28T05:53:10.824318Z","shell.execute_reply":"2022-06-28T05:53:10.91984Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()","metadata":{"execution":{"iopub.status.busy":"2022-06-28T05:53:10.923893Z","iopub.execute_input":"2022-06-28T05:53:10.924796Z","iopub.status.idle":"2022-06-28T05:53:10.9588Z","shell.execute_reply.started":"2022-06-28T05:53:10.924757Z","shell.execute_reply":"2022-06-28T05:53:10.957882Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.head()","metadata":{"execution":{"iopub.status.busy":"2022-06-28T05:53:10.960164Z","iopub.execute_input":"2022-06-28T05:53:10.96073Z","iopub.status.idle":"2022-06-28T05:53:10.988874Z","shell.execute_reply.started":"2022-06-28T05:53:10.960696Z","shell.execute_reply":"2022-06-28T05:53:10.987387Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"columns_description = {\n    'PassengerId': \"'gggg_pp' Id, 'gggg': group id, 'pp': personal id within group\",\n    'HomePlanet': \"Hometown planet\",\n    'CryoSleep': \"frozen sleep\",\n    'Cabin': \"cabin number where the passenger is staying\", \n    'Destination': \"planet destination\",\n    'Age': 'age', \n    'VIP': \"paid for special VIP service\",\n    'RoomService': \"billed at luxury amenity\",\n    'FoodCourt': \"billed at luxury amenity\",\n    'ShoppingMall': \"billed at luxury amenity\",\n    'Spa': \"billed at luxury amenity\",\n    'VRDeck': \"billed at luxury amenity\",\n    'Name': \"name\",\n    'Transported': \"Target\"\n}","metadata":{"execution":{"iopub.status.busy":"2022-06-28T05:53:10.991981Z","iopub.execute_input":"2022-06-28T05:53:10.993628Z","iopub.status.idle":"2022-06-28T05:53:11.002795Z","shell.execute_reply.started":"2022-06-28T05:53:10.993572Z","shell.execute_reply":"2022-06-28T05:53:11.001417Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.describe()","metadata":{"execution":{"iopub.status.busy":"2022-06-28T05:53:11.004443Z","iopub.execute_input":"2022-06-28T05:53:11.005099Z","iopub.status.idle":"2022-06-28T05:53:11.058371Z","shell.execute_reply.started":"2022-06-28T05:53:11.005054Z","shell.execute_reply":"2022-06-28T05:53:11.057322Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.info()","metadata":{"execution":{"iopub.status.busy":"2022-06-28T05:53:11.05979Z","iopub.execute_input":"2022-06-28T05:53:11.060954Z","iopub.status.idle":"2022-06-28T05:53:11.09114Z","shell.execute_reply.started":"2022-06-28T05:53:11.060906Z","shell.execute_reply":"2022-06-28T05:53:11.090343Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.shape, test.shape","metadata":{"execution":{"iopub.status.busy":"2022-06-28T05:53:11.093792Z","iopub.execute_input":"2022-06-28T05:53:11.094113Z","iopub.status.idle":"2022-06-28T05:53:11.100273Z","shell.execute_reply.started":"2022-06-28T05:53:11.094083Z","shell.execute_reply":"2022-06-28T05:53:11.099463Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Null data check","metadata":{}},{"cell_type":"code","source":"null_df = pd.DataFrame()\nnull_cnt = []\nnull_percent = []\nfor col in train.columns:\n    cnt = train[col].isnull().sum()\n    null_cnt += [cnt]\n    null_percent += [cnt / len(train) * 100]\nnull_df['feature'] = train.columns\nnull_df['null_count'] = null_cnt\nnull_df['null_percent'] = null_percent\nnull_df.sort_values('null_count', ascending=False, inplace=True)\nnull_df","metadata":{"execution":{"iopub.status.busy":"2022-06-28T05:53:11.10166Z","iopub.execute_input":"2022-06-28T05:53:11.10267Z","iopub.status.idle":"2022-06-28T05:53:11.135379Z","shell.execute_reply.started":"2022-06-28T05:53:11.10263Z","shell.execute_reply":"2022-06-28T05:53:11.134481Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import missingno as msno\nmsno.matrix(df=train.iloc[:, :], figsize=(8, 8))","metadata":{"execution":{"iopub.status.busy":"2022-06-28T05:53:11.136756Z","iopub.execute_input":"2022-06-28T05:53:11.13707Z","iopub.status.idle":"2022-06-28T05:53:12.322656Z","shell.execute_reply.started":"2022-06-28T05:53:11.137043Z","shell.execute_reply":"2022-06-28T05:53:12.321353Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"msno.matrix(df=test.iloc[:, :], figsize=(8, 8))","metadata":{"execution":{"iopub.status.busy":"2022-06-28T05:53:12.325504Z","iopub.execute_input":"2022-06-28T05:53:12.325994Z","iopub.status.idle":"2022-06-28T05:53:12.669066Z","shell.execute_reply.started":"2022-06-28T05:53:12.325948Z","shell.execute_reply":"2022-06-28T05:53:12.667775Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"feats_cat = []\nfeats_num = []\nfor col in train.columns:\n    if col in ['PassengerId', 'Transported']:\n        continue\n    if train[col].dtype == 'object':\n        feats_cat += [col]\n    else:\n        feats_num += [col]\n        \nfeats_cat, feats_num","metadata":{"execution":{"iopub.status.busy":"2022-06-28T05:53:12.673638Z","iopub.execute_input":"2022-06-28T05:53:12.674721Z","iopub.status.idle":"2022-06-28T05:53:12.690132Z","shell.execute_reply.started":"2022-06-28T05:53:12.674665Z","shell.execute_reply":"2022-06-28T05:53:12.688085Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Target label","metadata":{}},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nf, ax = plt.subplots(figsize=(8, 8))\ntrain['Transported'].value_counts().plot(ax=ax, kind='bar', ylabel='frequency')","metadata":{"execution":{"iopub.status.busy":"2022-06-28T05:53:12.69293Z","iopub.execute_input":"2022-06-28T05:53:12.693676Z","iopub.status.idle":"2022-06-28T05:53:12.894212Z","shell.execute_reply.started":"2022-06-28T05:53:12.693592Z","shell.execute_reply":"2022-06-28T05:53:12.893227Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### continuous & categorical feature","metadata":{}},{"cell_type":"code","source":"num_feats, cat_feats = [], []\nfor col in train.columns:\n    if train[col].dtype == 'object':\n        cat_feats += [col]\n    elif train[col].dtype == 'float64':\n        num_feats += [col]","metadata":{"execution":{"iopub.status.busy":"2022-06-28T05:53:12.896255Z","iopub.execute_input":"2022-06-28T05:53:12.896728Z","iopub.status.idle":"2022-06-28T05:53:12.903307Z","shell.execute_reply.started":"2022-06-28T05:53:12.896696Z","shell.execute_reply":"2022-06-28T05:53:12.902381Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"num_feats, cat_feats","metadata":{"execution":{"iopub.status.busy":"2022-06-28T05:53:12.904622Z","iopub.execute_input":"2022-06-28T05:53:12.905132Z","iopub.status.idle":"2022-06-28T05:53:12.918068Z","shell.execute_reply.started":"2022-06-28T05:53:12.905101Z","shell.execute_reply":"2022-06-28T05:53:12.917054Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### PassengerId","metadata":{}},{"cell_type":"code","source":"train['PassengerId'].isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-06-28T05:53:12.919512Z","iopub.execute_input":"2022-06-28T05:53:12.92006Z","iopub.status.idle":"2022-06-28T05:53:12.931314Z","shell.execute_reply.started":"2022-06-28T05:53:12.920024Z","shell.execute_reply":"2022-06-28T05:53:12.93039Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### HomePlanet","metadata":{}},{"cell_type":"code","source":"train['HomePlanet'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-06-28T05:53:12.933014Z","iopub.execute_input":"2022-06-28T05:53:12.934223Z","iopub.status.idle":"2022-06-28T05:53:12.946417Z","shell.execute_reply.started":"2022-06-28T05:53:12.934188Z","shell.execute_reply":"2022-06-28T05:53:12.945316Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def Target_True_func(x):\n    return (x == True).sum()\n\ndef Target_False_func(x):\n    return (x == False).sum()\n    \ntrain[['HomePlanet', 'Transported']].groupby('HomePlanet').agg([Target_True_func, Target_False_func])","metadata":{"execution":{"iopub.status.busy":"2022-06-28T05:53:12.948159Z","iopub.execute_input":"2022-06-28T05:53:12.948887Z","iopub.status.idle":"2022-06-28T05:53:12.974943Z","shell.execute_reply.started":"2022-06-28T05:53:12.948853Z","shell.execute_reply":"2022-06-28T05:53:12.973793Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pd.crosstab(train['HomePlanet'], train['Transported'], margins=True)","metadata":{"execution":{"iopub.status.busy":"2022-06-28T05:53:12.976629Z","iopub.execute_input":"2022-06-28T05:53:12.976988Z","iopub.status.idle":"2022-06-28T05:53:13.042995Z","shell.execute_reply.started":"2022-06-28T05:53:12.976955Z","shell.execute_reply":"2022-06-28T05:53:13.041848Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train[['HomePlanet', 'Transported']].groupby('HomePlanet').mean().sort_values('Transported', ascending=False).plot.bar()","metadata":{"execution":{"iopub.status.busy":"2022-06-28T05:53:13.04441Z","iopub.execute_input":"2022-06-28T05:53:13.045687Z","iopub.status.idle":"2022-06-28T05:53:13.239131Z","shell.execute_reply.started":"2022-06-28T05:53:13.045639Z","shell.execute_reply":"2022-06-28T05:53:13.238303Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import seaborn as sns\nfig, ax = plt.subplots(1, 2)\nsns.countplot(x='HomePlanet', data=train, ax=ax[0])\nsns.countplot(x='HomePlanet', hue='Transported',data=train, ax=ax[1])\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-06-28T05:53:13.241165Z","iopub.execute_input":"2022-06-28T05:53:13.242433Z","iopub.status.idle":"2022-06-28T05:53:13.573996Z","shell.execute_reply.started":"2022-06-28T05:53:13.242388Z","shell.execute_reply":"2022-06-28T05:53:13.57238Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cat_feats","metadata":{"execution":{"iopub.status.busy":"2022-06-28T05:53:13.581296Z","iopub.execute_input":"2022-06-28T05:53:13.58174Z","iopub.status.idle":"2022-06-28T05:53:13.589626Z","shell.execute_reply.started":"2022-06-28T05:53:13.581707Z","shell.execute_reply":"2022-06-28T05:53:13.588379Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### CryoSleep","metadata":{}},{"cell_type":"code","source":"train['CryoSleep'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-06-28T05:53:13.591272Z","iopub.execute_input":"2022-06-28T05:53:13.592085Z","iopub.status.idle":"2022-06-28T05:53:13.606694Z","shell.execute_reply.started":"2022-06-28T05:53:13.592036Z","shell.execute_reply":"2022-06-28T05:53:13.60573Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"f, ax = plt.subplots(1, 2, figsize=(10, 6))\ntrain[['CryoSleep', 'Transported']].groupby('CryoSleep').mean().plot.bar(ax=ax[0])\nsns.countplot(x='CryoSleep', data=train, ax=ax[1], hue='Transported')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-06-28T05:53:13.609036Z","iopub.execute_input":"2022-06-28T05:53:13.609566Z","iopub.status.idle":"2022-06-28T05:53:13.974982Z","shell.execute_reply.started":"2022-06-28T05:53:13.609517Z","shell.execute_reply":"2022-06-28T05:53:13.973385Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.factorplot('HomePlanet', 'Transported', hue='CryoSleep', data=train)","metadata":{"execution":{"iopub.status.busy":"2022-06-28T05:53:13.979432Z","iopub.execute_input":"2022-06-28T05:53:13.979878Z","iopub.status.idle":"2022-06-28T05:53:14.744386Z","shell.execute_reply.started":"2022-06-28T05:53:13.979842Z","shell.execute_reply":"2022-06-28T05:53:14.743431Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cat_feats","metadata":{"execution":{"iopub.status.busy":"2022-06-28T05:53:14.745755Z","iopub.execute_input":"2022-06-28T05:53:14.746378Z","iopub.status.idle":"2022-06-28T05:53:14.755187Z","shell.execute_reply.started":"2022-06-28T05:53:14.746335Z","shell.execute_reply":"2022-06-28T05:53:14.753801Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Cabin","metadata":{}},{"cell_type":"code","source":"train['Cabin'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-06-28T05:53:14.757356Z","iopub.execute_input":"2022-06-28T05:53:14.7588Z","iopub.status.idle":"2022-06-28T05:53:14.778628Z","shell.execute_reply.started":"2022-06-28T05:53:14.758754Z","shell.execute_reply":"2022-06-28T05:53:14.776725Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"feat_extension = ['PassengerId', 'Cabin']","metadata":{"execution":{"iopub.status.busy":"2022-06-28T05:53:14.781112Z","iopub.execute_input":"2022-06-28T05:53:14.781994Z","iopub.status.idle":"2022-06-28T05:53:14.787066Z","shell.execute_reply.started":"2022-06-28T05:53:14.781945Z","shell.execute_reply":"2022-06-28T05:53:14.78636Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cat_feats","metadata":{"execution":{"iopub.status.busy":"2022-06-28T05:53:14.788187Z","iopub.execute_input":"2022-06-28T05:53:14.788702Z","iopub.status.idle":"2022-06-28T05:53:14.800177Z","shell.execute_reply.started":"2022-06-28T05:53:14.788664Z","shell.execute_reply":"2022-06-28T05:53:14.799343Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Destination","metadata":{}},{"cell_type":"code","source":"train['Destination'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-06-28T05:53:14.801269Z","iopub.execute_input":"2022-06-28T05:53:14.80215Z","iopub.status.idle":"2022-06-28T05:53:14.816175Z","shell.execute_reply.started":"2022-06-28T05:53:14.802109Z","shell.execute_reply":"2022-06-28T05:53:14.815399Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, ax = plt.subplots(1, 2, figsize=(10, 6))\ntrain[['Destination', 'Transported']].groupby('Destination').mean().plot.bar(ax=ax[0])\nsns.countplot(x='Destination', hue='Transported', data=train, ax=ax[1])","metadata":{"execution":{"iopub.status.busy":"2022-06-28T05:53:14.817412Z","iopub.execute_input":"2022-06-28T05:53:14.818072Z","iopub.status.idle":"2022-06-28T05:53:15.161803Z","shell.execute_reply.started":"2022-06-28T05:53:14.818037Z","shell.execute_reply":"2022-06-28T05:53:15.160752Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pd.crosstab(index=train['Destination'], columns=train['HomePlanet'], normalize='index', margins=True)","metadata":{"execution":{"iopub.status.busy":"2022-06-28T05:53:15.163694Z","iopub.execute_input":"2022-06-28T05:53:15.164123Z","iopub.status.idle":"2022-06-28T05:53:15.215654Z","shell.execute_reply.started":"2022-06-28T05:53:15.164081Z","shell.execute_reply":"2022-06-28T05:53:15.214888Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### VIP","metadata":{}},{"cell_type":"code","source":"train['VIP'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-06-28T05:53:15.216947Z","iopub.execute_input":"2022-06-28T05:53:15.218181Z","iopub.status.idle":"2022-06-28T05:53:15.229125Z","shell.execute_reply.started":"2022-06-28T05:53:15.218138Z","shell.execute_reply":"2022-06-28T05:53:15.228132Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, ax = plt.subplots(1, 2, figsize=(10, 6))\ntrain[['VIP', 'Transported']].groupby('VIP').mean().plot.bar(ax=ax[0])\nsns.countplot(x='VIP', hue='Transported', data=train, ax=ax[1])","metadata":{"execution":{"iopub.status.busy":"2022-06-28T05:53:15.230865Z","iopub.execute_input":"2022-06-28T05:53:15.231734Z","iopub.status.idle":"2022-06-28T05:53:15.577551Z","shell.execute_reply.started":"2022-06-28T05:53:15.23169Z","shell.execute_reply":"2022-06-28T05:53:15.576657Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cat_feats","metadata":{"execution":{"iopub.status.busy":"2022-06-28T05:53:15.578808Z","iopub.execute_input":"2022-06-28T05:53:15.579327Z","iopub.status.idle":"2022-06-28T05:53:15.585399Z","shell.execute_reply.started":"2022-06-28T05:53:15.57927Z","shell.execute_reply":"2022-06-28T05:53:15.584515Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Name","metadata":{}},{"cell_type":"code","source":"len(train['Name'].unique()), len(train)","metadata":{"execution":{"iopub.status.busy":"2022-06-28T05:53:15.586506Z","iopub.execute_input":"2022-06-28T05:53:15.587094Z","iopub.status.idle":"2022-06-28T05:53:15.599227Z","shell.execute_reply.started":"2022-06-28T05:53:15.587058Z","shell.execute_reply":"2022-06-28T05:53:15.598433Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cat_feats, num_feats","metadata":{"execution":{"iopub.status.busy":"2022-06-28T05:53:15.600446Z","iopub.execute_input":"2022-06-28T05:53:15.601218Z","iopub.status.idle":"2022-06-28T05:53:15.613768Z","shell.execute_reply.started":"2022-06-28T05:53:15.601184Z","shell.execute_reply":"2022-06-28T05:53:15.611793Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Age","metadata":{}},{"cell_type":"code","source":"train['Age'].max(), train['Age'].min(), train['Age'].mean()","metadata":{"execution":{"iopub.status.busy":"2022-06-28T05:53:15.61573Z","iopub.execute_input":"2022-06-28T05:53:15.616629Z","iopub.status.idle":"2022-06-28T05:53:15.628366Z","shell.execute_reply.started":"2022-06-28T05:53:15.616553Z","shell.execute_reply":"2022-06-28T05:53:15.627465Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.kdeplot(x='Age', hue='Transported', data=train)","metadata":{"execution":{"iopub.status.busy":"2022-06-28T05:53:15.630218Z","iopub.execute_input":"2022-06-28T05:53:15.631223Z","iopub.status.idle":"2022-06-28T05:53:15.900068Z","shell.execute_reply.started":"2022-06-28T05:53:15.631174Z","shell.execute_reply":"2022-06-28T05:53:15.899221Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### RoomService, FoodCourt, ShoppingMall, Spa, VRDeck","metadata":{}},{"cell_type":"code","source":"import copy\nnum_feats_ = copy.deepcopy(num_feats)\nnum_feats_.remove('Age')\nfig, axes = plt.subplots(len(num_feats_), 1, figsize=(6, 15))\nfor i, col in enumerate(num_feats_):\n    print(train[col].max(), train[col].min(), train[col].mean())\n    sns.kdeplot(x=col, hue='Transported', data=train, ax=axes[i])","metadata":{"execution":{"iopub.status.busy":"2022-06-28T05:53:15.901266Z","iopub.execute_input":"2022-06-28T05:53:15.903667Z","iopub.status.idle":"2022-06-28T05:53:17.034577Z","shell.execute_reply.started":"2022-06-28T05:53:15.903623Z","shell.execute_reply":"2022-06-28T05:53:17.033679Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"g = sns.pairplot(train[num_feats_+['Transported']], hue='Transported', kind='kde')\ng.set(ylim=(0, 5000), xlim=(0, 5000))","metadata":{"execution":{"iopub.status.busy":"2022-06-28T05:53:17.035807Z","iopub.execute_input":"2022-06-28T05:53:17.037253Z","iopub.status.idle":"2022-06-28T05:55:41.595989Z","shell.execute_reply.started":"2022-06-28T05:53:17.037216Z","shell.execute_reply":"2022-06-28T05:55:41.594488Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Feature engineering","metadata":{}},{"cell_type":"code","source":"dataset = pd.concat([train, test], axis=0).reset_index(drop=True)\ndataset","metadata":{"execution":{"iopub.status.busy":"2022-06-28T05:55:41.598688Z","iopub.execute_input":"2022-06-28T05:55:41.599188Z","iopub.status.idle":"2022-06-28T05:55:41.647172Z","shell.execute_reply.started":"2022-06-28T05:55:41.599141Z","shell.execute_reply":"2022-06-28T05:55:41.646004Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset = dataset.drop(columns=['PassengerId', 'Cabin', 'Name'])","metadata":{"execution":{"iopub.status.busy":"2022-06-28T05:55:41.648719Z","iopub.execute_input":"2022-06-28T05:55:41.649201Z","iopub.status.idle":"2022-06-28T05:55:41.656484Z","shell.execute_reply.started":"2022-06-28T05:55:41.649165Z","shell.execute_reply":"2022-06-28T05:55:41.655423Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset.head()","metadata":{"execution":{"iopub.status.busy":"2022-06-28T05:55:41.658065Z","iopub.execute_input":"2022-06-28T05:55:41.658593Z","iopub.status.idle":"2022-06-28T05:55:41.683351Z","shell.execute_reply.started":"2022-06-28T05:55:41.658556Z","shell.execute_reply":"2022-06-28T05:55:41.681798Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cat_feats","metadata":{"execution":{"iopub.status.busy":"2022-06-28T05:55:41.684928Z","iopub.execute_input":"2022-06-28T05:55:41.685628Z","iopub.status.idle":"2022-06-28T05:55:41.693459Z","shell.execute_reply.started":"2022-06-28T05:55:41.685581Z","shell.execute_reply":"2022-06-28T05:55:41.692178Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cat_feats = list(set(cat_feats) - set(['PassengerId', 'Cabin', 'Name']))\ncat_feats","metadata":{"execution":{"iopub.status.busy":"2022-06-28T05:55:41.695161Z","iopub.execute_input":"2022-06-28T05:55:41.696314Z","iopub.status.idle":"2022-06-28T05:55:41.705996Z","shell.execute_reply.started":"2022-06-28T05:55:41.696252Z","shell.execute_reply":"2022-06-28T05:55:41.705082Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset = pd.get_dummies(dataset, columns=cat_feats)\ndataset.head()","metadata":{"execution":{"iopub.status.busy":"2022-06-28T05:55:41.707237Z","iopub.execute_input":"2022-06-28T05:55:41.707756Z","iopub.status.idle":"2022-06-28T05:55:41.747839Z","shell.execute_reply.started":"2022-06-28T05:55:41.707725Z","shell.execute_reply":"2022-06-28T05:55:41.746791Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset = dataset.fillna(-1)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## model (XGBoost)","metadata":{}},{"cell_type":"code","source":"train_length = len(train)\ntrain, test = dataset[:train_length], dataset[train_length:]","metadata":{"execution":{"iopub.status.busy":"2022-06-28T05:55:41.749184Z","iopub.execute_input":"2022-06-28T05:55:41.749542Z","iopub.status.idle":"2022-06-28T05:55:41.754824Z","shell.execute_reply.started":"2022-06-28T05:55:41.749512Z","shell.execute_reply":"2022-06-28T05:55:41.753736Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_y = train['Transported']\ntrain_x = train.drop('Transported', axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-06-28T05:55:41.756519Z","iopub.execute_input":"2022-06-28T05:55:41.75713Z","iopub.status.idle":"2022-06-28T05:55:41.773962Z","shell.execute_reply.started":"2022-06-28T05:55:41.757098Z","shell.execute_reply":"2022-06-28T05:55:41.772854Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test = test.drop('Transported', axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-06-28T05:55:41.775575Z","iopub.execute_input":"2022-06-28T05:55:41.775902Z","iopub.status.idle":"2022-06-28T05:55:41.785803Z","shell.execute_reply.started":"2022-06-28T05:55:41.775866Z","shell.execute_reply":"2022-06-28T05:55:41.784627Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from xgboost import plot_importance\nfrom xgboost import XGBClassifier","metadata":{"execution":{"iopub.status.busy":"2022-06-28T05:55:41.787594Z","iopub.execute_input":"2022-06-28T05:55:41.788062Z","iopub.status.idle":"2022-06-28T05:55:42.046252Z","shell.execute_reply.started":"2022-06-28T05:55:41.788026Z","shell.execute_reply":"2022-06-28T05:55:42.045087Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\n\nx_train, x_val, y_train, y_val = train_test_split(train_x, train_y, random_state=0, shuffle=True, stratify=train_y, test_size=0.2)","metadata":{"execution":{"iopub.status.busy":"2022-06-28T05:55:42.053827Z","iopub.execute_input":"2022-06-28T05:55:42.054228Z","iopub.status.idle":"2022-06-28T05:55:42.079436Z","shell.execute_reply.started":"2022-06-28T05:55:42.054196Z","shell.execute_reply":"2022-06-28T05:55:42.077787Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_train.shape, x_val.shape, y_train.shape","metadata":{"execution":{"iopub.status.busy":"2022-06-28T05:56:36.130909Z","iopub.execute_input":"2022-06-28T05:56:36.131506Z","iopub.status.idle":"2022-06-28T05:56:36.142725Z","shell.execute_reply.started":"2022-06-28T05:56:36.131444Z","shell.execute_reply":"2022-06-28T05:56:36.141383Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import accuracy_score\nxgb = XGBClassifier()\nxgb.fit(x_train, y_train, eval_set=[(x_val, y_val)], eval_metric='error', verbose=True)","metadata":{"execution":{"iopub.status.busy":"2022-06-28T06:25:25.648401Z","iopub.execute_input":"2022-06-28T06:25:25.648859Z","iopub.status.idle":"2022-06-28T06:25:27.090172Z","shell.execute_reply.started":"2022-06-28T06:25:25.648825Z","shell.execute_reply":"2022-06-28T06:25:27.089111Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_importance(xgb)","metadata":{"execution":{"iopub.status.busy":"2022-06-28T06:25:54.821752Z","iopub.execute_input":"2022-06-28T06:25:54.822141Z","iopub.status.idle":"2022-06-28T06:25:55.130905Z","shell.execute_reply.started":"2022-06-28T06:25:54.82211Z","shell.execute_reply":"2022-06-28T06:25:55.129731Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission['Transported'] = xgb.predict(test).astype('bool')\nsubmission.to_csv('sampleSubmission3.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2022-06-28T07:01:47.941613Z","iopub.execute_input":"2022-06-28T07:01:47.942063Z","iopub.status.idle":"2022-06-28T07:01:47.973977Z","shell.execute_reply.started":"2022-06-28T07:01:47.942029Z","shell.execute_reply":"2022-06-28T07:01:47.972652Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## test score: 0.78138","metadata":{}}]}