{"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:46:44.689141Z","iopub.execute_input":"2022-08-07T15:46:44.689928Z","iopub.status.idle":"2022-08-07T15:46:45.884713Z","shell.execute_reply.started":"2022-08-07T15:46:44.689793Z","shell.execute_reply":"2022-08-07T15:46:45.883609Z"},"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:46:45.886917Z","iopub.execute_input":"2022-08-07T15:46:45.887255Z","iopub.status.idle":"2022-08-07T15:46:45.894816Z","shell.execute_reply.started":"2022-08-07T15:46:45.887221Z","shell.execute_reply":"2022-08-07T15:46:45.893555Z"},"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:46:45.896289Z","iopub.execute_input":"2022-08-07T15:46:45.897081Z","iopub.status.idle":"2022-08-07T15:46:45.991626Z","shell.execute_reply.started":"2022-08-07T15:46:45.897037Z","shell.execute_reply":"2022-08-07T15:46:45.990934Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:46:45.993983Z","iopub.execute_input":"2022-08-07T15:46:45.995119Z","iopub.status.idle":"2022-08-07T15:46:46.042914Z","shell.execute_reply.started":"2022-08-07T15:46:45.995063Z","shell.execute_reply":"2022-08-07T15:46:46.041780Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:46:46.044225Z","iopub.execute_input":"2022-08-07T15:46:46.045357Z","iopub.status.idle":"2022-08-07T15:46:46.073604Z","shell.execute_reply.started":"2022-08-07T15:46:46.045315Z","shell.execute_reply":"2022-08-07T15:46:46.072633Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:46:46.074987Z","iopub.execute_input":"2022-08-07T15:46:46.076188Z","iopub.status.idle":"2022-08-07T15:46:46.093298Z","shell.execute_reply.started":"2022-08-07T15:46:46.076031Z","shell.execute_reply":"2022-08-07T15:46:46.092046Z"},"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:46:46.094991Z","iopub.execute_input":"2022-08-07T15:46:46.095475Z","iopub.status.idle":"2022-08-07T15:46:46.109404Z","shell.execute_reply.started":"2022-08-07T15:46:46.095431Z","shell.execute_reply":"2022-08-07T15:46:46.108349Z"},"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:46:46.111027Z","iopub.execute_input":"2022-08-07T15:46:46.111581Z","iopub.status.idle":"2022-08-07T15:46:46.156128Z","shell.execute_reply.started":"2022-08-07T15:46:46.111534Z","shell.execute_reply":"2022-08-07T15:46:46.155443Z"},"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:46:46.157596Z","iopub.execute_input":"2022-08-07T15:46:46.158437Z","iopub.status.idle":"2022-08-07T15:46:46.202563Z","shell.execute_reply.started":"2022-08-07T15:46:46.158389Z","shell.execute_reply":"2022-08-07T15:46:46.201506Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:46:46.205431Z","iopub.execute_input":"2022-08-07T15:46:46.205915Z","iopub.status.idle":"2022-08-07T15:46:46.230714Z","shell.execute_reply.started":"2022-08-07T15:46:46.205882Z","shell.execute_reply":"2022-08-07T15:46:46.230063Z"},"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:46:46.231843Z","iopub.execute_input":"2022-08-07T15:46:46.232210Z","iopub.status.idle":"2022-08-07T15:46:46.251506Z","shell.execute_reply.started":"2022-08-07T15:46:46.232180Z","shell.execute_reply":"2022-08-07T15:46:46.250415Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.displot(train1['Transported'])","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:46:46.252853Z","iopub.execute_input":"2022-08-07T15:46:46.253136Z","iopub.status.idle":"2022-08-07T15:46:46.667956Z","shell.execute_reply.started":"2022-08-07T15:46:46.253103Z","shell.execute_reply":"2022-08-07T15:46:46.666820Z"},"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:46:46.669851Z","iopub.execute_input":"2022-08-07T15:46:46.670202Z","iopub.status.idle":"2022-08-07T15:46:46.681591Z","shell.execute_reply.started":"2022-08-07T15:46:46.670157Z","shell.execute_reply":"2022-08-07T15:46:46.680311Z"},"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:46:46.684375Z","iopub.execute_input":"2022-08-07T15:46:46.684853Z","iopub.status.idle":"2022-08-07T15:46:46.696378Z","shell.execute_reply.started":"2022-08-07T15:46:46.684795Z","shell.execute_reply":"2022-08-07T15:46:46.695412Z"},"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:46:46.697794Z","iopub.execute_input":"2022-08-07T15:46:46.698187Z","iopub.status.idle":"2022-08-07T15:46:47.252164Z","shell.execute_reply.started":"2022-08-07T15:46:46.698154Z","shell.execute_reply":"2022-08-07T15:46:47.251074Z"},"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:46:47.254380Z","iopub.execute_input":"2022-08-07T15:46:47.254764Z","iopub.status.idle":"2022-08-07T15:46:47.285905Z","shell.execute_reply.started":"2022-08-07T15:46:47.254700Z","shell.execute_reply":"2022-08-07T15:46:47.285148Z"},"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:46:47.287642Z","iopub.execute_input":"2022-08-07T15:46:47.287995Z","iopub.status.idle":"2022-08-07T15:46:47.319987Z","shell.execute_reply.started":"2022-08-07T15:46:47.287953Z","shell.execute_reply":"2022-08-07T15:46:47.319085Z"},"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:46:47.321421Z","iopub.execute_input":"2022-08-07T15:46:47.321665Z","iopub.status.idle":"2022-08-07T15:46:47.342022Z","shell.execute_reply.started":"2022-08-07T15:46:47.321634Z","shell.execute_reply":"2022-08-07T15:46:47.341261Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"combi.describe()","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:46:47.343211Z","iopub.execute_input":"2022-08-07T15:46:47.343446Z","iopub.status.idle":"2022-08-07T15:46:47.381570Z","shell.execute_reply.started":"2022-08-07T15:46:47.343419Z","shell.execute_reply":"2022-08-07T15:46:47.380809Z"},"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:46:47.382870Z","iopub.execute_input":"2022-08-07T15:46:47.383102Z","iopub.status.idle":"2022-08-07T15:46:47.395434Z","shell.execute_reply.started":"2022-08-07T15:46:47.383074Z","shell.execute_reply":"2022-08-07T15:46:47.394153Z"},"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:46:47.397555Z","iopub.execute_input":"2022-08-07T15:46:47.397955Z","iopub.status.idle":"2022-08-07T15:46:47.773995Z","shell.execute_reply.started":"2022-08-07T15:46:47.397913Z","shell.execute_reply":"2022-08-07T15:46:47.772924Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"combi.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:46:47.775391Z","iopub.execute_input":"2022-08-07T15:46:47.775643Z","iopub.status.idle":"2022-08-07T15:46:47.787168Z","shell.execute_reply.started":"2022-08-07T15:46:47.775613Z","shell.execute_reply":"2022-08-07T15:46:47.786493Z"},"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:46:47.788407Z","iopub.execute_input":"2022-08-07T15:46:47.789172Z","iopub.status.idle":"2022-08-07T15:46:48.112503Z","shell.execute_reply.started":"2022-08-07T15:46:47.789138Z","shell.execute_reply":"2022-08-07T15:46:48.111622Z"},"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:46:48.114018Z","iopub.execute_input":"2022-08-07T15:46:48.114273Z","iopub.status.idle":"2022-08-07T15:46:48.124586Z","shell.execute_reply.started":"2022-08-07T15:46:48.114229Z","shell.execute_reply":"2022-08-07T15:46:48.123494Z"},"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:46:48.125909Z","iopub.execute_input":"2022-08-07T15:46:48.127230Z","iopub.status.idle":"2022-08-07T15:46:48.139448Z","shell.execute_reply.started":"2022-08-07T15:46:48.127181Z","shell.execute_reply":"2022-08-07T15:46:48.138406Z"},"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:46:48.144641Z","iopub.execute_input":"2022-08-07T15:46:48.145718Z","iopub.status.idle":"2022-08-07T15:46:48.256900Z","shell.execute_reply.started":"2022-08-07T15:46:48.145680Z","shell.execute_reply":"2022-08-07T15:46:48.255688Z"},"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:46:48.258514Z","iopub.execute_input":"2022-08-07T15:46:48.258966Z","iopub.status.idle":"2022-08-07T15:46:48.290020Z","shell.execute_reply.started":"2022-08-07T15:46:48.258932Z","shell.execute_reply":"2022-08-07T15:46:48.288925Z"},"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:46:48.291760Z","iopub.execute_input":"2022-08-07T15:46:48.293045Z","iopub.status.idle":"2022-08-07T15:46:48.309725Z","shell.execute_reply.started":"2022-08-07T15:46:48.292983Z","shell.execute_reply":"2022-08-07T15:46:48.308228Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(combi.iloc[6674])","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:46:48.312124Z","iopub.execute_input":"2022-08-07T15:46:48.313020Z","iopub.status.idle":"2022-08-07T15:46:48.323963Z","shell.execute_reply.started":"2022-08-07T15:46:48.312951Z","shell.execute_reply":"2022-08-07T15:46:48.322782Z"},"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:46:48.326314Z","iopub.execute_input":"2022-08-07T15:46:48.327263Z","iopub.status.idle":"2022-08-07T15:46:48.351186Z","shell.execute_reply.started":"2022-08-07T15:46:48.327192Z","shell.execute_reply":"2022-08-07T15:46:48.350167Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.distplot(combi['CryoSleep'])","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:46:48.353275Z","iopub.execute_input":"2022-08-07T15:46:48.353631Z","iopub.status.idle":"2022-08-07T15:46:48.713446Z","shell.execute_reply.started":"2022-08-07T15:46:48.353587Z","shell.execute_reply":"2022-08-07T15:46:48.712330Z"},"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:46:48.715458Z","iopub.execute_input":"2022-08-07T15:46:48.715855Z","iopub.status.idle":"2022-08-07T15:46:48.726273Z","shell.execute_reply.started":"2022-08-07T15:46:48.715804Z","shell.execute_reply":"2022-08-07T15:46:48.725394Z"},"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:46:48.728097Z","iopub.execute_input":"2022-08-07T15:46:48.728616Z","iopub.status.idle":"2022-08-07T15:46:48.742653Z","shell.execute_reply.started":"2022-08-07T15:46:48.728570Z","shell.execute_reply":"2022-08-07T15:46:48.741413Z"},"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:46:48.746395Z","iopub.execute_input":"2022-08-07T15:46:48.746833Z","iopub.status.idle":"2022-08-07T15:46:48.758615Z","shell.execute_reply.started":"2022-08-07T15:46:48.746796Z","shell.execute_reply":"2022-08-07T15:46:48.757700Z"},"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:46:48.760308Z","iopub.execute_input":"2022-08-07T15:46:48.760691Z","iopub.status.idle":"2022-08-07T15:46:49.020128Z","shell.execute_reply.started":"2022-08-07T15:46:48.760660Z","shell.execute_reply":"2022-08-07T15:46:49.019354Z"},"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:46:49.021862Z","iopub.execute_input":"2022-08-07T15:46:49.022404Z","iopub.status.idle":"2022-08-07T15:46:49.032670Z","shell.execute_reply.started":"2022-08-07T15:46:49.022356Z","shell.execute_reply":"2022-08-07T15:46:49.032067Z"},"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:46:49.034353Z","iopub.execute_input":"2022-08-07T15:46:49.034822Z","iopub.status.idle":"2022-08-07T15:46:49.047482Z","shell.execute_reply.started":"2022-08-07T15:46:49.034772Z","shell.execute_reply":"2022-08-07T15:46:49.046769Z"},"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:46:49.049216Z","iopub.execute_input":"2022-08-07T15:46:49.049777Z","iopub.status.idle":"2022-08-07T15:46:49.152425Z","shell.execute_reply.started":"2022-08-07T15:46:49.049711Z","shell.execute_reply":"2022-08-07T15:46:49.151615Z"},"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:46:49.154037Z","iopub.execute_input":"2022-08-07T15:46:49.154533Z","iopub.status.idle":"2022-08-07T15:46:49.174445Z","shell.execute_reply.started":"2022-08-07T15:46:49.154486Z","shell.execute_reply":"2022-08-07T15:46:49.173384Z"},"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:46:49.176332Z","iopub.execute_input":"2022-08-07T15:46:49.176689Z","iopub.status.idle":"2022-08-07T15:46:49.196070Z","shell.execute_reply.started":"2022-08-07T15:46:49.176642Z","shell.execute_reply":"2022-08-07T15:46:49.195027Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.displot(combi['Age_group'])","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:46:49.197902Z","iopub.execute_input":"2022-08-07T15:46:49.199012Z","iopub.status.idle":"2022-08-07T15:46:49.624122Z","shell.execute_reply.started":"2022-08-07T15:46:49.198960Z","shell.execute_reply":"2022-08-07T15:46:49.623092Z"},"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:46:49.625742Z","iopub.execute_input":"2022-08-07T15:46:49.626505Z","iopub.status.idle":"2022-08-07T15:46:49.637675Z","shell.execute_reply.started":"2022-08-07T15:46:49.626457Z","shell.execute_reply":"2022-08-07T15:46:49.636527Z"},"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:46:49.639233Z","iopub.execute_input":"2022-08-07T15:46:49.640027Z","iopub.status.idle":"2022-08-07T15:46:49.648917Z","shell.execute_reply.started":"2022-08-07T15:46:49.639970Z","shell.execute_reply":"2022-08-07T15:46:49.647981Z"},"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:46:49.650677Z","iopub.execute_input":"2022-08-07T15:46:49.651959Z","iopub.status.idle":"2022-08-07T15:46:49.737217Z","shell.execute_reply.started":"2022-08-07T15:46:49.651884Z","shell.execute_reply":"2022-08-07T15:46:49.736497Z"},"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:46:49.738769Z","iopub.execute_input":"2022-08-07T15:46:49.739254Z","iopub.status.idle":"2022-08-07T15:46:49.753322Z","shell.execute_reply.started":"2022-08-07T15:46:49.739213Z","shell.execute_reply":"2022-08-07T15:46:49.752467Z"},"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:46:49.754983Z","iopub.execute_input":"2022-08-07T15:46:49.755286Z","iopub.status.idle":"2022-08-07T15:46:49.760827Z","shell.execute_reply.started":"2022-08-07T15:46:49.755247Z","shell.execute_reply":"2022-08-07T15:46:49.759582Z"},"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:46:49.763807Z","iopub.execute_input":"2022-08-07T15:46:49.764221Z","iopub.status.idle":"2022-08-07T15:46:49.776530Z","shell.execute_reply.started":"2022-08-07T15:46:49.764179Z","shell.execute_reply":"2022-08-07T15:46:49.775430Z"},"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:46:49.780034Z","iopub.execute_input":"2022-08-07T15:46:49.780337Z","iopub.status.idle":"2022-08-07T15:46:49.793778Z","shell.execute_reply.started":"2022-08-07T15:46:49.780306Z","shell.execute_reply":"2022-08-07T15:46:49.792908Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.distplot(combi['VIP'])","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:46:49.795700Z","iopub.execute_input":"2022-08-07T15:46:49.796280Z","iopub.status.idle":"2022-08-07T15:46:50.173856Z","shell.execute_reply.started":"2022-08-07T15:46:49.796235Z","shell.execute_reply":"2022-08-07T15:46:50.173220Z"},"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:46:50.175379Z","iopub.execute_input":"2022-08-07T15:46:50.175891Z","iopub.status.idle":"2022-08-07T15:46:50.184472Z","shell.execute_reply.started":"2022-08-07T15:46:50.175847Z","shell.execute_reply":"2022-08-07T15:46:50.183840Z"},"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:46:50.185678Z","iopub.execute_input":"2022-08-07T15:46:50.185980Z","iopub.status.idle":"2022-08-07T15:46:50.195394Z","shell.execute_reply.started":"2022-08-07T15:46:50.185950Z","shell.execute_reply":"2022-08-07T15:46:50.194809Z"},"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:46:50.196311Z","iopub.execute_input":"2022-08-07T15:46:50.196683Z","iopub.status.idle":"2022-08-07T15:46:50.210799Z","shell.execute_reply.started":"2022-08-07T15:46:50.196654Z","shell.execute_reply":"2022-08-07T15:46:50.209711Z"},"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:46:50.212175Z","iopub.execute_input":"2022-08-07T15:46:50.213186Z","iopub.status.idle":"2022-08-07T15:46:50.506157Z","shell.execute_reply.started":"2022-08-07T15:46:50.213118Z","shell.execute_reply":"2022-08-07T15:46:50.505496Z"},"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:46:50.507378Z","iopub.execute_input":"2022-08-07T15:46:50.508317Z","iopub.status.idle":"2022-08-07T15:46:50.514421Z","shell.execute_reply.started":"2022-08-07T15:46:50.508279Z","shell.execute_reply":"2022-08-07T15:46:50.513173Z"},"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:46:50.515660Z","iopub.execute_input":"2022-08-07T15:46:50.515944Z","iopub.status.idle":"2022-08-07T15:46:50.533683Z","shell.execute_reply.started":"2022-08-07T15:46:50.515913Z","shell.execute_reply":"2022-08-07T15:46:50.533057Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.displot(combi['Room_Service_group'])","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:46:50.535019Z","iopub.execute_input":"2022-08-07T15:46:50.535396Z","iopub.status.idle":"2022-08-07T15:46:50.782339Z","shell.execute_reply.started":"2022-08-07T15:46:50.535353Z","shell.execute_reply":"2022-08-07T15:46:50.781287Z"},"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:46:50.785649Z","iopub.execute_input":"2022-08-07T15:46:50.786424Z","iopub.status.idle":"2022-08-07T15:46:50.793590Z","shell.execute_reply.started":"2022-08-07T15:46:50.786388Z","shell.execute_reply":"2022-08-07T15:46:50.792989Z"},"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:46:50.795580Z","iopub.execute_input":"2022-08-07T15:46:50.796943Z","iopub.status.idle":"2022-08-07T15:46:50.805933Z","shell.execute_reply.started":"2022-08-07T15:46:50.796888Z","shell.execute_reply":"2022-08-07T15:46:50.805311Z"},"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:46:50.807005Z","iopub.execute_input":"2022-08-07T15:46:50.807535Z","iopub.status.idle":"2022-08-07T15:46:50.918128Z","shell.execute_reply.started":"2022-08-07T15:46:50.807504Z","shell.execute_reply":"2022-08-07T15:46:50.916825Z"},"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:46:50.920244Z","iopub.execute_input":"2022-08-07T15:46:50.921079Z","iopub.status.idle":"2022-08-07T15:46:50.949426Z","shell.execute_reply.started":"2022-08-07T15:46:50.921007Z","shell.execute_reply":"2022-08-07T15:46:50.947926Z"},"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:46:50.963439Z","iopub.execute_input":"2022-08-07T15:46:50.964415Z","iopub.status.idle":"2022-08-07T15:46:51.252929Z","shell.execute_reply.started":"2022-08-07T15:46:50.964343Z","shell.execute_reply":"2022-08-07T15:46:51.251949Z"},"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:46:51.254284Z","iopub.execute_input":"2022-08-07T15:46:51.254529Z","iopub.status.idle":"2022-08-07T15:46:51.260462Z","shell.execute_reply.started":"2022-08-07T15:46:51.254498Z","shell.execute_reply":"2022-08-07T15:46:51.259282Z"},"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:46:51.261691Z","iopub.execute_input":"2022-08-07T15:46:51.261935Z","iopub.status.idle":"2022-08-07T15:46:51.280103Z","shell.execute_reply.started":"2022-08-07T15:46:51.261907Z","shell.execute_reply":"2022-08-07T15:46:51.279399Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.displot(combi['Food_Court_group'])","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:46:51.281106Z","iopub.execute_input":"2022-08-07T15:46:51.281882Z","iopub.status.idle":"2022-08-07T15:46:51.573675Z","shell.execute_reply.started":"2022-08-07T15:46:51.281849Z","shell.execute_reply":"2022-08-07T15:46:51.572770Z"},"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:46:51.575010Z","iopub.execute_input":"2022-08-07T15:46:51.575234Z","iopub.status.idle":"2022-08-07T15:46:51.585710Z","shell.execute_reply.started":"2022-08-07T15:46:51.575206Z","shell.execute_reply":"2022-08-07T15:46:51.584422Z"},"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:46:51.587268Z","iopub.execute_input":"2022-08-07T15:46:51.587508Z","iopub.status.idle":"2022-08-07T15:46:51.596405Z","shell.execute_reply.started":"2022-08-07T15:46:51.587477Z","shell.execute_reply":"2022-08-07T15:46:51.595789Z"},"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:46:51.597722Z","iopub.execute_input":"2022-08-07T15:46:51.598316Z","iopub.status.idle":"2022-08-07T15:46:51.702578Z","shell.execute_reply.started":"2022-08-07T15:46:51.598284Z","shell.execute_reply":"2022-08-07T15:46:51.701427Z"},"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:46:51.704967Z","iopub.execute_input":"2022-08-07T15:46:51.710224Z","iopub.status.idle":"2022-08-07T15:46:51.740113Z","shell.execute_reply.started":"2022-08-07T15:46:51.710083Z","shell.execute_reply":"2022-08-07T15:46:51.739020Z"},"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:46:51.743613Z","iopub.execute_input":"2022-08-07T15:46:51.745016Z","iopub.status.idle":"2022-08-07T15:46:52.030642Z","shell.execute_reply.started":"2022-08-07T15:46:51.744936Z","shell.execute_reply":"2022-08-07T15:46:52.029747Z"},"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:46:52.032047Z","iopub.execute_input":"2022-08-07T15:46:52.032326Z","iopub.status.idle":"2022-08-07T15:46:52.038427Z","shell.execute_reply.started":"2022-08-07T15:46:52.032288Z","shell.execute_reply":"2022-08-07T15:46:52.037829Z"},"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:46:52.039447Z","iopub.execute_input":"2022-08-07T15:46:52.040561Z","iopub.status.idle":"2022-08-07T15:46:52.056439Z","shell.execute_reply.started":"2022-08-07T15:46:52.040491Z","shell.execute_reply":"2022-08-07T15:46:52.055432Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.displot(combi['Shopping_group'])","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:46:52.058046Z","iopub.execute_input":"2022-08-07T15:46:52.058316Z","iopub.status.idle":"2022-08-07T15:46:52.341235Z","shell.execute_reply.started":"2022-08-07T15:46:52.058285Z","shell.execute_reply":"2022-08-07T15:46:52.340605Z"},"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:46:52.342462Z","iopub.execute_input":"2022-08-07T15:46:52.342862Z","iopub.status.idle":"2022-08-07T15:46:52.352164Z","shell.execute_reply.started":"2022-08-07T15:46:52.342812Z","shell.execute_reply":"2022-08-07T15:46:52.351025Z"},"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:46:52.354015Z","iopub.execute_input":"2022-08-07T15:46:52.354420Z","iopub.status.idle":"2022-08-07T15:46:52.367416Z","shell.execute_reply.started":"2022-08-07T15:46:52.354315Z","shell.execute_reply":"2022-08-07T15:46:52.366317Z"},"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:46:52.368818Z","iopub.execute_input":"2022-08-07T15:46:52.369324Z","iopub.status.idle":"2022-08-07T15:46:52.466767Z","shell.execute_reply.started":"2022-08-07T15:46:52.369230Z","shell.execute_reply":"2022-08-07T15:46:52.465705Z"},"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:46:52.468358Z","iopub.execute_input":"2022-08-07T15:46:52.468837Z","iopub.status.idle":"2022-08-07T15:46:52.482445Z","shell.execute_reply.started":"2022-08-07T15:46:52.468794Z","shell.execute_reply":"2022-08-07T15:46:52.481515Z"},"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:46:52.484068Z","iopub.execute_input":"2022-08-07T15:46:52.484371Z","iopub.status.idle":"2022-08-07T15:46:52.749785Z","shell.execute_reply.started":"2022-08-07T15:46:52.484331Z","shell.execute_reply":"2022-08-07T15:46:52.748783Z"},"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:46:52.751507Z","iopub.execute_input":"2022-08-07T15:46:52.751845Z","iopub.status.idle":"2022-08-07T15:46:52.757592Z","shell.execute_reply.started":"2022-08-07T15:46:52.751804Z","shell.execute_reply":"2022-08-07T15:46:52.756764Z"},"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:46:52.759056Z","iopub.execute_input":"2022-08-07T15:46:52.759545Z","iopub.status.idle":"2022-08-07T15:46:52.781496Z","shell.execute_reply.started":"2022-08-07T15:46:52.759512Z","shell.execute_reply":"2022-08-07T15:46:52.780834Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.displot(combi['Spa_group'])","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:46:52.782912Z","iopub.execute_input":"2022-08-07T15:46:52.783603Z","iopub.status.idle":"2022-08-07T15:46:53.010308Z","shell.execute_reply.started":"2022-08-07T15:46:52.783568Z","shell.execute_reply":"2022-08-07T15:46:53.009517Z"},"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:46:53.011718Z","iopub.execute_input":"2022-08-07T15:46:53.012147Z","iopub.status.idle":"2022-08-07T15:46:53.022530Z","shell.execute_reply.started":"2022-08-07T15:46:53.012114Z","shell.execute_reply":"2022-08-07T15:46:53.021386Z"},"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:46:53.024195Z","iopub.execute_input":"2022-08-07T15:46:53.025339Z","iopub.status.idle":"2022-08-07T15:46:53.034304Z","shell.execute_reply.started":"2022-08-07T15:46:53.025292Z","shell.execute_reply":"2022-08-07T15:46:53.033342Z"},"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:46:53.035421Z","iopub.execute_input":"2022-08-07T15:46:53.035663Z","iopub.status.idle":"2022-08-07T15:46:53.128816Z","shell.execute_reply.started":"2022-08-07T15:46:53.035634Z","shell.execute_reply":"2022-08-07T15:46:53.127854Z"},"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:46:53.130328Z","iopub.execute_input":"2022-08-07T15:46:53.131071Z","iopub.status.idle":"2022-08-07T15:46:53.149834Z","shell.execute_reply.started":"2022-08-07T15:46:53.131015Z","shell.execute_reply":"2022-08-07T15:46:53.148925Z"},"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:46:53.151294Z","iopub.execute_input":"2022-08-07T15:46:53.152644Z","iopub.status.idle":"2022-08-07T15:46:53.415442Z","shell.execute_reply.started":"2022-08-07T15:46:53.152599Z","shell.execute_reply":"2022-08-07T15:46:53.414799Z"},"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:46:53.416422Z","iopub.execute_input":"2022-08-07T15:46:53.417333Z","iopub.status.idle":"2022-08-07T15:46:53.423231Z","shell.execute_reply.started":"2022-08-07T15:46:53.417290Z","shell.execute_reply":"2022-08-07T15:46:53.422012Z"},"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:46:53.424542Z","iopub.execute_input":"2022-08-07T15:46:53.424791Z","iopub.status.idle":"2022-08-07T15:46:53.440485Z","shell.execute_reply.started":"2022-08-07T15:46:53.424753Z","shell.execute_reply":"2022-08-07T15:46:53.439825Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.displot(combi['VR_group'])","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:46:53.441637Z","iopub.execute_input":"2022-08-07T15:46:53.442652Z","iopub.status.idle":"2022-08-07T15:46:53.756400Z","shell.execute_reply.started":"2022-08-07T15:46:53.442614Z","shell.execute_reply":"2022-08-07T15:46:53.755287Z"},"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:46:53.757797Z","iopub.execute_input":"2022-08-07T15:46:53.758042Z","iopub.status.idle":"2022-08-07T15:46:53.769296Z","shell.execute_reply.started":"2022-08-07T15:46:53.758012Z","shell.execute_reply":"2022-08-07T15:46:53.768003Z"},"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:46:53.770596Z","iopub.execute_input":"2022-08-07T15:46:53.770920Z","iopub.status.idle":"2022-08-07T15:46:53.783209Z","shell.execute_reply.started":"2022-08-07T15:46:53.770886Z","shell.execute_reply":"2022-08-07T15:46:53.782003Z"},"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:46:53.785455Z","iopub.execute_input":"2022-08-07T15:46:53.785796Z","iopub.status.idle":"2022-08-07T15:46:53.892432Z","shell.execute_reply.started":"2022-08-07T15:46:53.785749Z","shell.execute_reply":"2022-08-07T15:46:53.890841Z"},"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:46:53.895229Z","iopub.execute_input":"2022-08-07T15:46:53.895690Z","iopub.status.idle":"2022-08-07T15:46:53.923600Z","shell.execute_reply.started":"2022-08-07T15:46:53.895632Z","shell.execute_reply":"2022-08-07T15:46:53.922202Z"},"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:46:53.926782Z","iopub.execute_input":"2022-08-07T15:46:53.927862Z","iopub.status.idle":"2022-08-07T15:46:53.950396Z","shell.execute_reply.started":"2022-08-07T15:46:53.927650Z","shell.execute_reply":"2022-08-07T15:46:53.949188Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"combi.info()","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:46:53.953063Z","iopub.execute_input":"2022-08-07T15:46:53.953919Z","iopub.status.idle":"2022-08-07T15:46:53.982413Z","shell.execute_reply.started":"2022-08-07T15:46:53.953853Z","shell.execute_reply":"2022-08-07T15:46:53.981592Z"},"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:46:53.983718Z","iopub.execute_input":"2022-08-07T15:46:53.984364Z","iopub.status.idle":"2022-08-07T15:46:54.488249Z","shell.execute_reply.started":"2022-08-07T15:46:53.984326Z","shell.execute_reply":"2022-08-07T15:46:54.487153Z"},"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:46:54.489927Z","iopub.execute_input":"2022-08-07T15:46:54.490216Z","iopub.status.idle":"2022-08-07T15:46:54.531132Z","shell.execute_reply.started":"2022-08-07T15:46:54.490180Z","shell.execute_reply":"2022-08-07T15:46:54.530476Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"combi.info()","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:46:54.532542Z","iopub.execute_input":"2022-08-07T15:46:54.532887Z","iopub.status.idle":"2022-08-07T15:46:54.550381Z","shell.execute_reply.started":"2022-08-07T15:46:54.532846Z","shell.execute_reply":"2022-08-07T15:46:54.549590Z"},"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:46:54.551968Z","iopub.execute_input":"2022-08-07T15:46:54.552476Z","iopub.status.idle":"2022-08-07T15:46:54.557456Z","shell.execute_reply.started":"2022-08-07T15:46:54.552440Z","shell.execute_reply":"2022-08-07T15:46:54.556642Z"},"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:46:54.559356Z","iopub.execute_input":"2022-08-07T15:46:54.560289Z","iopub.status.idle":"2022-08-07T15:46:54.580509Z","shell.execute_reply.started":"2022-08-07T15:46:54.560243Z","shell.execute_reply":"2022-08-07T15:46:54.579313Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Select model","metadata":{}},{"cell_type":"code","source":"from sklearn.svm import SVC\n\nmodel = SVC(class_weight='balanced', probability=True, random_state=42).fit(X_train, y_train)\nprint(model.score(X_train, y_train))","metadata":{"execution":{"iopub.status.busy":"2022-08-07T15:46:54.582216Z","iopub.execute_input":"2022-08-07T15:46:54.582583Z","iopub.status.idle":"2022-08-07T15:47:00.873242Z","shell.execute_reply.started":"2022-08-07T15:46:54.582551Z","shell.execute_reply":"2022-08-07T15:47:00.871838Z"},"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:47:00.874972Z","iopub.execute_input":"2022-08-07T15:47:00.875255Z","iopub.status.idle":"2022-08-07T15:47:01.011460Z","shell.execute_reply.started":"2022-08-07T15:47:00.875218Z","shell.execute_reply":"2022-08-07T15:47:01.010225Z"},"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:47:01.015174Z","iopub.execute_input":"2022-08-07T15:47:01.015433Z","iopub.status.idle":"2022-08-07T15:47:01.025796Z","shell.execute_reply.started":"2022-08-07T15:47:01.015403Z","shell.execute_reply":"2022-08-07T15:47:01.024799Z"},"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:47:01.027295Z","iopub.execute_input":"2022-08-07T15:47:01.028098Z","iopub.status.idle":"2022-08-07T15:47:01.442320Z","shell.execute_reply.started":"2022-08-07T15:47:01.028022Z","shell.execute_reply":"2022-08-07T15:47:01.441215Z"},"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:47:01.443866Z","iopub.execute_input":"2022-08-07T15:47:01.444163Z","iopub.status.idle":"2022-08-07T15:47:01.475707Z","shell.execute_reply.started":"2022-08-07T15:47:01.444132Z","shell.execute_reply":"2022-08-07T15:47:01.474828Z"},"trusted":true},"execution_count":null,"outputs":[]}]}