{"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-07T16:10:08.730778Z","iopub.execute_input":"2022-08-07T16:10:08.731301Z","iopub.status.idle":"2022-08-07T16:10:08.735271Z","shell.execute_reply.started":"2022-08-07T16:10:08.731266Z","shell.execute_reply":"2022-08-07T16:10:08.734715Z"},"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-07T16:10:08.812538Z","iopub.execute_input":"2022-08-07T16:10:08.813064Z","iopub.status.idle":"2022-08-07T16:10:08.821504Z","shell.execute_reply.started":"2022-08-07T16:10:08.813029Z","shell.execute_reply":"2022-08-07T16:10:08.820879Z"},"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-07T16:10:08.847305Z","iopub.execute_input":"2022-08-07T16:10:08.847915Z","iopub.status.idle":"2022-08-07T16:10:08.902765Z","shell.execute_reply.started":"2022-08-07T16:10:08.847878Z","shell.execute_reply":"2022-08-07T16:10:08.901851Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train","metadata":{"execution":{"iopub.status.busy":"2022-08-07T16:10:08.922734Z","iopub.execute_input":"2022-08-07T16:10:08.923046Z","iopub.status.idle":"2022-08-07T16:10:08.952753Z","shell.execute_reply.started":"2022-08-07T16:10:08.923011Z","shell.execute_reply":"2022-08-07T16:10:08.951871Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test","metadata":{"execution":{"iopub.status.busy":"2022-08-07T16:10:08.997232Z","iopub.execute_input":"2022-08-07T16:10:08.998038Z","iopub.status.idle":"2022-08-07T16:10:09.026382Z","shell.execute_reply.started":"2022-08-07T16:10:08.998000Z","shell.execute_reply":"2022-08-07T16:10:09.025581Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission","metadata":{"execution":{"iopub.status.busy":"2022-08-07T16:10:09.062673Z","iopub.execute_input":"2022-08-07T16:10:09.062947Z","iopub.status.idle":"2022-08-07T16:10:09.075857Z","shell.execute_reply.started":"2022-08-07T16:10:09.062919Z","shell.execute_reply":"2022-08-07T16:10:09.074896Z"},"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-07T16:10:09.111893Z","iopub.execute_input":"2022-08-07T16:10:09.112200Z","iopub.status.idle":"2022-08-07T16:10:09.124916Z","shell.execute_reply.started":"2022-08-07T16:10:09.112163Z","shell.execute_reply":"2022-08-07T16:10:09.124021Z"},"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-07T16:10:09.177611Z","iopub.execute_input":"2022-08-07T16:10:09.177907Z","iopub.status.idle":"2022-08-07T16:10:09.213052Z","shell.execute_reply.started":"2022-08-07T16:10:09.177871Z","shell.execute_reply":"2022-08-07T16:10:09.212484Z"},"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-07T16:10:09.247186Z","iopub.execute_input":"2022-08-07T16:10:09.247870Z","iopub.status.idle":"2022-08-07T16:10:09.278853Z","shell.execute_reply.started":"2022-08-07T16:10:09.247835Z","shell.execute_reply":"2022-08-07T16:10:09.278095Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test","metadata":{"execution":{"iopub.status.busy":"2022-08-07T16:10:09.317687Z","iopub.execute_input":"2022-08-07T16:10:09.318147Z","iopub.status.idle":"2022-08-07T16:10:09.346347Z","shell.execute_reply.started":"2022-08-07T16:10:09.318111Z","shell.execute_reply":"2022-08-07T16:10:09.345751Z"},"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-07T16:10:09.362334Z","iopub.execute_input":"2022-08-07T16:10:09.363138Z","iopub.status.idle":"2022-08-07T16:10:09.375552Z","shell.execute_reply.started":"2022-08-07T16:10:09.363098Z","shell.execute_reply":"2022-08-07T16:10:09.374664Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.displot(train1['Transported'])","metadata":{"execution":{"iopub.status.busy":"2022-08-07T16:10:09.424214Z","iopub.execute_input":"2022-08-07T16:10:09.425153Z","iopub.status.idle":"2022-08-07T16:10:09.701758Z","shell.execute_reply.started":"2022-08-07T16:10:09.425111Z","shell.execute_reply":"2022-08-07T16:10:09.700697Z"},"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-07T16:10:09.703472Z","iopub.execute_input":"2022-08-07T16:10:09.703745Z","iopub.status.idle":"2022-08-07T16:10:09.711910Z","shell.execute_reply.started":"2022-08-07T16:10:09.703696Z","shell.execute_reply":"2022-08-07T16:10:09.711060Z"},"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-07T16:10:09.713229Z","iopub.execute_input":"2022-08-07T16:10:09.713533Z","iopub.status.idle":"2022-08-07T16:10:09.728271Z","shell.execute_reply.started":"2022-08-07T16:10:09.713503Z","shell.execute_reply":"2022-08-07T16:10:09.727264Z"},"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-07T16:10:09.730021Z","iopub.execute_input":"2022-08-07T16:10:09.730252Z","iopub.status.idle":"2022-08-07T16:10:10.230986Z","shell.execute_reply.started":"2022-08-07T16:10:09.730222Z","shell.execute_reply":"2022-08-07T16:10:10.230141Z"},"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-07T16:10:10.232921Z","iopub.execute_input":"2022-08-07T16:10:10.233287Z","iopub.status.idle":"2022-08-07T16:10:10.264231Z","shell.execute_reply.started":"2022-08-07T16:10:10.233245Z","shell.execute_reply":"2022-08-07T16:10:10.263387Z"},"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-07T16:10:10.265445Z","iopub.execute_input":"2022-08-07T16:10:10.265736Z","iopub.status.idle":"2022-08-07T16:10:10.292451Z","shell.execute_reply.started":"2022-08-07T16:10:10.265694Z","shell.execute_reply":"2022-08-07T16:10:10.291608Z"},"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-07T16:10:10.294900Z","iopub.execute_input":"2022-08-07T16:10:10.295142Z","iopub.status.idle":"2022-08-07T16:10:10.311253Z","shell.execute_reply.started":"2022-08-07T16:10:10.295113Z","shell.execute_reply":"2022-08-07T16:10:10.310410Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"combi.describe()","metadata":{"execution":{"iopub.status.busy":"2022-08-07T16:10:10.313277Z","iopub.execute_input":"2022-08-07T16:10:10.313698Z","iopub.status.idle":"2022-08-07T16:10:10.345771Z","shell.execute_reply.started":"2022-08-07T16:10:10.313656Z","shell.execute_reply":"2022-08-07T16:10:10.345186Z"},"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-07T16:10:10.347068Z","iopub.execute_input":"2022-08-07T16:10:10.347722Z","iopub.status.idle":"2022-08-07T16:10:10.357918Z","shell.execute_reply.started":"2022-08-07T16:10:10.347690Z","shell.execute_reply":"2022-08-07T16:10:10.357236Z"},"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-07T16:10:10.358965Z","iopub.execute_input":"2022-08-07T16:10:10.359160Z","iopub.status.idle":"2022-08-07T16:10:10.403203Z","shell.execute_reply.started":"2022-08-07T16:10:10.359135Z","shell.execute_reply":"2022-08-07T16:10:10.402328Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"combi.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-08-07T16:10:10.404406Z","iopub.execute_input":"2022-08-07T16:10:10.404647Z","iopub.status.idle":"2022-08-07T16:10:10.414727Z","shell.execute_reply.started":"2022-08-07T16:10:10.404618Z","shell.execute_reply":"2022-08-07T16:10:10.413771Z"},"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-07T16:10:10.416626Z","iopub.execute_input":"2022-08-07T16:10:10.416863Z","iopub.status.idle":"2022-08-07T16:10:10.723557Z","shell.execute_reply.started":"2022-08-07T16:10:10.416834Z","shell.execute_reply":"2022-08-07T16:10:10.722925Z"},"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-07T16:10:10.725636Z","iopub.execute_input":"2022-08-07T16:10:10.727392Z","iopub.status.idle":"2022-08-07T16:10:10.736029Z","shell.execute_reply.started":"2022-08-07T16:10:10.727337Z","shell.execute_reply":"2022-08-07T16:10:10.735490Z"},"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-07T16:10:10.737127Z","iopub.execute_input":"2022-08-07T16:10:10.737494Z","iopub.status.idle":"2022-08-07T16:10:10.751666Z","shell.execute_reply.started":"2022-08-07T16:10:10.737462Z","shell.execute_reply":"2022-08-07T16:10:10.750788Z"},"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-07T16:10:10.754395Z","iopub.execute_input":"2022-08-07T16:10:10.755108Z","iopub.status.idle":"2022-08-07T16:10:10.856219Z","shell.execute_reply.started":"2022-08-07T16:10:10.755073Z","shell.execute_reply":"2022-08-07T16:10:10.855078Z"},"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-07T16:10:10.858158Z","iopub.execute_input":"2022-08-07T16:10:10.859394Z","iopub.status.idle":"2022-08-07T16:10:10.888321Z","shell.execute_reply.started":"2022-08-07T16:10:10.859315Z","shell.execute_reply":"2022-08-07T16:10:10.887337Z"},"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-07T16:10:10.890017Z","iopub.execute_input":"2022-08-07T16:10:10.891129Z","iopub.status.idle":"2022-08-07T16:10:10.905287Z","shell.execute_reply.started":"2022-08-07T16:10:10.891069Z","shell.execute_reply":"2022-08-07T16:10:10.904270Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(combi.iloc[6674])","metadata":{"execution":{"iopub.status.busy":"2022-08-07T16:10:10.907623Z","iopub.execute_input":"2022-08-07T16:10:10.908397Z","iopub.status.idle":"2022-08-07T16:10:10.921541Z","shell.execute_reply.started":"2022-08-07T16:10:10.908325Z","shell.execute_reply":"2022-08-07T16:10:10.920376Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"combi['CryoSleep'].replace({False: 0, True: 1})","metadata":{"execution":{"iopub.status.busy":"2022-08-07T16:10:10.923872Z","iopub.execute_input":"2022-08-07T16:10:10.924608Z","iopub.status.idle":"2022-08-07T16:10:10.945494Z","shell.execute_reply.started":"2022-08-07T16:10:10.924551Z","shell.execute_reply":"2022-08-07T16:10:10.944582Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.distplot(combi['CryoSleep'])","metadata":{"execution":{"iopub.status.busy":"2022-08-07T16:10:10.946850Z","iopub.execute_input":"2022-08-07T16:10:10.947240Z","iopub.status.idle":"2022-08-07T16:10:11.537418Z","shell.execute_reply.started":"2022-08-07T16:10:10.947189Z","shell.execute_reply":"2022-08-07T16:10:11.536410Z"},"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-07T16:10:11.538884Z","iopub.execute_input":"2022-08-07T16:10:11.539291Z","iopub.status.idle":"2022-08-07T16:10:11.548404Z","shell.execute_reply.started":"2022-08-07T16:10:11.539245Z","shell.execute_reply":"2022-08-07T16:10:11.547573Z"},"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-07T16:10:11.549980Z","iopub.execute_input":"2022-08-07T16:10:11.550217Z","iopub.status.idle":"2022-08-07T16:10:11.563576Z","shell.execute_reply.started":"2022-08-07T16:10:11.550185Z","shell.execute_reply":"2022-08-07T16:10:11.562862Z"},"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-07T16:10:11.566310Z","iopub.execute_input":"2022-08-07T16:10:11.566589Z","iopub.status.idle":"2022-08-07T16:10:11.579623Z","shell.execute_reply.started":"2022-08-07T16:10:11.566560Z","shell.execute_reply":"2022-08-07T16:10:11.578671Z"},"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-07T16:10:11.581291Z","iopub.execute_input":"2022-08-07T16:10:11.581625Z","iopub.status.idle":"2022-08-07T16:10:11.891674Z","shell.execute_reply.started":"2022-08-07T16:10:11.581583Z","shell.execute_reply":"2022-08-07T16:10:11.890946Z"},"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-07T16:10:11.892776Z","iopub.execute_input":"2022-08-07T16:10:11.893016Z","iopub.status.idle":"2022-08-07T16:10:11.900115Z","shell.execute_reply.started":"2022-08-07T16:10:11.892987Z","shell.execute_reply":"2022-08-07T16:10:11.899573Z"},"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-07T16:10:11.901071Z","iopub.execute_input":"2022-08-07T16:10:11.901404Z","iopub.status.idle":"2022-08-07T16:10:11.916128Z","shell.execute_reply.started":"2022-08-07T16:10:11.901361Z","shell.execute_reply":"2022-08-07T16:10:11.915439Z"},"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-07T16:10:11.917091Z","iopub.execute_input":"2022-08-07T16:10:11.917563Z","iopub.status.idle":"2022-08-07T16:10:12.026256Z","shell.execute_reply.started":"2022-08-07T16:10:11.917532Z","shell.execute_reply":"2022-08-07T16:10:12.025133Z"},"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-07T16:10:12.028071Z","iopub.execute_input":"2022-08-07T16:10:12.028812Z","iopub.status.idle":"2022-08-07T16:10:12.061133Z","shell.execute_reply.started":"2022-08-07T16:10:12.028749Z","shell.execute_reply":"2022-08-07T16:10:12.060017Z"},"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-07T16:10:12.063134Z","iopub.execute_input":"2022-08-07T16:10:12.064067Z","iopub.status.idle":"2022-08-07T16:10:12.086022Z","shell.execute_reply.started":"2022-08-07T16:10:12.064004Z","shell.execute_reply":"2022-08-07T16:10:12.085045Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.displot(combi['Age_group'])","metadata":{"execution":{"iopub.status.busy":"2022-08-07T16:10:12.087665Z","iopub.execute_input":"2022-08-07T16:10:12.088568Z","iopub.status.idle":"2022-08-07T16:10:12.308420Z","shell.execute_reply.started":"2022-08-07T16:10:12.088524Z","shell.execute_reply":"2022-08-07T16:10:12.307439Z"},"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-07T16:10:12.310149Z","iopub.execute_input":"2022-08-07T16:10:12.310489Z","iopub.status.idle":"2022-08-07T16:10:12.321879Z","shell.execute_reply.started":"2022-08-07T16:10:12.310444Z","shell.execute_reply":"2022-08-07T16:10:12.321024Z"},"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-07T16:10:12.323022Z","iopub.execute_input":"2022-08-07T16:10:12.323264Z","iopub.status.idle":"2022-08-07T16:10:12.334192Z","shell.execute_reply.started":"2022-08-07T16:10:12.323235Z","shell.execute_reply":"2022-08-07T16:10:12.333406Z"},"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-07T16:10:12.335347Z","iopub.execute_input":"2022-08-07T16:10:12.335612Z","iopub.status.idle":"2022-08-07T16:10:12.424140Z","shell.execute_reply.started":"2022-08-07T16:10:12.335583Z","shell.execute_reply":"2022-08-07T16:10:12.423324Z"},"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-07T16:10:12.425656Z","iopub.execute_input":"2022-08-07T16:10:12.426134Z","iopub.status.idle":"2022-08-07T16:10:12.439716Z","shell.execute_reply.started":"2022-08-07T16:10:12.426090Z","shell.execute_reply":"2022-08-07T16:10:12.438623Z"},"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-07T16:10:12.442256Z","iopub.execute_input":"2022-08-07T16:10:12.443130Z","iopub.status.idle":"2022-08-07T16:10:12.447942Z","shell.execute_reply.started":"2022-08-07T16:10:12.443090Z","shell.execute_reply":"2022-08-07T16:10:12.447332Z"},"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-07T16:10:12.449384Z","iopub.execute_input":"2022-08-07T16:10:12.450013Z","iopub.status.idle":"2022-08-07T16:10:12.463074Z","shell.execute_reply.started":"2022-08-07T16:10:12.449971Z","shell.execute_reply":"2022-08-07T16:10:12.462436Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"combi['VIP'].replace({False: 0, True: 1})","metadata":{"execution":{"iopub.status.busy":"2022-08-07T16:10:12.464350Z","iopub.execute_input":"2022-08-07T16:10:12.465352Z","iopub.status.idle":"2022-08-07T16:10:12.480979Z","shell.execute_reply.started":"2022-08-07T16:10:12.465312Z","shell.execute_reply":"2022-08-07T16:10:12.480012Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.distplot(combi['VIP'])","metadata":{"execution":{"iopub.status.busy":"2022-08-07T16:10:12.482320Z","iopub.execute_input":"2022-08-07T16:10:12.482655Z","iopub.status.idle":"2022-08-07T16:10:12.847088Z","shell.execute_reply.started":"2022-08-07T16:10:12.482615Z","shell.execute_reply":"2022-08-07T16:10:12.846546Z"},"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-07T16:10:12.850481Z","iopub.execute_input":"2022-08-07T16:10:12.850816Z","iopub.status.idle":"2022-08-07T16:10:12.859625Z","shell.execute_reply.started":"2022-08-07T16:10:12.850788Z","shell.execute_reply":"2022-08-07T16:10:12.858791Z"},"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-07T16:10:12.860603Z","iopub.execute_input":"2022-08-07T16:10:12.860806Z","iopub.status.idle":"2022-08-07T16:10:12.870852Z","shell.execute_reply.started":"2022-08-07T16:10:12.860780Z","shell.execute_reply":"2022-08-07T16:10:12.870324Z"},"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-07T16:10:12.872029Z","iopub.execute_input":"2022-08-07T16:10:12.872415Z","iopub.status.idle":"2022-08-07T16:10:12.888756Z","shell.execute_reply.started":"2022-08-07T16:10:12.872376Z","shell.execute_reply":"2022-08-07T16:10:12.887654Z"},"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-07T16:10:12.891767Z","iopub.execute_input":"2022-08-07T16:10:12.892402Z","iopub.status.idle":"2022-08-07T16:10:13.129984Z","shell.execute_reply.started":"2022-08-07T16:10:12.892368Z","shell.execute_reply":"2022-08-07T16:10:13.129293Z"},"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-07T16:10:13.131431Z","iopub.execute_input":"2022-08-07T16:10:13.132228Z","iopub.status.idle":"2022-08-07T16:10:13.138871Z","shell.execute_reply.started":"2022-08-07T16:10:13.132178Z","shell.execute_reply":"2022-08-07T16:10:13.137868Z"},"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-07T16:10:13.140486Z","iopub.execute_input":"2022-08-07T16:10:13.141181Z","iopub.status.idle":"2022-08-07T16:10:13.158392Z","shell.execute_reply.started":"2022-08-07T16:10:13.141134Z","shell.execute_reply":"2022-08-07T16:10:13.157495Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.displot(combi['Room_Service_group'])","metadata":{"execution":{"iopub.status.busy":"2022-08-07T16:10:13.159697Z","iopub.execute_input":"2022-08-07T16:10:13.160305Z","iopub.status.idle":"2022-08-07T16:10:13.452902Z","shell.execute_reply.started":"2022-08-07T16:10:13.160270Z","shell.execute_reply":"2022-08-07T16:10:13.452268Z"},"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-07T16:10:13.454062Z","iopub.execute_input":"2022-08-07T16:10:13.454450Z","iopub.status.idle":"2022-08-07T16:10:13.462675Z","shell.execute_reply.started":"2022-08-07T16:10:13.454417Z","shell.execute_reply":"2022-08-07T16:10:13.461867Z"},"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-07T16:10:13.463890Z","iopub.execute_input":"2022-08-07T16:10:13.464111Z","iopub.status.idle":"2022-08-07T16:10:13.479752Z","shell.execute_reply.started":"2022-08-07T16:10:13.464084Z","shell.execute_reply":"2022-08-07T16:10:13.478943Z"},"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-07T16:10:13.481034Z","iopub.execute_input":"2022-08-07T16:10:13.481292Z","iopub.status.idle":"2022-08-07T16:10:13.583418Z","shell.execute_reply.started":"2022-08-07T16:10:13.481256Z","shell.execute_reply":"2022-08-07T16:10:13.582297Z"},"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-07T16:10:13.585272Z","iopub.execute_input":"2022-08-07T16:10:13.585753Z","iopub.status.idle":"2022-08-07T16:10:13.610531Z","shell.execute_reply.started":"2022-08-07T16:10:13.585696Z","shell.execute_reply":"2022-08-07T16:10:13.609432Z"},"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-07T16:10:13.612465Z","iopub.execute_input":"2022-08-07T16:10:13.613071Z","iopub.status.idle":"2022-08-07T16:10:13.887027Z","shell.execute_reply.started":"2022-08-07T16:10:13.613018Z","shell.execute_reply":"2022-08-07T16:10:13.886077Z"},"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-07T16:10:13.888396Z","iopub.execute_input":"2022-08-07T16:10:13.888635Z","iopub.status.idle":"2022-08-07T16:10:13.893492Z","shell.execute_reply.started":"2022-08-07T16:10:13.888607Z","shell.execute_reply":"2022-08-07T16:10:13.892620Z"},"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-07T16:10:13.894907Z","iopub.execute_input":"2022-08-07T16:10:13.895676Z","iopub.status.idle":"2022-08-07T16:10:13.911960Z","shell.execute_reply.started":"2022-08-07T16:10:13.895632Z","shell.execute_reply":"2022-08-07T16:10:13.911340Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.displot(combi['Food_Court_group'])","metadata":{"execution":{"iopub.status.busy":"2022-08-07T16:10:13.912851Z","iopub.execute_input":"2022-08-07T16:10:13.913373Z","iopub.status.idle":"2022-08-07T16:10:14.200140Z","shell.execute_reply.started":"2022-08-07T16:10:13.913322Z","shell.execute_reply":"2022-08-07T16:10:14.199284Z"},"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-07T16:10:14.201420Z","iopub.execute_input":"2022-08-07T16:10:14.202292Z","iopub.status.idle":"2022-08-07T16:10:14.210483Z","shell.execute_reply.started":"2022-08-07T16:10:14.202255Z","shell.execute_reply":"2022-08-07T16:10:14.209644Z"},"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-07T16:10:14.211794Z","iopub.execute_input":"2022-08-07T16:10:14.212448Z","iopub.status.idle":"2022-08-07T16:10:14.224742Z","shell.execute_reply.started":"2022-08-07T16:10:14.212414Z","shell.execute_reply":"2022-08-07T16:10:14.223849Z"},"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-07T16:10:14.227884Z","iopub.execute_input":"2022-08-07T16:10:14.228345Z","iopub.status.idle":"2022-08-07T16:10:14.330757Z","shell.execute_reply.started":"2022-08-07T16:10:14.228312Z","shell.execute_reply":"2022-08-07T16:10:14.329570Z"},"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-07T16:10:14.332679Z","iopub.execute_input":"2022-08-07T16:10:14.333610Z","iopub.status.idle":"2022-08-07T16:10:14.358471Z","shell.execute_reply.started":"2022-08-07T16:10:14.333552Z","shell.execute_reply":"2022-08-07T16:10:14.357437Z"},"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-07T16:10:14.360436Z","iopub.execute_input":"2022-08-07T16:10:14.361072Z","iopub.status.idle":"2022-08-07T16:10:14.635477Z","shell.execute_reply.started":"2022-08-07T16:10:14.361014Z","shell.execute_reply":"2022-08-07T16:10:14.634593Z"},"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-07T16:10:14.637087Z","iopub.execute_input":"2022-08-07T16:10:14.637406Z","iopub.status.idle":"2022-08-07T16:10:14.642349Z","shell.execute_reply.started":"2022-08-07T16:10:14.637347Z","shell.execute_reply":"2022-08-07T16:10:14.641601Z"},"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-07T16:10:14.644039Z","iopub.execute_input":"2022-08-07T16:10:14.644318Z","iopub.status.idle":"2022-08-07T16:10:14.660819Z","shell.execute_reply.started":"2022-08-07T16:10:14.644282Z","shell.execute_reply":"2022-08-07T16:10:14.660041Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.displot(combi['Shopping_group'])","metadata":{"execution":{"iopub.status.busy":"2022-08-07T16:10:14.662240Z","iopub.execute_input":"2022-08-07T16:10:14.662714Z","iopub.status.idle":"2022-08-07T16:10:14.945345Z","shell.execute_reply.started":"2022-08-07T16:10:14.662682Z","shell.execute_reply":"2022-08-07T16:10:14.944541Z"},"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-07T16:10:14.946812Z","iopub.execute_input":"2022-08-07T16:10:14.947043Z","iopub.status.idle":"2022-08-07T16:10:14.954962Z","shell.execute_reply.started":"2022-08-07T16:10:14.947014Z","shell.execute_reply":"2022-08-07T16:10:14.954182Z"},"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-07T16:10:14.956109Z","iopub.execute_input":"2022-08-07T16:10:14.956430Z","iopub.status.idle":"2022-08-07T16:10:14.966253Z","shell.execute_reply.started":"2022-08-07T16:10:14.956334Z","shell.execute_reply":"2022-08-07T16:10:14.965506Z"},"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-07T16:10:14.967518Z","iopub.execute_input":"2022-08-07T16:10:14.968244Z","iopub.status.idle":"2022-08-07T16:10:15.063318Z","shell.execute_reply.started":"2022-08-07T16:10:14.968202Z","shell.execute_reply":"2022-08-07T16:10:15.062258Z"},"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-07T16:10:15.073330Z","iopub.execute_input":"2022-08-07T16:10:15.074017Z","iopub.status.idle":"2022-08-07T16:10:15.098613Z","shell.execute_reply.started":"2022-08-07T16:10:15.073964Z","shell.execute_reply":"2022-08-07T16:10:15.097239Z"},"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-07T16:10:15.100815Z","iopub.execute_input":"2022-08-07T16:10:15.101483Z","iopub.status.idle":"2022-08-07T16:10:15.313214Z","shell.execute_reply.started":"2022-08-07T16:10:15.101422Z","shell.execute_reply":"2022-08-07T16:10:15.312348Z"},"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-07T16:10:15.314604Z","iopub.execute_input":"2022-08-07T16:10:15.315131Z","iopub.status.idle":"2022-08-07T16:10:15.322201Z","shell.execute_reply.started":"2022-08-07T16:10:15.315082Z","shell.execute_reply":"2022-08-07T16:10:15.321290Z"},"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-07T16:10:15.323715Z","iopub.execute_input":"2022-08-07T16:10:15.324771Z","iopub.status.idle":"2022-08-07T16:10:15.342113Z","shell.execute_reply.started":"2022-08-07T16:10:15.324729Z","shell.execute_reply":"2022-08-07T16:10:15.341407Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.displot(combi['Spa_group'])","metadata":{"execution":{"iopub.status.busy":"2022-08-07T16:10:15.343181Z","iopub.execute_input":"2022-08-07T16:10:15.343543Z","iopub.status.idle":"2022-08-07T16:10:15.542762Z","shell.execute_reply.started":"2022-08-07T16:10:15.343514Z","shell.execute_reply":"2022-08-07T16:10:15.542059Z"},"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-07T16:10:15.543865Z","iopub.execute_input":"2022-08-07T16:10:15.544521Z","iopub.status.idle":"2022-08-07T16:10:15.553744Z","shell.execute_reply.started":"2022-08-07T16:10:15.544476Z","shell.execute_reply":"2022-08-07T16:10:15.552892Z"},"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-07T16:10:15.555678Z","iopub.execute_input":"2022-08-07T16:10:15.556158Z","iopub.status.idle":"2022-08-07T16:10:15.572211Z","shell.execute_reply.started":"2022-08-07T16:10:15.556107Z","shell.execute_reply":"2022-08-07T16:10:15.570966Z"},"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-07T16:10:15.573647Z","iopub.execute_input":"2022-08-07T16:10:15.574689Z","iopub.status.idle":"2022-08-07T16:10:15.656410Z","shell.execute_reply.started":"2022-08-07T16:10:15.574601Z","shell.execute_reply":"2022-08-07T16:10:15.655333Z"},"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-07T16:10:15.658055Z","iopub.execute_input":"2022-08-07T16:10:15.658993Z","iopub.status.idle":"2022-08-07T16:10:15.682941Z","shell.execute_reply.started":"2022-08-07T16:10:15.658934Z","shell.execute_reply":"2022-08-07T16:10:15.681905Z"},"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-07T16:10:15.684594Z","iopub.execute_input":"2022-08-07T16:10:15.685567Z","iopub.status.idle":"2022-08-07T16:10:15.892296Z","shell.execute_reply.started":"2022-08-07T16:10:15.685506Z","shell.execute_reply":"2022-08-07T16:10:15.891276Z"},"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-07T16:10:15.893667Z","iopub.execute_input":"2022-08-07T16:10:15.893967Z","iopub.status.idle":"2022-08-07T16:10:15.899892Z","shell.execute_reply.started":"2022-08-07T16:10:15.893926Z","shell.execute_reply":"2022-08-07T16:10:15.899049Z"},"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-07T16:10:15.901277Z","iopub.execute_input":"2022-08-07T16:10:15.901768Z","iopub.status.idle":"2022-08-07T16:10:15.919606Z","shell.execute_reply.started":"2022-08-07T16:10:15.901728Z","shell.execute_reply":"2022-08-07T16:10:15.918522Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.displot(combi['VR_group'])","metadata":{"execution":{"iopub.status.busy":"2022-08-07T16:10:15.920793Z","iopub.execute_input":"2022-08-07T16:10:15.921149Z","iopub.status.idle":"2022-08-07T16:10:16.147836Z","shell.execute_reply.started":"2022-08-07T16:10:15.921117Z","shell.execute_reply":"2022-08-07T16:10:16.147159Z"},"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-07T16:10:16.149012Z","iopub.execute_input":"2022-08-07T16:10:16.149403Z","iopub.status.idle":"2022-08-07T16:10:16.157384Z","shell.execute_reply.started":"2022-08-07T16:10:16.149350Z","shell.execute_reply":"2022-08-07T16:10:16.156634Z"},"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-07T16:10:16.158629Z","iopub.execute_input":"2022-08-07T16:10:16.159017Z","iopub.status.idle":"2022-08-07T16:10:16.170014Z","shell.execute_reply.started":"2022-08-07T16:10:16.158971Z","shell.execute_reply":"2022-08-07T16:10:16.169237Z"},"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-07T16:10:16.170906Z","iopub.execute_input":"2022-08-07T16:10:16.171379Z","iopub.status.idle":"2022-08-07T16:10:16.266848Z","shell.execute_reply.started":"2022-08-07T16:10:16.171338Z","shell.execute_reply":"2022-08-07T16:10:16.265759Z"},"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-07T16:10:16.268848Z","iopub.execute_input":"2022-08-07T16:10:16.269485Z","iopub.status.idle":"2022-08-07T16:10:16.294350Z","shell.execute_reply.started":"2022-08-07T16:10:16.269424Z","shell.execute_reply":"2022-08-07T16:10:16.293303Z"},"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-07T16:10:16.296321Z","iopub.execute_input":"2022-08-07T16:10:16.296985Z","iopub.status.idle":"2022-08-07T16:10:16.314039Z","shell.execute_reply.started":"2022-08-07T16:10:16.296932Z","shell.execute_reply":"2022-08-07T16:10:16.312612Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"combi.info()","metadata":{"execution":{"iopub.status.busy":"2022-08-07T16:10:16.316007Z","iopub.execute_input":"2022-08-07T16:10:16.316676Z","iopub.status.idle":"2022-08-07T16:10:16.341268Z","shell.execute_reply.started":"2022-08-07T16:10:16.316620Z","shell.execute_reply":"2022-08-07T16:10:16.340221Z"},"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-07T16:10:16.343331Z","iopub.execute_input":"2022-08-07T16:10:16.343989Z","iopub.status.idle":"2022-08-07T16:10:16.817986Z","shell.execute_reply.started":"2022-08-07T16:10:16.343938Z","shell.execute_reply":"2022-08-07T16:10:16.817118Z"},"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-07T16:10:16.819326Z","iopub.execute_input":"2022-08-07T16:10:16.819673Z","iopub.status.idle":"2022-08-07T16:10:16.854271Z","shell.execute_reply.started":"2022-08-07T16:10:16.819628Z","shell.execute_reply":"2022-08-07T16:10:16.853426Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"combi.info()","metadata":{"execution":{"iopub.status.busy":"2022-08-07T16:10:16.857220Z","iopub.execute_input":"2022-08-07T16:10:16.857762Z","iopub.status.idle":"2022-08-07T16:10:16.872294Z","shell.execute_reply.started":"2022-08-07T16:10:16.857729Z","shell.execute_reply":"2022-08-07T16:10:16.871604Z"},"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-07T16:10:16.874924Z","iopub.execute_input":"2022-08-07T16:10:16.875645Z","iopub.status.idle":"2022-08-07T16:10:16.880324Z","shell.execute_reply.started":"2022-08-07T16:10:16.875609Z","shell.execute_reply":"2022-08-07T16:10:16.879294Z"},"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-07T16:10:16.881403Z","iopub.execute_input":"2022-08-07T16:10:16.881734Z","iopub.status.idle":"2022-08-07T16:10:16.899650Z","shell.execute_reply.started":"2022-08-07T16:10:16.881708Z","shell.execute_reply":"2022-08-07T16:10:16.898784Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Select model","metadata":{}},{"cell_type":"code","source":"from sklearn.ensemble import RandomForestClassifier\n\nmodel = RandomForestClassifier(n_estimators=1000, max_depth=2, random_state=42, class_weight='balanced').fit(X_train, y_train)\nprint(model.score(X_train, y_train))","metadata":{"execution":{"iopub.status.busy":"2022-08-07T16:10:16.900732Z","iopub.execute_input":"2022-08-07T16:10:16.901117Z","iopub.status.idle":"2022-08-07T16:10:20.219906Z","shell.execute_reply.started":"2022-08-07T16:10:16.901085Z","shell.execute_reply":"2022-08-07T16:10:20.219074Z"},"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-07T16:10:20.221173Z","iopub.execute_input":"2022-08-07T16:10:20.221435Z","iopub.status.idle":"2022-08-07T16:10:20.476913Z","shell.execute_reply.started":"2022-08-07T16:10:20.221403Z","shell.execute_reply":"2022-08-07T16:10:20.476201Z"},"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-07T16:10:20.478241Z","iopub.execute_input":"2022-08-07T16:10:20.478485Z","iopub.status.idle":"2022-08-07T16:10:20.484070Z","shell.execute_reply.started":"2022-08-07T16:10:20.478453Z","shell.execute_reply":"2022-08-07T16:10:20.483345Z"},"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-07T16:10:20.485312Z","iopub.execute_input":"2022-08-07T16:10:20.485547Z","iopub.status.idle":"2022-08-07T16:10:20.829654Z","shell.execute_reply.started":"2022-08-07T16:10:20.485520Z","shell.execute_reply":"2022-08-07T16:10:20.828849Z"},"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-07T16:10:20.830778Z","iopub.execute_input":"2022-08-07T16:10:20.831029Z","iopub.status.idle":"2022-08-07T16:10:20.854608Z","shell.execute_reply.started":"2022-08-07T16:10:20.830999Z","shell.execute_reply":"2022-08-07T16:10:20.853764Z"},"trusted":true},"execution_count":null,"outputs":[]}]}