{"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":"Problem statement\n\nWelcome to the year 2912, where your data science skills are needed to solve a cosmic mystery. We've received a transmission from four lightyears away and things aren't looking good.\n\nThe Spaceship Titanic was an interstellar passenger liner launched a month ago. With almost 13,000 passengers on board, the vessel set out on its maiden voyage transporting emigrants from our solar system to three newly habitable exoplanets orbiting nearby stars.\n\nWhile rounding Alpha Centauri en route to its first destination—the torrid 55 Cancri E—the unwary Spaceship Titanic collided with a spacetime anomaly hidden within a dust cloud. Sadly, it met a similar fate as its namesake from 1000 years before. Though the ship stayed intact, almost half of the passengers were transported to an alternate dimension!\n\n\n\nTo help rescue crews and retrieve the lost passengers, you are challenged to predict which passengers were transported by the anomaly using records recovered from the spaceship’s damaged computer system.\n\nHelp save them and change history!","metadata":{}},{"cell_type":"markdown","source":"Import libraries","metadata":{}},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport seaborn as sns","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:10.459417Z","iopub.execute_input":"2022-08-07T15:03:10.460257Z","iopub.status.idle":"2022-08-07T15:03:10.464352Z","shell.execute_reply.started":"2022-08-07T15:03:10.460212Z","shell.execute_reply":"2022-08-07T15:03:10.463584Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Load files","metadata":{}},{"cell_type":"code","source":"import os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:10.510056Z","iopub.execute_input":"2022-08-07T15:03:10.510958Z","iopub.status.idle":"2022-08-07T15:03:10.519438Z","shell.execute_reply.started":"2022-08-07T15:03:10.510914Z","shell.execute_reply":"2022-08-07T15:03:10.518729Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Read files","metadata":{}},{"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-08-07T15:03:10.596719Z","iopub.execute_input":"2022-08-07T15:03:10.597166Z","iopub.status.idle":"2022-08-07T15:03:10.647675Z","shell.execute_reply.started":"2022-08-07T15:03:10.597133Z","shell.execute_reply":"2022-08-07T15:03:10.646867Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:10.710722Z","iopub.execute_input":"2022-08-07T15:03:10.711529Z","iopub.status.idle":"2022-08-07T15:03:10.743629Z","shell.execute_reply.started":"2022-08-07T15:03:10.711487Z","shell.execute_reply":"2022-08-07T15:03:10.742796Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:10.781654Z","iopub.execute_input":"2022-08-07T15:03:10.782520Z","iopub.status.idle":"2022-08-07T15:03:10.809685Z","shell.execute_reply.started":"2022-08-07T15:03:10.782472Z","shell.execute_reply":"2022-08-07T15:03:10.808898Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:10.860749Z","iopub.execute_input":"2022-08-07T15:03:10.861637Z","iopub.status.idle":"2022-08-07T15:03:10.875061Z","shell.execute_reply.started":"2022-08-07T15:03:10.861584Z","shell.execute_reply":"2022-08-07T15:03:10.873864Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Analyse train","metadata":{}},{"cell_type":"code","source":"train.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:10.927221Z","iopub.execute_input":"2022-08-07T15:03:10.928045Z","iopub.status.idle":"2022-08-07T15:03:10.938585Z","shell.execute_reply.started":"2022-08-07T15:03:10.927995Z","shell.execute_reply":"2022-08-07T15:03:10.937931Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Drop null values in train set","metadata":{}},{"cell_type":"code","source":"train1 = train.dropna()\ntrain1","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:10.999223Z","iopub.execute_input":"2022-08-07T15:03:10.999981Z","iopub.status.idle":"2022-08-07T15:03:11.035729Z","shell.execute_reply.started":"2022-08-07T15:03:10.999937Z","shell.execute_reply":"2022-08-07T15:03:11.034982Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Drop cabin and name","metadata":{}},{"cell_type":"code","source":"train1.drop(['Cabin', 'Name', 'PassengerId'], axis = 1, inplace=True)\ntest.drop(['Cabin', 'Name', 'PassengerId'], axis = 1, inplace=True)\ntrain1","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:11.080668Z","iopub.execute_input":"2022-08-07T15:03:11.081354Z","iopub.status.idle":"2022-08-07T15:03:11.110751Z","shell.execute_reply.started":"2022-08-07T15:03:11.081313Z","shell.execute_reply":"2022-08-07T15:03:11.109966Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:11.185900Z","iopub.execute_input":"2022-08-07T15:03:11.186210Z","iopub.status.idle":"2022-08-07T15:03:11.212949Z","shell.execute_reply.started":"2022-08-07T15:03:11.186174Z","shell.execute_reply":"2022-08-07T15:03:11.212319Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Analyse target","metadata":{}},{"cell_type":"code","source":"train1['Transported'].replace({False: 0, True: 1},inplace=True)\ntrain1['Transported']","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:11.238583Z","iopub.execute_input":"2022-08-07T15:03:11.238996Z","iopub.status.idle":"2022-08-07T15:03:11.250361Z","shell.execute_reply.started":"2022-08-07T15:03:11.238959Z","shell.execute_reply":"2022-08-07T15:03:11.249564Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.displot(train1['Transported'])","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:11.275415Z","iopub.execute_input":"2022-08-07T15:03:11.275926Z","iopub.status.idle":"2022-08-07T15:03:11.568571Z","shell.execute_reply.started":"2022-08-07T15:03:11.275890Z","shell.execute_reply":"2022-08-07T15:03:11.567661Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"trans_count = train1['Transported'].value_counts()\ntrans_count","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:11.570532Z","iopub.execute_input":"2022-08-07T15:03:11.571199Z","iopub.status.idle":"2022-08-07T15:03:11.578593Z","shell.execute_reply.started":"2022-08-07T15:03:11.571147Z","shell.execute_reply":"2022-08-07T15:03:11.577984Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"trans_percent = trans_count / len(train1)\ntrans_percent","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:11.579912Z","iopub.execute_input":"2022-08-07T15:03:11.580280Z","iopub.status.idle":"2022-08-07T15:03:11.587890Z","shell.execute_reply.started":"2022-08-07T15:03:11.580239Z","shell.execute_reply":"2022-08-07T15:03:11.587113Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(25, 7))\nax = plt.subplot()\nax.scatter(train1[train1['Transported'] == 1]['Age'], train1[train['Transported'] == 1]['FoodCourt'], c='green', s=train1[train1['Transported'] == 1]['VRDeck'])\nax.scatter(train1[train1['Transported'] == 0]['Age'], train1[train['Transported'] == 0]['FoodCourt'], c='red', s=train1[train1['Transported'] == 0]['VRDeck']);\n","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:11.589554Z","iopub.execute_input":"2022-08-07T15:03:11.589768Z","iopub.status.idle":"2022-08-07T15:03:12.059577Z","shell.execute_reply.started":"2022-08-07T15:03:11.589735Z","shell.execute_reply":"2022-08-07T15:03:12.058898Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Drop target","metadata":{}},{"cell_type":"code","source":"target = train1['Transported']\n\ntrain1.drop(['Transported'],axis=1, inplace=True)\ntrain1","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:12.060855Z","iopub.execute_input":"2022-08-07T15:03:12.061221Z","iopub.status.idle":"2022-08-07T15:03:12.090121Z","shell.execute_reply.started":"2022-08-07T15:03:12.061189Z","shell.execute_reply":"2022-08-07T15:03:12.089301Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Combine train and test","metadata":{}},{"cell_type":"code","source":"combi = train1.append(test)\ncombi","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:12.091253Z","iopub.execute_input":"2022-08-07T15:03:12.092012Z","iopub.status.idle":"2022-08-07T15:03:12.118260Z","shell.execute_reply.started":"2022-08-07T15:03:12.091967Z","shell.execute_reply":"2022-08-07T15:03:12.117535Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Analyse combi","metadata":{}},{"cell_type":"code","source":"combi.info()","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:12.120045Z","iopub.execute_input":"2022-08-07T15:03:12.120494Z","iopub.status.idle":"2022-08-07T15:03:12.134265Z","shell.execute_reply.started":"2022-08-07T15:03:12.120463Z","shell.execute_reply":"2022-08-07T15:03:12.133653Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"combi.describe()","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:12.135361Z","iopub.execute_input":"2022-08-07T15:03:12.135975Z","iopub.status.idle":"2022-08-07T15:03:12.164756Z","shell.execute_reply.started":"2022-08-07T15:03:12.135943Z","shell.execute_reply":"2022-08-07T15:03:12.164041Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Check for null values","metadata":{}},{"cell_type":"code","source":"combi.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:12.165859Z","iopub.execute_input":"2022-08-07T15:03:12.166084Z","iopub.status.idle":"2022-08-07T15:03:12.178123Z","shell.execute_reply.started":"2022-08-07T15:03:12.166055Z","shell.execute_reply":"2022-08-07T15:03:12.177278Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Impute null values","metadata":{}},{"cell_type":"code","source":"from sklearn.experimental import enable_iterative_imputer\nfrom sklearn.impute import IterativeImputer\n\nimp = IterativeImputer(random_state=42)\n\ndate = pd.Timestamp('2200-01-01')\n\nfor col in combi:\n    if combi[col].dtype==\"object\":\n        combi[col].fillna(\"not listed\", inplace=True)\n    if combi[col].dtype==\"int\":\n        #X[col].fillna(X[col].mode()[0], inplace=True)\n        combi[col].fillna(combi[col].mean(), inplace=True)\n        #combi[col] = combi[col].astype.int()\n    if combi[col].dtype=='float':\n       #X[col].fillna(X[col].mean(), inplace=True)\n       combi[col] = imp.fit_transform(combi[col].values.reshape(-1,1))\n    if combi[col].dtype==\"datetime64[ns]\":\n        combi[col].fillna(date, inplace=True)\ncombi","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:12.179570Z","iopub.execute_input":"2022-08-07T15:03:12.179930Z","iopub.status.idle":"2022-08-07T15:03:12.224434Z","shell.execute_reply.started":"2022-08-07T15:03:12.179890Z","shell.execute_reply":"2022-08-07T15:03:12.223657Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"combi.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:12.225670Z","iopub.execute_input":"2022-08-07T15:03:12.226466Z","iopub.status.idle":"2022-08-07T15:03:12.237412Z","shell.execute_reply.started":"2022-08-07T15:03:12.226422Z","shell.execute_reply":"2022-08-07T15:03:12.236542Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Analyse features","metadata":{}},{"cell_type":"markdown","source":"Home Planet","metadata":{}},{"cell_type":"code","source":"sns.displot(combi['HomePlanet'])","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:12.238707Z","iopub.execute_input":"2022-08-07T15:03:12.238960Z","iopub.status.idle":"2022-08-07T15:03:12.505950Z","shell.execute_reply.started":"2022-08-07T15:03:12.238923Z","shell.execute_reply":"2022-08-07T15:03:12.505301Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"home_count = combi['HomePlanet'].value_counts()\nhome_count","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:12.507256Z","iopub.execute_input":"2022-08-07T15:03:12.507490Z","iopub.status.idle":"2022-08-07T15:03:12.515430Z","shell.execute_reply.started":"2022-08-07T15:03:12.507458Z","shell.execute_reply":"2022-08-07T15:03:12.514629Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"home_percent = home_count / len(combi)\nhome_percent","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:12.516749Z","iopub.execute_input":"2022-08-07T15:03:12.517010Z","iopub.status.idle":"2022-08-07T15:03:12.524563Z","shell.execute_reply.started":"2022-08-07T15:03:12.516975Z","shell.execute_reply":"2022-08-07T15:03:12.523990Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mylabels = [\"Earth\", \"Europa\", \"Mars\", \"not listed\"]\nplt.pie(home_percent, labels=mylabels)\nplt.show() ","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:12.527315Z","iopub.execute_input":"2022-08-07T15:03:12.527614Z","iopub.status.idle":"2022-08-07T15:03:12.756885Z","shell.execute_reply.started":"2022-08-07T15:03:12.527582Z","shell.execute_reply":"2022-08-07T15:03:12.755771Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"combi['HomePlanet'].replace({\"Earth\": 1, \"Europa\": 2, \"Mars\": 3, \"not listed\": 4},inplace=True)\ncombi['HomePlanet']","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:12.758421Z","iopub.execute_input":"2022-08-07T15:03:12.758825Z","iopub.status.idle":"2022-08-07T15:03:12.781392Z","shell.execute_reply.started":"2022-08-07T15:03:12.758770Z","shell.execute_reply":"2022-08-07T15:03:12.780416Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Cryo Sleep","metadata":{}},{"cell_type":"code","source":"combi['CryoSleep'][combi['CryoSleep'] == 'not listed'] = False","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:12.782842Z","iopub.execute_input":"2022-08-07T15:03:12.783372Z","iopub.status.idle":"2022-08-07T15:03:12.798998Z","shell.execute_reply.started":"2022-08-07T15:03:12.783327Z","shell.execute_reply":"2022-08-07T15:03:12.794034Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(combi.iloc[6674])","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:12.800909Z","iopub.execute_input":"2022-08-07T15:03:12.801442Z","iopub.status.idle":"2022-08-07T15:03:12.808612Z","shell.execute_reply.started":"2022-08-07T15:03:12.801398Z","shell.execute_reply":"2022-08-07T15:03:12.807771Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"combi['CryoSleep'].replace({False: 0, True: 1})","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:12.810332Z","iopub.execute_input":"2022-08-07T15:03:12.810885Z","iopub.status.idle":"2022-08-07T15:03:12.832946Z","shell.execute_reply.started":"2022-08-07T15:03:12.810841Z","shell.execute_reply":"2022-08-07T15:03:12.832018Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.distplot(combi['CryoSleep'])","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:12.834797Z","iopub.execute_input":"2022-08-07T15:03:12.835402Z","iopub.status.idle":"2022-08-07T15:03:13.145456Z","shell.execute_reply.started":"2022-08-07T15:03:12.835356Z","shell.execute_reply":"2022-08-07T15:03:13.144575Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sleep_count = combi['CryoSleep'].value_counts()\nsleep_count","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:13.146690Z","iopub.execute_input":"2022-08-07T15:03:13.147018Z","iopub.status.idle":"2022-08-07T15:03:13.156060Z","shell.execute_reply.started":"2022-08-07T15:03:13.146974Z","shell.execute_reply":"2022-08-07T15:03:13.155201Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sleep_percent = sleep_count / len(combi)\nsleep_percent","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:13.157497Z","iopub.execute_input":"2022-08-07T15:03:13.157787Z","iopub.status.idle":"2022-08-07T15:03:13.168066Z","shell.execute_reply.started":"2022-08-07T15:03:13.157748Z","shell.execute_reply":"2022-08-07T15:03:13.167364Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"combi['CryoSleep'] = combi['CryoSleep'].astype(int)\ncombi['CryoSleep']","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:13.169165Z","iopub.execute_input":"2022-08-07T15:03:13.169753Z","iopub.status.idle":"2022-08-07T15:03:13.181626Z","shell.execute_reply.started":"2022-08-07T15:03:13.169720Z","shell.execute_reply":"2022-08-07T15:03:13.181012Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Destination","metadata":{}},{"cell_type":"code","source":"sns.displot(combi['Destination'])","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:13.182714Z","iopub.execute_input":"2022-08-07T15:03:13.183333Z","iopub.status.idle":"2022-08-07T15:03:13.452432Z","shell.execute_reply.started":"2022-08-07T15:03:13.183294Z","shell.execute_reply":"2022-08-07T15:03:13.451556Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dest_count = combi['Destination'].value_counts()\ndest_count","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:13.456659Z","iopub.execute_input":"2022-08-07T15:03:13.456925Z","iopub.status.idle":"2022-08-07T15:03:13.464938Z","shell.execute_reply.started":"2022-08-07T15:03:13.456892Z","shell.execute_reply":"2022-08-07T15:03:13.464101Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dest_percent = dest_count / len(combi)\ndest_percent","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:13.466061Z","iopub.execute_input":"2022-08-07T15:03:13.466315Z","iopub.status.idle":"2022-08-07T15:03:13.477197Z","shell.execute_reply.started":"2022-08-07T15:03:13.466279Z","shell.execute_reply":"2022-08-07T15:03:13.476471Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mylabels = [\"TRAPPIST-1e\", \"55 Cancri e\", \"PSO J318.5-22\", \"not listed\"]\nplt.pie(dest_percent, labels=mylabels)\nplt.show() ","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:13.478287Z","iopub.execute_input":"2022-08-07T15:03:13.478524Z","iopub.status.idle":"2022-08-07T15:03:13.573046Z","shell.execute_reply.started":"2022-08-07T15:03:13.478486Z","shell.execute_reply":"2022-08-07T15:03:13.572124Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"combi['Destination'].replace({\"TRAPPIST-1e\": 1, \"55 Cancri e\": 2, \"PSO J318.5-22\": 3, \"not listed\": 4},inplace=True)\ncombi['Destination']","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:13.574318Z","iopub.execute_input":"2022-08-07T15:03:13.575107Z","iopub.status.idle":"2022-08-07T15:03:13.589511Z","shell.execute_reply.started":"2022-08-07T15:03:13.575065Z","shell.execute_reply":"2022-08-07T15:03:13.588590Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Age","metadata":{}},{"cell_type":"code","source":"combi['Age_group'] = pd.cut(x=combi['Age'], bins=[-1, 18, 40, 65, 100], labels=['child', 'young adult', 'middle age', 'pensioner'])\ncombi['Age_group']","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:13.592029Z","iopub.execute_input":"2022-08-07T15:03:13.593315Z","iopub.status.idle":"2022-08-07T15:03:13.605606Z","shell.execute_reply.started":"2022-08-07T15:03:13.593281Z","shell.execute_reply":"2022-08-07T15:03:13.604751Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.displot(combi['Age_group'])","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:13.606895Z","iopub.execute_input":"2022-08-07T15:03:13.607414Z","iopub.status.idle":"2022-08-07T15:03:13.820228Z","shell.execute_reply.started":"2022-08-07T15:03:13.607369Z","shell.execute_reply":"2022-08-07T15:03:13.819231Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"age_count = combi['Age_group'].value_counts()\nage_count","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:13.821740Z","iopub.execute_input":"2022-08-07T15:03:13.822254Z","iopub.status.idle":"2022-08-07T15:03:13.831388Z","shell.execute_reply.started":"2022-08-07T15:03:13.822207Z","shell.execute_reply":"2022-08-07T15:03:13.830535Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"age_percent = age_count / len(combi)\nage_percent","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:13.832956Z","iopub.execute_input":"2022-08-07T15:03:13.833456Z","iopub.status.idle":"2022-08-07T15:03:13.844507Z","shell.execute_reply.started":"2022-08-07T15:03:13.833413Z","shell.execute_reply":"2022-08-07T15:03:13.843733Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mylabels = [\"young adult\", \"child\", \"middle age\", \"pensioner\"]\nplt.pie(age_percent, labels=mylabels)\nplt.show() ","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:13.845829Z","iopub.execute_input":"2022-08-07T15:03:13.846284Z","iopub.status.idle":"2022-08-07T15:03:13.928031Z","shell.execute_reply.started":"2022-08-07T15:03:13.846241Z","shell.execute_reply":"2022-08-07T15:03:13.927060Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"combi['Age_group'].replace({\"young adult\": 1, \"child\": 2, \"middle age\": 3, \"pensioner\": 4},inplace=True)\ncombi['Age_group']","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:13.929510Z","iopub.execute_input":"2022-08-07T15:03:13.929892Z","iopub.status.idle":"2022-08-07T15:03:13.945399Z","shell.execute_reply.started":"2022-08-07T15:03:13.929849Z","shell.execute_reply":"2022-08-07T15:03:13.944022Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"combi['Age_group'] = combi['Age_group'].astype(int)","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:13.947042Z","iopub.execute_input":"2022-08-07T15:03:13.947543Z","iopub.status.idle":"2022-08-07T15:03:13.953437Z","shell.execute_reply.started":"2022-08-07T15:03:13.947498Z","shell.execute_reply":"2022-08-07T15:03:13.952783Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"VIP","metadata":{}},{"cell_type":"code","source":"combi['VIP'][combi['VIP'] == 'not listed'] = False","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:13.954804Z","iopub.execute_input":"2022-08-07T15:03:13.955318Z","iopub.status.idle":"2022-08-07T15:03:13.969685Z","shell.execute_reply.started":"2022-08-07T15:03:13.955273Z","shell.execute_reply":"2022-08-07T15:03:13.968781Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"combi['VIP'].replace({False: 0, True: 1})","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:13.971487Z","iopub.execute_input":"2022-08-07T15:03:13.972241Z","iopub.status.idle":"2022-08-07T15:03:13.984851Z","shell.execute_reply.started":"2022-08-07T15:03:13.972196Z","shell.execute_reply":"2022-08-07T15:03:13.983949Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.distplot(combi['VIP'])","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:13.988170Z","iopub.execute_input":"2022-08-07T15:03:13.988618Z","iopub.status.idle":"2022-08-07T15:03:14.338420Z","shell.execute_reply.started":"2022-08-07T15:03:13.988573Z","shell.execute_reply":"2022-08-07T15:03:14.336881Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"vip_count = combi['VIP'].value_counts()\nvip_count","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:14.340032Z","iopub.execute_input":"2022-08-07T15:03:14.340332Z","iopub.status.idle":"2022-08-07T15:03:14.349081Z","shell.execute_reply.started":"2022-08-07T15:03:14.340291Z","shell.execute_reply":"2022-08-07T15:03:14.348198Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"vip_percent = vip_count / len(combi)\nvip_percent","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:14.350366Z","iopub.execute_input":"2022-08-07T15:03:14.350576Z","iopub.status.idle":"2022-08-07T15:03:14.358848Z","shell.execute_reply.started":"2022-08-07T15:03:14.350548Z","shell.execute_reply":"2022-08-07T15:03:14.357973Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"combi['VIP'] = combi['VIP'].astype(int)\ncombi['VIP']","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:14.360010Z","iopub.execute_input":"2022-08-07T15:03:14.360724Z","iopub.status.idle":"2022-08-07T15:03:14.371781Z","shell.execute_reply.started":"2022-08-07T15:03:14.360680Z","shell.execute_reply":"2022-08-07T15:03:14.370936Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Room Service","metadata":{}},{"cell_type":"code","source":"sns.violinplot(combi['RoomService'])","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:14.373194Z","iopub.execute_input":"2022-08-07T15:03:14.373557Z","iopub.status.idle":"2022-08-07T15:03:14.597935Z","shell.execute_reply.started":"2022-08-07T15:03:14.373516Z","shell.execute_reply":"2022-08-07T15:03:14.597292Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rm_service_high = combi['RoomService'].max()\nprint(rm_service_high)","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:14.599106Z","iopub.execute_input":"2022-08-07T15:03:14.599340Z","iopub.status.idle":"2022-08-07T15:03:14.604908Z","shell.execute_reply.started":"2022-08-07T15:03:14.599310Z","shell.execute_reply":"2022-08-07T15:03:14.604276Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"combi['Room_Service_group'] = pd.cut(x=combi['RoomService'], bins=[-1, 2000, 8000, 15000], labels=['low', 'med', 'high'])\ncombi['Room_Service_group']\n","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:14.605967Z","iopub.execute_input":"2022-08-07T15:03:14.606306Z","iopub.status.idle":"2022-08-07T15:03:14.621408Z","shell.execute_reply.started":"2022-08-07T15:03:14.606276Z","shell.execute_reply":"2022-08-07T15:03:14.620840Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.displot(combi['Room_Service_group'])","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:14.622559Z","iopub.execute_input":"2022-08-07T15:03:14.622970Z","iopub.status.idle":"2022-08-07T15:03:14.875639Z","shell.execute_reply.started":"2022-08-07T15:03:14.622939Z","shell.execute_reply":"2022-08-07T15:03:14.874823Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rm_service_count = combi['Room_Service_group'].value_counts()\nrm_service_count","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:14.880031Z","iopub.execute_input":"2022-08-07T15:03:14.880269Z","iopub.status.idle":"2022-08-07T15:03:14.889663Z","shell.execute_reply.started":"2022-08-07T15:03:14.880238Z","shell.execute_reply":"2022-08-07T15:03:14.888718Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rm_service_percent = rm_service_count / len(combi)\nrm_service_percent","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:14.890879Z","iopub.execute_input":"2022-08-07T15:03:14.891644Z","iopub.status.idle":"2022-08-07T15:03:14.898898Z","shell.execute_reply.started":"2022-08-07T15:03:14.891608Z","shell.execute_reply":"2022-08-07T15:03:14.897943Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mylabels = [\"low\", \"med\", \"high\"]\nplt.pie(rm_service_percent, labels=mylabels)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:14.900181Z","iopub.execute_input":"2022-08-07T15:03:14.900887Z","iopub.status.idle":"2022-08-07T15:03:14.989028Z","shell.execute_reply.started":"2022-08-07T15:03:14.900844Z","shell.execute_reply":"2022-08-07T15:03:14.988173Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"combi['Room_Service_group'].replace({\"low\": 1, \"med\": 2, \"high\": 3},inplace=True)\ncombi['Room_Service_group']","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:14.990547Z","iopub.execute_input":"2022-08-07T15:03:14.991038Z","iopub.status.idle":"2022-08-07T15:03:15.008375Z","shell.execute_reply.started":"2022-08-07T15:03:14.990995Z","shell.execute_reply":"2022-08-07T15:03:15.007535Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Food Court","metadata":{}},{"cell_type":"code","source":"sns.violinplot(combi['FoodCourt'])","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:15.009871Z","iopub.execute_input":"2022-08-07T15:03:15.010339Z","iopub.status.idle":"2022-08-07T15:03:15.230298Z","shell.execute_reply.started":"2022-08-07T15:03:15.010298Z","shell.execute_reply":"2022-08-07T15:03:15.229536Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"food_high = combi['FoodCourt'].max()\nprint(food_high)","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:15.231552Z","iopub.execute_input":"2022-08-07T15:03:15.231763Z","iopub.status.idle":"2022-08-07T15:03:15.236417Z","shell.execute_reply.started":"2022-08-07T15:03:15.231735Z","shell.execute_reply":"2022-08-07T15:03:15.235638Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"combi['Food_Court_group'] = pd.cut(x=combi['FoodCourt'], bins=[-1, 5000, 20000, 30000], labels=['low', 'med', 'high'])\ncombi['Food_Court_group']","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:15.237685Z","iopub.execute_input":"2022-08-07T15:03:15.237915Z","iopub.status.idle":"2022-08-07T15:03:15.253744Z","shell.execute_reply.started":"2022-08-07T15:03:15.237880Z","shell.execute_reply":"2022-08-07T15:03:15.253070Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.displot(combi['Food_Court_group'])","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:15.254968Z","iopub.execute_input":"2022-08-07T15:03:15.255350Z","iopub.status.idle":"2022-08-07T15:03:15.499462Z","shell.execute_reply.started":"2022-08-07T15:03:15.255315Z","shell.execute_reply":"2022-08-07T15:03:15.498867Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fd_court_count = combi['Food_Court_group'].value_counts()\nfd_court_count","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:15.500553Z","iopub.execute_input":"2022-08-07T15:03:15.500889Z","iopub.status.idle":"2022-08-07T15:03:15.507892Z","shell.execute_reply.started":"2022-08-07T15:03:15.500859Z","shell.execute_reply":"2022-08-07T15:03:15.507154Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fd_court_percent = fd_court_count / len(combi)\nfd_court_percent","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:15.509471Z","iopub.execute_input":"2022-08-07T15:03:15.510004Z","iopub.status.idle":"2022-08-07T15:03:15.520727Z","shell.execute_reply.started":"2022-08-07T15:03:15.509962Z","shell.execute_reply":"2022-08-07T15:03:15.520021Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mylabels = [\"low\", \"med\", \"high\"]\nplt.pie(fd_court_percent, labels=mylabels)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:15.521970Z","iopub.execute_input":"2022-08-07T15:03:15.522312Z","iopub.status.idle":"2022-08-07T15:03:15.610953Z","shell.execute_reply.started":"2022-08-07T15:03:15.522281Z","shell.execute_reply":"2022-08-07T15:03:15.610232Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"combi['Food_Court_group'].replace({\"low\": 1, \"med\": 2, \"high\": 3},inplace=True)\ncombi['Food_Court_group']","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:15.614075Z","iopub.execute_input":"2022-08-07T15:03:15.614920Z","iopub.status.idle":"2022-08-07T15:03:15.627322Z","shell.execute_reply.started":"2022-08-07T15:03:15.614873Z","shell.execute_reply":"2022-08-07T15:03:15.626655Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Shopping Mall","metadata":{}},{"cell_type":"code","source":"sns.violinplot(combi['ShoppingMall'])","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:15.628429Z","iopub.execute_input":"2022-08-07T15:03:15.629130Z","iopub.status.idle":"2022-08-07T15:03:15.828776Z","shell.execute_reply.started":"2022-08-07T15:03:15.629086Z","shell.execute_reply":"2022-08-07T15:03:15.828054Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"shop_high = combi['ShoppingMall'].max()\nprint(shop_high)","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:15.830230Z","iopub.execute_input":"2022-08-07T15:03:15.830711Z","iopub.status.idle":"2022-08-07T15:03:15.836862Z","shell.execute_reply.started":"2022-08-07T15:03:15.830667Z","shell.execute_reply":"2022-08-07T15:03:15.836008Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"combi['Shopping_group'] = pd.cut(x=combi['ShoppingMall'], bins=[-1, 2000, 15000, 24000], labels=['low', 'med', 'high'])\ncombi['Shopping_group']","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:15.838269Z","iopub.execute_input":"2022-08-07T15:03:15.838731Z","iopub.status.idle":"2022-08-07T15:03:15.853087Z","shell.execute_reply.started":"2022-08-07T15:03:15.838690Z","shell.execute_reply":"2022-08-07T15:03:15.852147Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.displot(combi['Shopping_group'])","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:15.854514Z","iopub.execute_input":"2022-08-07T15:03:15.855072Z","iopub.status.idle":"2022-08-07T15:03:16.048162Z","shell.execute_reply.started":"2022-08-07T15:03:15.855029Z","shell.execute_reply":"2022-08-07T15:03:16.047344Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"shopping_count = combi['Shopping_group'].value_counts()\nshopping_count","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:16.050037Z","iopub.execute_input":"2022-08-07T15:03:16.050337Z","iopub.status.idle":"2022-08-07T15:03:16.060112Z","shell.execute_reply.started":"2022-08-07T15:03:16.050287Z","shell.execute_reply":"2022-08-07T15:03:16.059319Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"shopping_percent = shopping_count / len(combi)\nshopping_percent","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:16.061306Z","iopub.execute_input":"2022-08-07T15:03:16.061550Z","iopub.status.idle":"2022-08-07T15:03:16.071747Z","shell.execute_reply.started":"2022-08-07T15:03:16.061513Z","shell.execute_reply":"2022-08-07T15:03:16.071055Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mylabels = [\"low\", \"med\", \"high\"]\nplt.pie(shopping_percent, labels=mylabels)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:16.072878Z","iopub.execute_input":"2022-08-07T15:03:16.073343Z","iopub.status.idle":"2022-08-07T15:03:16.155480Z","shell.execute_reply.started":"2022-08-07T15:03:16.073311Z","shell.execute_reply":"2022-08-07T15:03:16.154796Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"combi['Shopping_group'].replace({\"low\": 1, \"med\": 2, \"high\": 3},inplace=True)\ncombi['Shopping_group']","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:16.156641Z","iopub.execute_input":"2022-08-07T15:03:16.157296Z","iopub.status.idle":"2022-08-07T15:03:16.170331Z","shell.execute_reply.started":"2022-08-07T15:03:16.157250Z","shell.execute_reply":"2022-08-07T15:03:16.169557Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Spa","metadata":{}},{"cell_type":"code","source":"sns.violinplot(combi['Spa'])","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:16.171492Z","iopub.execute_input":"2022-08-07T15:03:16.172329Z","iopub.status.idle":"2022-08-07T15:03:16.365837Z","shell.execute_reply.started":"2022-08-07T15:03:16.172283Z","shell.execute_reply":"2022-08-07T15:03:16.365202Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"spa_high = combi['Spa'].max()\nprint(spa_high)","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:16.367049Z","iopub.execute_input":"2022-08-07T15:03:16.367931Z","iopub.status.idle":"2022-08-07T15:03:16.373550Z","shell.execute_reply.started":"2022-08-07T15:03:16.367887Z","shell.execute_reply":"2022-08-07T15:03:16.372682Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"combi['Spa_group'] = pd.cut(x=combi['Spa'], bins=[-1, 5000, 15000, 23000], labels=['low', 'med', 'high'])\ncombi['Spa_group']","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:16.374744Z","iopub.execute_input":"2022-08-07T15:03:16.375254Z","iopub.status.idle":"2022-08-07T15:03:16.389368Z","shell.execute_reply.started":"2022-08-07T15:03:16.375212Z","shell.execute_reply":"2022-08-07T15:03:16.388551Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.displot(combi['Spa_group'])","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:16.390631Z","iopub.execute_input":"2022-08-07T15:03:16.390956Z","iopub.status.idle":"2022-08-07T15:03:16.608879Z","shell.execute_reply.started":"2022-08-07T15:03:16.390926Z","shell.execute_reply":"2022-08-07T15:03:16.608274Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"spa_count = combi['Spa_group'].value_counts()\nspa_count","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:16.609959Z","iopub.execute_input":"2022-08-07T15:03:16.610338Z","iopub.status.idle":"2022-08-07T15:03:16.618464Z","shell.execute_reply.started":"2022-08-07T15:03:16.610293Z","shell.execute_reply":"2022-08-07T15:03:16.617611Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"spa_percent = spa_count / len(combi)\nspa_percent","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:16.619510Z","iopub.execute_input":"2022-08-07T15:03:16.620287Z","iopub.status.idle":"2022-08-07T15:03:16.628736Z","shell.execute_reply.started":"2022-08-07T15:03:16.620244Z","shell.execute_reply":"2022-08-07T15:03:16.628139Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mylabels = [\"low\", \"med\", \"high\"]\nplt.pie(spa_percent, labels=mylabels)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:16.633237Z","iopub.execute_input":"2022-08-07T15:03:16.633688Z","iopub.status.idle":"2022-08-07T15:03:16.722204Z","shell.execute_reply.started":"2022-08-07T15:03:16.633656Z","shell.execute_reply":"2022-08-07T15:03:16.721252Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"combi['Spa_group'].replace({\"low\": 1, \"med\": 2, \"high\": 3},inplace=True)\ncombi['Spa_group']","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:16.724003Z","iopub.execute_input":"2022-08-07T15:03:16.724313Z","iopub.status.idle":"2022-08-07T15:03:16.742968Z","shell.execute_reply.started":"2022-08-07T15:03:16.724271Z","shell.execute_reply":"2022-08-07T15:03:16.742042Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"VR Deck","metadata":{}},{"cell_type":"code","source":"sns.violinplot(combi['VRDeck'])","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:16.746707Z","iopub.execute_input":"2022-08-07T15:03:16.747595Z","iopub.status.idle":"2022-08-07T15:03:16.938020Z","shell.execute_reply.started":"2022-08-07T15:03:16.747548Z","shell.execute_reply":"2022-08-07T15:03:16.936961Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"vr_high = combi['VRDeck'].max()\nprint(vr_high)","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:16.939499Z","iopub.execute_input":"2022-08-07T15:03:16.940033Z","iopub.status.idle":"2022-08-07T15:03:16.946829Z","shell.execute_reply.started":"2022-08-07T15:03:16.939987Z","shell.execute_reply":"2022-08-07T15:03:16.945762Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"combi['VR_group'] = pd.cut(x=combi['VRDeck'], bins=[-1, 5000, 15000, 23000], labels=['low', 'med', 'high'])\ncombi['VR_group']","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:16.948553Z","iopub.execute_input":"2022-08-07T15:03:16.948875Z","iopub.status.idle":"2022-08-07T15:03:16.963969Z","shell.execute_reply.started":"2022-08-07T15:03:16.948835Z","shell.execute_reply":"2022-08-07T15:03:16.962906Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.displot(combi['VR_group'])","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:16.965174Z","iopub.execute_input":"2022-08-07T15:03:16.965419Z","iopub.status.idle":"2022-08-07T15:03:17.212737Z","shell.execute_reply.started":"2022-08-07T15:03:16.965380Z","shell.execute_reply":"2022-08-07T15:03:17.211840Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"vr_count = combi['VR_group'].value_counts()\nvr_count","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:17.213737Z","iopub.execute_input":"2022-08-07T15:03:17.213973Z","iopub.status.idle":"2022-08-07T15:03:17.223266Z","shell.execute_reply.started":"2022-08-07T15:03:17.213944Z","shell.execute_reply":"2022-08-07T15:03:17.222359Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"vr_percent = vr_count / len(combi)\nvr_percent","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:17.224634Z","iopub.execute_input":"2022-08-07T15:03:17.224972Z","iopub.status.idle":"2022-08-07T15:03:17.230899Z","shell.execute_reply.started":"2022-08-07T15:03:17.224941Z","shell.execute_reply":"2022-08-07T15:03:17.230317Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mylabels = [\"low\", \"med\", \"high\"]\nplt.pie(vr_percent, labels=mylabels)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:17.231922Z","iopub.execute_input":"2022-08-07T15:03:17.232124Z","iopub.status.idle":"2022-08-07T15:03:17.322921Z","shell.execute_reply.started":"2022-08-07T15:03:17.232097Z","shell.execute_reply":"2022-08-07T15:03:17.322065Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"combi['VR_group'].replace({\"low\": 1, \"med\": 2, \"high\": 3},inplace=True)\ncombi['VR_group']","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:17.324443Z","iopub.execute_input":"2022-08-07T15:03:17.324932Z","iopub.status.idle":"2022-08-07T15:03:17.341514Z","shell.execute_reply.started":"2022-08-07T15:03:17.324890Z","shell.execute_reply":"2022-08-07T15:03:17.340697Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Assign features","metadata":{}},{"cell_type":"code","source":"combi.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:17.342982Z","iopub.execute_input":"2022-08-07T15:03:17.343446Z","iopub.status.idle":"2022-08-07T15:03:17.354636Z","shell.execute_reply.started":"2022-08-07T15:03:17.343405Z","shell.execute_reply":"2022-08-07T15:03:17.353849Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"combi.info()","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:17.356110Z","iopub.execute_input":"2022-08-07T15:03:17.356596Z","iopub.status.idle":"2022-08-07T15:03:17.373684Z","shell.execute_reply.started":"2022-08-07T15:03:17.356556Z","shell.execute_reply":"2022-08-07T15:03:17.372863Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Heatmap","metadata":{}},{"cell_type":"code","source":"corr = combi.corr()\nsns.heatmap(corr)","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:17.375356Z","iopub.execute_input":"2022-08-07T15:03:17.375764Z","iopub.status.idle":"2022-08-07T15:03:17.840723Z","shell.execute_reply.started":"2022-08-07T15:03:17.375723Z","shell.execute_reply":"2022-08-07T15:03:17.840133Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Delete columns that have a high correlation","metadata":{}},{"cell_type":"code","source":"columns = np.full((corr.shape[0],), True, dtype=bool)\nfor i in range(corr.shape[0]):\n    for j in range(i+1, corr.shape[0]):\n        if corr.iloc[i,j] >= 0.9:\n            if columns[j]:\n                columns[j] = False\nselected_columns = combi.columns[columns]\ncombi = combi[selected_columns]\ncombi","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:17.841691Z","iopub.execute_input":"2022-08-07T15:03:17.842363Z","iopub.status.idle":"2022-08-07T15:03:17.875027Z","shell.execute_reply.started":"2022-08-07T15:03:17.842321Z","shell.execute_reply":"2022-08-07T15:03:17.874363Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"combi.info()","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:17.875964Z","iopub.execute_input":"2022-08-07T15:03:17.876562Z","iopub.status.idle":"2022-08-07T15:03:17.890337Z","shell.execute_reply.started":"2022-08-07T15:03:17.876528Z","shell.execute_reply":"2022-08-07T15:03:17.889574Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Define X and y","metadata":{}},{"cell_type":"code","source":"y = target\nX = combi[: len(train1)]\nX_test = combi[len(train1) :]","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:17.891653Z","iopub.execute_input":"2022-08-07T15:03:17.892024Z","iopub.status.idle":"2022-08-07T15:03:17.896140Z","shell.execute_reply.started":"2022-08-07T15:03:17.891990Z","shell.execute_reply":"2022-08-07T15:03:17.895130Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Split dataset for training and validating","metadata":{}},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\n\nX_train, X_val, y_train, y_val = train_test_split(X, y, test_size=0.10, random_state=42, stratify=y, shuffle=True)\nX_train.shape, X_val.shape, y_train.shape, y_val.shape, X_test.shape","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:17.897136Z","iopub.execute_input":"2022-08-07T15:03:17.897730Z","iopub.status.idle":"2022-08-07T15:03:17.914480Z","shell.execute_reply.started":"2022-08-07T15:03:17.897697Z","shell.execute_reply":"2022-08-07T15:03:17.913544Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Select model","metadata":{}},{"cell_type":"code","source":"from sklearn.linear_model import LogisticRegression\n\nmodel = LogisticRegression(random_state=42, C=10, class_weight='balanced', solver='liblinear').fit(X_train, y_train)\nprint(model.score(X_train, y_train))","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:17.915702Z","iopub.execute_input":"2022-08-07T15:03:17.916262Z","iopub.status.idle":"2022-08-07T15:03:18.052706Z","shell.execute_reply.started":"2022-08-07T15:03:17.916218Z","shell.execute_reply":"2022-08-07T15:03:18.051167Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Predict validation","metadata":{}},{"cell_type":"code","source":"y_pred = model.predict(X_val)\nprint(model.score(X_val, y_val))","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:18.054703Z","iopub.execute_input":"2022-08-07T15:03:18.056223Z","iopub.status.idle":"2022-08-07T15:03:18.077877Z","shell.execute_reply.started":"2022-08-07T15:03:18.056178Z","shell.execute_reply":"2022-08-07T15:03:18.077024Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Confusion matrix","metadata":{}},{"cell_type":"code","source":"from sklearn.metrics import confusion_matrix\n\nprint(confusion_matrix(y_val, y_pred))","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:18.082494Z","iopub.execute_input":"2022-08-07T15:03:18.085275Z","iopub.status.idle":"2022-08-07T15:03:18.103077Z","shell.execute_reply.started":"2022-08-07T15:03:18.085223Z","shell.execute_reply":"2022-08-07T15:03:18.101880Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Predict on X_test","metadata":{}},{"cell_type":"code","source":"predictions = model.predict(X_test)\npredictions = predictions.astype(str)\npredictions = np.char.replace(predictions, '0', 'False')\npredictions = np.char.replace(predictions, '1', 'True')\npredictions","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:18.107794Z","iopub.execute_input":"2022-08-07T15:03:18.110693Z","iopub.status.idle":"2022-08-07T15:03:18.171981Z","shell.execute_reply.started":"2022-08-07T15:03:18.110640Z","shell.execute_reply":"2022-08-07T15:03:18.171085Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Prepare and submit","metadata":{}},{"cell_type":"code","source":"submission['Transported'] = predictions\nsubmission.to_csv('submission.csv', index=False)\nsubmission = pd.read_csv(\"submission.csv\")\nsubmission","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:03:18.178979Z","iopub.execute_input":"2022-08-07T15:03:18.181282Z","iopub.status.idle":"2022-08-07T15:03:18.225616Z","shell.execute_reply.started":"2022-08-07T15:03:18.181236Z","shell.execute_reply":"2022-08-07T15:03:18.224741Z"},"trusted":true},"execution_count":null,"outputs":[]}]}