{"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":"code","source":"import numpy as np \nimport pandas as pd\nimport seaborn as sns\nimport matplotlib.pyplot as plt\nimport matplotlib.colors\nfrom matplotlib.ticker import MultipleLocator, FormatStrFormatter\nimport plotly.express as px\nimport plotly.graph_objects as go\nfrom plotly.subplots import make_subplots\nfrom plotly.offline import init_notebook_mode\nfrom sklearn.preprocessing import LabelEncoder\nfrom sklearn.model_selection import StratifiedKFold \nfrom sklearn.metrics import roc_auc_score, roc_curve, auc\nimport catboost\nfrom catboost import Pool\nfrom catboost import CatBoostRegressor\nfrom xgboost import XGBRegressor\nfrom xgboost import plot_importance\nfrom sklearn.metrics import mean_squared_error\nfrom sklearn.linear_model import LinearRegression\nfrom sklearn.ensemble import RandomForestRegressor\nfrom sklearn.preprocessing import StandardScaler, MinMaxScaler\nfrom sklearn.impute import SimpleImputer\n\n","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-07-30T15:15:01.702632Z","iopub.execute_input":"2022-07-30T15:15:01.703027Z","iopub.status.idle":"2022-07-30T15:15:01.713570Z","shell.execute_reply.started":"2022-07-30T15:15:01.702995Z","shell.execute_reply":"2022-07-30T15:15:01.712285Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Let's explore which variable is the most important factor affecting whether a passenger will be sent to another dimension!","metadata":{}},{"cell_type":"code","source":"#load data\ntrain = pd.read_csv(\"../input/spaceship-titanic/train.csv\")\ntest = pd.read_csv(\"../input/spaceship-titanic/test.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-07-30T15:15:01.837689Z","iopub.execute_input":"2022-07-30T15:15:01.838791Z","iopub.status.idle":"2022-07-30T15:15:01.896535Z","shell.execute_reply.started":"2022-07-30T15:15:01.838736Z","shell.execute_reply":"2022-07-30T15:15:01.895224Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Data Preprocessing","metadata":{}},{"cell_type":"markdown","source":"checking the type of data and missing data","metadata":{}},{"cell_type":"code","source":"train.info()","metadata":{"execution":{"iopub.status.busy":"2022-07-30T15:15:02.105304Z","iopub.execute_input":"2022-07-30T15:15:02.106979Z","iopub.status.idle":"2022-07-30T15:15:02.132731Z","shell.execute_reply.started":"2022-07-30T15:15:02.106929Z","shell.execute_reply":"2022-07-30T15:15:02.131389Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-30T15:15:02.213178Z","iopub.execute_input":"2022-07-30T15:15:02.213581Z","iopub.status.idle":"2022-07-30T15:15:02.232369Z","shell.execute_reply.started":"2022-07-30T15:15:02.213550Z","shell.execute_reply":"2022-07-30T15:15:02.231091Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.info()","metadata":{"execution":{"iopub.status.busy":"2022-07-30T15:15:02.344790Z","iopub.execute_input":"2022-07-30T15:15:02.345503Z","iopub.status.idle":"2022-07-30T15:15:02.365104Z","shell.execute_reply.started":"2022-07-30T15:15:02.345466Z","shell.execute_reply":"2022-07-30T15:15:02.363205Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-30T15:15:02.466488Z","iopub.execute_input":"2022-07-30T15:15:02.466936Z","iopub.status.idle":"2022-07-30T15:15:02.480054Z","shell.execute_reply.started":"2022-07-30T15:15:02.466899Z","shell.execute_reply":"2022-07-30T15:15:02.478899Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"change 'CryoSleep', 'VIP' and 'Transported' into 0 and 1","metadata":{}},{"cell_type":"code","source":"train['CryoSleep']=train['CryoSleep'].astype(str)\ntrain['VIP']=train['VIP'].astype(str)\n\ntest['CryoSleep']=test['CryoSleep'].astype(str)\ntest['VIP']=test['VIP'].astype(str)\n","metadata":{"execution":{"iopub.status.busy":"2022-07-30T15:15:02.513916Z","iopub.execute_input":"2022-07-30T15:15:02.514947Z","iopub.status.idle":"2022-07-30T15:15:02.535544Z","shell.execute_reply.started":"2022-07-30T15:15:02.514900Z","shell.execute_reply":"2022-07-30T15:15:02.533683Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['Transported']=train['Transported'].astype(int)\n\ntrain['CryoSleep'].replace('False',0,inplace=True)\ntrain['CryoSleep'].replace('True',1,inplace=True)\ntrain['VIP'].replace('False',0,inplace=True)\ntrain['VIP'].replace('True',1,inplace=True)\n\ntest['CryoSleep'].replace('False',0,inplace=True)\ntest['CryoSleep'].replace('True',1,inplace=True)\ntest['VIP'].replace('False',0,inplace=True)\ntest['VIP'].replace('True',1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-30T15:15:02.575911Z","iopub.execute_input":"2022-07-30T15:15:02.576539Z","iopub.status.idle":"2022-07-30T15:15:02.594676Z","shell.execute_reply.started":"2022-07-30T15:15:02.576503Z","shell.execute_reply":"2022-07-30T15:15:02.593365Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Deal with missing data**","metadata":{}},{"cell_type":"markdown","source":"Since People in a group are often family members(not always), we can use PassengerId to fill in their last name.","metadata":{}},{"cell_type":"code","source":"#split PassengerId and Name to get group number and last name\ntrain['gggg']=train['PassengerId'].str.split('_', 1).str[0]\ntrain['pp']=train['PassengerId'].str.split('_', 1).str[1]\ntrain['firstname']=train['Name'].str.split(' ',1).str[0]\ntrain['lastname']=train['Name'].str.split(' ',1).str[1]\ntrain['Cabin_desk']=train['Cabin'].str.split('/',1).str[0]\ntrain['Cabin_num']=train['Cabin'].str.split('/',1).str[1]\ntrain['Cabin_side']=train['Cabin_num'].str.split('/',1).str[1]\ntrain['Cabin_num']=train['Cabin_num'].str.split('/',1).str[0]\ntrain.drop('Cabin',axis=1,inplace=True)\ntrain.drop('Name',axis=1,inplace=True)\n\ntest['gggg']=test['PassengerId'].str.split('_', 1).str[0]\ntest['pp']=test['PassengerId'].str.split('_', 1).str[1]\ntest['firstname']=test['Name'].str.split(' ',1).str[0]\ntest['lastname']=test['Name'].str.split(' ',1).str[1]\ntest['Cabin_desk']=test['Cabin'].str.split('/',1).str[0]\ntest['Cabin_num']=test['Cabin'].str.split('/',1).str[1]\ntest['Cabin_side']=test['Cabin_num'].str.split('/',1).str[1]\ntest['Cabin_num']=test['Cabin_num'].str.split('/',1).str[0]\ntest.drop('Name',axis=1,inplace=True)\ntest.drop('Cabin',axis=1,inplace=True)\n","metadata":{"execution":{"iopub.status.busy":"2022-07-30T15:15:02.632153Z","iopub.execute_input":"2022-07-30T15:15:02.632849Z","iopub.status.idle":"2022-07-30T15:15:02.899245Z","shell.execute_reply.started":"2022-07-30T15:15:02.632785Z","shell.execute_reply":"2022-07-30T15:15:02.897857Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['firstname'].fillna('missing',inplace=True)\ntrain['lastname'].fillna('missing',inplace=True)\nfor i in range(train.shape[0]):\n    if train.iloc[i,16]=='missing':\n        if train.iloc[i,13]==train.iloc[(i-1),13]:\n            train.iloc[i,16]=train.iloc[(i-1),16]\n        elif train.iloc[i,13]==train.iloc[(i+1),13]:\n            train.iloc[i,16]=train.iloc[(i+1),16]","metadata":{"execution":{"iopub.status.busy":"2022-07-30T15:15:02.904293Z","iopub.execute_input":"2022-07-30T15:15:02.904679Z","iopub.status.idle":"2022-07-30T15:15:03.249199Z","shell.execute_reply.started":"2022-07-30T15:15:02.904650Z","shell.execute_reply":"2022-07-30T15:15:03.247890Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test['firstname'].fillna('missing',inplace=True)\ntest['lastname'].fillna('missing',inplace=True)\nfor i in range(test.shape[0]):\n    if test.iloc[i,15]=='missing':\n        if test.iloc[i,12]==test.iloc[(i-1),12]:\n            test.iloc[i,15]=test.iloc[(i-1),15]\n        elif test.iloc[i,12]==test.iloc[(i+1),12]:\n            test.iloc[i,15]=test.iloc[(i+1),15]","metadata":{"execution":{"iopub.status.busy":"2022-07-30T15:15:03.250573Z","iopub.execute_input":"2022-07-30T15:15:03.250996Z","iopub.status.idle":"2022-07-30T15:15:03.424786Z","shell.execute_reply.started":"2022-07-30T15:15:03.250959Z","shell.execute_reply":"2022-07-30T15:15:03.423595Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Use numbers to represent different categories","metadata":{}},{"cell_type":"code","source":"#To plot the pie chart of HomePlanet and Destination, we do dummies later\n#train=pd.get_dummies(train,columns=['HomePlanet','Destination'])\n#test=pd.get_dummies(test,columns=['HomePlanet','Destination'])","metadata":{"execution":{"iopub.status.busy":"2022-07-30T15:15:03.428007Z","iopub.execute_input":"2022-07-30T15:15:03.428381Z","iopub.status.idle":"2022-07-30T15:15:03.434294Z","shell.execute_reply.started":"2022-07-30T15:15:03.428349Z","shell.execute_reply":"2022-07-30T15:15:03.432891Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def ABC(x):\n    if x == 'A':\n        return 1\n    elif x=='B':\n        return 2\n    elif x=='C':\n        return 3\n    elif x=='D':\n        return 4\n    elif x=='E':\n        return 5\n    elif x=='F':\n        return 6\n    elif x=='G':\n        return 7\n    elif x=='T':\n        return 8\n   ","metadata":{"execution":{"iopub.status.busy":"2022-07-30T15:15:03.435704Z","iopub.execute_input":"2022-07-30T15:15:03.436129Z","iopub.status.idle":"2022-07-30T15:15:03.454141Z","shell.execute_reply.started":"2022-07-30T15:15:03.436046Z","shell.execute_reply":"2022-07-30T15:15:03.452739Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['Cabin_side'].replace('P',0,inplace=True)\ntrain['Cabin_side'].replace('S',1,inplace=True)\ntest['Cabin_side'].replace('P',0,inplace=True)\ntest['Cabin_side'].replace('S',1,inplace=True)\n\ntrain['Cabin_desk']=train['Cabin_desk'].map(ABC)\ntest['Cabin_desk']=test['Cabin_desk'].map(ABC)","metadata":{"execution":{"iopub.status.busy":"2022-07-30T15:15:03.456047Z","iopub.execute_input":"2022-07-30T15:15:03.456390Z","iopub.status.idle":"2022-07-30T15:15:03.495857Z","shell.execute_reply.started":"2022-07-30T15:15:03.456360Z","shell.execute_reply":"2022-07-30T15:15:03.494381Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Since the dataframe is sort by PassengerId, and the next person is usually a family member or friend of the person at the front. So we use 'bfill' to fill in object variables(variables about seat, destination and so on), which are always similar to their friend.","metadata":{}},{"cell_type":"code","source":"train['VIP'].replace('nan', 0, inplace=True)\ntest['VIP'].replace('nan', 0, inplace=True)\n\ntrain['CryoSleep'].replace('nan', 0, inplace=True)\ntest['CryoSleep'].replace('nan', 0, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-30T15:15:03.497976Z","iopub.execute_input":"2022-07-30T15:15:03.498568Z","iopub.status.idle":"2022-07-30T15:15:03.528707Z","shell.execute_reply.started":"2022-07-30T15:15:03.498521Z","shell.execute_reply":"2022-07-30T15:15:03.527774Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for columns in train.columns:\n    if train[columns].dtype==object:\n        train[columns].fillna(method='bfill',inplace=True)\n    else:\n        train[columns].fillna(train[columns].mean(),inplace=True)\n        \nfor columns in test.columns:\n    if test[columns].dtype==object:\n        test[columns].fillna(method='bfill',inplace=True)\n    else:\n        test[columns].fillna(test[columns].mean(),inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-30T15:15:03.529901Z","iopub.execute_input":"2022-07-30T15:15:03.531069Z","iopub.status.idle":"2022-07-30T15:15:03.573910Z","shell.execute_reply.started":"2022-07-30T15:15:03.531018Z","shell.execute_reply":"2022-07-30T15:15:03.572611Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\ntrain['Cabin_num'].fillna(method='bfill',inplace=True)\ntrain['Cabin_num']=train['Cabin_num'].astype(int)\ntrain['Cabin_desk']=train['Cabin_desk'].astype(int)\ntrain['Cabin_side']=train['Cabin_side'].astype(int)\n\ntest['Cabin_num'].fillna(method='bfill',inplace=True)\ntest['Cabin_num']=test['Cabin_num'].astype(int)\ntest['Cabin_desk']=test['Cabin_desk'].astype(int)\ntest['Cabin_side']=test['Cabin_side'].astype(int)","metadata":{"execution":{"iopub.status.busy":"2022-07-30T15:15:03.576534Z","iopub.execute_input":"2022-07-30T15:15:03.577205Z","iopub.status.idle":"2022-07-30T15:15:03.599287Z","shell.execute_reply.started":"2022-07-30T15:15:03.577154Z","shell.execute_reply":"2022-07-30T15:15:03.598027Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Cabin_num may be given according to the location of the seat, we can divide them into 4 different zone.","metadata":{}},{"cell_type":"code","source":"def LOC(x):\n    if x <= 450:\n        return 0\n    elif 450 < x <=900:\n        return 1\n    elif 900 < x <= 1350:\n        return 2\n    elif x>1350:\n        return 3\n  ","metadata":{"execution":{"iopub.status.busy":"2022-07-30T15:15:03.602512Z","iopub.execute_input":"2022-07-30T15:15:03.602919Z","iopub.status.idle":"2022-07-30T15:15:03.610369Z","shell.execute_reply.started":"2022-07-30T15:15:03.602885Z","shell.execute_reply":"2022-07-30T15:15:03.609108Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['Cabin_zone']=train['Cabin_num'].map(LOC)\ntest['Cabin_zone']=test['Cabin_num'].map(LOC)","metadata":{"execution":{"iopub.status.busy":"2022-07-30T15:15:03.611879Z","iopub.execute_input":"2022-07-30T15:15:03.612753Z","iopub.status.idle":"2022-07-30T15:15:03.634025Z","shell.execute_reply.started":"2022-07-30T15:15:03.612715Z","shell.execute_reply":"2022-07-30T15:15:03.633124Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# EDA","metadata":{}},{"cell_type":"markdown","source":"Now, let's summarize the meaning of each columns:\n* PassengerId(unique)\n* CryoSleep: Indicates whether the passenger elected to be put into suspended animation for the duration of the voyage.(0:False,1:True)\n* Age\n* VIP: Whether the passenger has paid for special VIP service during the voyage.(0:False,1:True)\n* RoomService, FoodCourt, ShoppingMall, Spa, VRDeck: Amount the passenger has billed at each of the Spaceship Titanic's many luxury amenities.\n* Cabin_desk: which desk the passenger was in. (change alphabet to number)\n* Cabin_num: the cabin number.\n* Cabin_side: which side the passenger was in,P for Port or S for Starboard.(0:P,1:S)\n* HomePlanet_Earth, HomePlanet_Europa, HomePlanet_Mars: One-Hot encoding of the planet the passenger departed from.\n* Destination_55 Cancri e, Destination_PSO J318.5-22, Destination_TRAPPIST-1e: One-Hot encoding of the planet the passenger will be debarking to.","metadata":{}},{"cell_type":"code","source":"temp=dict(layout=go.Layout(font=dict(family=\"Franklin Gothic\", size=12), \n                           height=500, width=1000))","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-07-30T15:15:03.635138Z","iopub.execute_input":"2022-07-30T15:15:03.635474Z","iopub.status.idle":"2022-07-30T15:15:03.654438Z","shell.execute_reply.started":"2022-07-30T15:15:03.635443Z","shell.execute_reply":"2022-07-30T15:15:03.652957Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.style.use('ggplot')\nf, (ax1, ax2,ax3) = plt.subplots(1,3,figsize=(75, 25),dpi=100)\nax1.boxplot(x = train['Age'])\nax1.set_title('Overall Distribution',fontsize=30)\nax1.tick_params(labelsize=30)\n\ndf=train.loc[train['Transported']==0,:]\nax2.boxplot(x = df['Age'])\nax2.set_title('Not Transported Distribution',fontsize=30)\nax2.tick_params(labelsize=30)\n\ndf=train.loc[train['Transported']==1,:]\nax3.boxplot(x = df['Age'])\nax3.set_title('Transported Distribution',fontsize=30)\nax3.tick_params(labelsize=30)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-07-30T15:15:03.656273Z","iopub.execute_input":"2022-07-30T15:15:03.656731Z","iopub.status.idle":"2022-07-30T15:15:04.926476Z","shell.execute_reply.started":"2022-07-30T15:15:03.656694Z","shell.execute_reply":"2022-07-30T15:15:04.925102Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Most of the passengers are young adults in their 20s and 30s, and there are very few children and elderly among the passengers. The age distribution of all passengers, not transported passengers and transported passengers are very similar, whether transported or not may has nothing to do with age.","metadata":{}},{"cell_type":"code","source":"target=train.Transported.value_counts(normalize=True)\ntarget.rename(index={1:'True',0:'False'},inplace=True)\npal, color=['aliceblue','mistyrose','cornsilk','honeydew','plum'], ['skyblue','salmon','gold','darkseagreen','blueviolet']\nfig=go.Figure()\nfig.add_trace(go.Pie(labels=target.index, values=target*100, hole=.45, \n                     showlegend=True,sort=False, \n                     marker=dict(colors=color,line=dict(color=pal,width=2.5)),\n                     hovertemplate = \"%{label} Accounts: %{value:.2f}%<extra></extra>\"))\nfig.update_layout(template=temp, title='Transport state Distribution', \n                  legend=dict(traceorder='reversed',y=1.05,x=0),\n                  uniformtext_minsize=15, uniformtext_mode='hide',width=700)\nfig.show()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-07-30T15:15:04.930048Z","iopub.execute_input":"2022-07-30T15:15:04.930428Z","iopub.status.idle":"2022-07-30T15:15:04.956359Z","shell.execute_reply.started":"2022-07-30T15:15:04.930396Z","shell.execute_reply":"2022-07-30T15:15:04.955467Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"The number of passengers who have been transported to another dimension is almost the same as those who haven't been.","metadata":{}},{"cell_type":"code","source":"target=train.VIP.value_counts(normalize=True)\ntarget.rename(index={1:'True',0:'False'},inplace=True)\npal, color=['aliceblue','cornsilk','honeydew','plum'], ['skyblue','gold','darkseagreen','blueviolet']\nfig=go.Figure()\nfig.add_trace(go.Pie(labels=target.index, values=target*100, hole=.45, \n                     showlegend=True,sort=False, \n                     marker=dict(colors=color,line=dict(color=pal,width=2.5)),\n                     hovertemplate = \"%{label} Accounts: %{value:.2f}%<extra></extra>\"))\nfig.update_layout(template=temp, title='VIP Distribution', \n                  legend=dict(traceorder='reversed',y=1.05,x=0),\n                  uniformtext_minsize=15, uniformtext_mode='hide',width=700)\nfig.show()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-07-30T15:15:04.957605Z","iopub.execute_input":"2022-07-30T15:15:04.958681Z","iopub.status.idle":"2022-07-30T15:15:04.981958Z","shell.execute_reply.started":"2022-07-30T15:15:04.958645Z","shell.execute_reply":"2022-07-30T15:15:04.980652Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Most of the passengers are NOT VIP, only 2.29% of them are VIP.","metadata":{}},{"cell_type":"code","source":"target=train.loc[:,['VIP','Transported']]\ntarget['Transported']=target['Transported'].astype(object)\ntarget['VIP']=target['VIP'].astype(object)\ntarget=pd.get_dummies(target,columns=['Transported'])\ntarget=target.groupby('VIP',as_index=False).agg('sum')\npal, color=['aliceblue','mistyrose','cornsilk','honeydew','plum'], ['skyblue','salmon','gold','darkseagreen','blueviolet']\nrgb=['rgba'+str(matplotlib.colors.to_rgba(i,0.7)) for i in pal]\nfig=go.Figure()\nfig.add_trace(go.Bar(x=target.VIP, y=target.Transported_1, name='True',\n                     text=target.Transported_1, texttemplate='%{text:.0f}', \n                     textposition='inside',insidetextanchor=\"middle\",\n                     marker=dict(color=color[0],line=dict(color=pal[0],width=1.5)),\n                     hovertemplate = \"<b>%{x}</b><br>True accounts: %{y:.2f}\"))\nfig.add_trace(go.Bar(x=target.VIP, y=target.Transported_0, name='False',\n                     text=target.Transported_0, texttemplate='%{text:.0f}', \n                     textposition='inside',insidetextanchor=\"middle\",\n                     marker=dict(color=color[2],line=dict(color=pal[2],width=1.5)),\n                     hovertemplate = \"<b>%{x}</b><br>False accounts: %{y:.2f}\"))\nfig.update_layout(template=temp,title='Distribution of Transported', \n                  barmode='relative', width=1400,\n                  legend=dict(orientation=\"h\", traceorder=\"reversed\", yanchor=\"bottom\",y=1.1,xanchor=\"left\", x=0))\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-30T15:15:04.983496Z","iopub.execute_input":"2022-07-30T15:15:04.984312Z","iopub.status.idle":"2022-07-30T15:15:05.026448Z","shell.execute_reply.started":"2022-07-30T15:15:04.984276Z","shell.execute_reply":"2022-07-30T15:15:05.025350Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"target=train.CryoSleep.value_counts(normalize=True)\ntarget.rename(index={1:'True',0:'False'},inplace=True)\npal, color=['seashell','aliceblue','mistyrose','cornsilk','honeydew','plum'], ['sandybrown','skyblue','salmon','gold','darkseagreen','blueviolet']\nfig=go.Figure()\nfig.add_trace(go.Pie(labels=target.index, values=target*100, hole=.45, \n                     showlegend=True,sort=False, \n                     marker=dict(colors=color,line=dict(color=pal,width=2.5)),\n                     hovertemplate = \"%{label} Accounts: %{value:.2f}%<extra></extra>\"))\nfig.update_layout(template=temp, title='CryoSleep Distribution', \n                  legend=dict(traceorder='reversed',y=1.05,x=0),\n                  uniformtext_minsize=15, uniformtext_mode='hide',width=700)\nfig.show()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-07-30T15:15:05.028106Z","iopub.execute_input":"2022-07-30T15:15:05.028437Z","iopub.status.idle":"2022-07-30T15:15:05.053501Z","shell.execute_reply.started":"2022-07-30T15:15:05.028403Z","shell.execute_reply":"2022-07-30T15:15:05.052441Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Many people are elected to be put into suspended animation, which is almost twice as many as those who are not elected.","metadata":{}},{"cell_type":"code","source":"target=train.loc[:,['CryoSleep','Transported']]\ntarget['Transported']=target['Transported'].astype(object)\ntarget['CryoSleep']=target['CryoSleep'].astype(object)\ntarget=pd.get_dummies(target,columns=['Transported'])\ntarget=target.groupby('CryoSleep',as_index=False).agg('sum')\n\nrgb=['rgba'+str(matplotlib.colors.to_rgba(i,0.7)) for i in pal]\nfig=go.Figure()\nfig.add_trace(go.Bar(x=target.CryoSleep, y=target.Transported_1, name='True',\n                     text=target.Transported_1, texttemplate='%{text:.0f}', \n                     textposition='inside',insidetextanchor=\"middle\",\n                     marker=dict(color=color[4],line=dict(color=pal[4],width=1.5)),\n                     hovertemplate = \"<b>%{x}</b><br>True accounts: %{y:.2f}\"))\nfig.add_trace(go.Bar(x=target.CryoSleep, y=target.Transported_0, name='False',\n                     text=target.Transported_0, texttemplate='%{text:.0f}', \n                     textposition='inside',insidetextanchor=\"middle\",\n                     marker=dict(color=color[3],line=dict(color=pal[3],width=1.5)),\n                     hovertemplate = \"<b>%{x}</b><br>False accounts: %{y:.2f}\"))\nfig.update_layout(template=temp,title='Distribution of Transported', \n                  barmode='relative', width=1400,\n                  legend=dict(orientation=\"h\", traceorder=\"reversed\", yanchor=\"bottom\",y=1.1,xanchor=\"left\", x=0))\nfig.show()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-07-30T15:15:05.054675Z","iopub.execute_input":"2022-07-30T15:15:05.055484Z","iopub.status.idle":"2022-07-30T15:15:05.097209Z","shell.execute_reply.started":"2022-07-30T15:15:05.055448Z","shell.execute_reply":"2022-07-30T15:15:05.095967Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":" Passengers who choose to be CryoSleep  are more likely to be sent to another dimension.","metadata":{}},{"cell_type":"code","source":"target=train.HomePlanet.value_counts(normalize=True)\ntarget.rename(index={1:'True',0:'False'},inplace=True)\npal, color=['aliceblue','mistyrose','cornsilk','honeydew','plum'], ['skyblue','salmon','gold','darkseagreen','blueviolet']\nfig=go.Figure()\nfig.add_trace(go.Pie(labels=target.index, values=target*100, hole=.45, \n                     showlegend=True,sort=False, \n                     marker=dict(colors=color,line=dict(color=pal,width=2.5)),\n                     hovertemplate = \"%{label} Accounts: %{value:.2f}%<extra></extra>\"))\nfig.update_layout(template=temp, title='HomePlanet Distribution', \n                  legend=dict(traceorder='reversed',y=1.05,x=0),\n                  uniformtext_minsize=15, uniformtext_mode='hide',width=700)\nfig.show()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-07-30T15:15:05.098999Z","iopub.execute_input":"2022-07-30T15:15:05.099476Z","iopub.status.idle":"2022-07-30T15:15:05.129495Z","shell.execute_reply.started":"2022-07-30T15:15:05.099430Z","shell.execute_reply":"2022-07-30T15:15:05.128288Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"target=train.loc[:,['HomePlanet','Transported']]\ntarget['Transported']=target['Transported'].astype(object)\ntarget=pd.get_dummies(target,columns=['Transported'])\ntarget=target.groupby('HomePlanet',as_index=False).agg('sum')\n\npal, color=['seashell','aliceblue','mistyrose','cornsilk','honeydew','plum'], ['sandybrown','skyblue','salmon','gold','darkseagreen','blueviolet']\nrgb=['rgba'+str(matplotlib.colors.to_rgba(i,0.7)) for i in pal]\nfig=go.Figure()\nfig.add_trace(go.Bar(x=target.HomePlanet, y=target.Transported_1, name='True',\n                     text=target.Transported_1, texttemplate='%{text:.0f}', \n                     textposition='inside',insidetextanchor=\"middle\",\n                     marker=dict(color=color[5],line=dict(color=pal[5],width=1.5)),\n                     hovertemplate = \"<b>%{x}</b><br>True accounts: %{y:.2f}\"))\nfig.add_trace(go.Bar(x=target.HomePlanet, y=target.Transported_0, name='False',\n                     text=target.Transported_0, texttemplate='%{text:.0f}', \n                     textposition='inside',insidetextanchor=\"middle\",\n                     marker=dict(color=color[3],line=dict(color=pal[3],width=1.5)),\n                     hovertemplate = \"<b>%{x}</b><br>False accounts: %{y:.2f}\"))\nfig.update_layout(template=temp,title='Distribution of Transported', \n                  barmode='relative', width=1400,\n                  legend=dict(orientation=\"h\", traceorder=\"reversed\", yanchor=\"bottom\",y=1.1,xanchor=\"left\", x=0))\nfig.show()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-07-30T15:15:05.131548Z","iopub.execute_input":"2022-07-30T15:15:05.132948Z","iopub.status.idle":"2022-07-30T15:15:05.175404Z","shell.execute_reply.started":"2022-07-30T15:15:05.132895Z","shell.execute_reply":"2022-07-30T15:15:05.174434Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"The probability that a person from Europe will be transport is the highest among all, which is 66%.","metadata":{}},{"cell_type":"code","source":"target=train.Destination.value_counts(normalize=True)\ntarget.rename(index={1:'True',0:'False'},inplace=True)\npal, color=['aliceblue','cornsilk','honeydew','plum'], ['skyblue','gold','darkseagreen','blueviolet']\nfig=go.Figure()\nfig.add_trace(go.Pie(labels=target.index, values=target*100, hole=.45, \n                     showlegend=True,sort=False, \n                     marker=dict(colors=color,line=dict(color=pal,width=2.5)),\n                     hovertemplate = \"%{label} Accounts: %{value:.2f}%<extra></extra>\"))\nfig.update_layout(template=temp, title='Destination Distribution', \n                  legend=dict(traceorder='reversed',y=1.05,x=0),\n                  uniformtext_minsize=15, uniformtext_mode='hide',width=700)\nfig.show()\n","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-07-30T15:15:05.176533Z","iopub.execute_input":"2022-07-30T15:15:05.177154Z","iopub.status.idle":"2022-07-30T15:15:05.205780Z","shell.execute_reply.started":"2022-07-30T15:15:05.177114Z","shell.execute_reply":"2022-07-30T15:15:05.204275Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"target=train.loc[:,['Destination','Transported']]\ntarget['Transported']=target['Transported'].astype(object)\ntarget=pd.get_dummies(target,columns=['Transported'])\ntarget=target.groupby('Destination',as_index=False).agg('sum')\n\n\npal, color=['seashell','aliceblue','mistyrose','cornsilk','honeydew','plum'], ['sandybrown','skyblue','salmon','gold','darkseagreen','blueviolet']\nrgb=['rgba'+str(matplotlib.colors.to_rgba(i,0.7)) for i in pal]\nfig=go.Figure()\nfig.add_trace(go.Bar(x=target.Destination, y=target.Transported_1, name='True',\n                     text=target.Transported_1, texttemplate='%{text:.0f}', \n                     textposition='inside',insidetextanchor=\"middle\",\n                     marker=dict(color=color[2],line=dict(color=pal[2],width=1.5)),\n                     hovertemplate = \"<b>%{x}</b><br>True accounts: %{y:.2f}\"))\nfig.add_trace(go.Bar(x=target.Destination, y=target.Transported_0, name='False',\n                     text=target.Transported_0, texttemplate='%{text:.0f}', \n                     textposition='inside',insidetextanchor=\"middle\",\n                     marker=dict(color=color[0],line=dict(color=pal[0],width=1.5)),\n                     hovertemplate = \"<b>%{x}</b><br>False accounts: %{y:.2f}\"))\nfig.update_layout(template=temp,title='Distribution of Transported', \n                  barmode='relative', width=1400,\n                  legend=dict(orientation=\"h\", traceorder=\"reversed\", yanchor=\"bottom\",y=1.1,xanchor=\"left\", x=0))\nfig.show()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-07-30T15:15:05.210638Z","iopub.execute_input":"2022-07-30T15:15:05.211488Z","iopub.status.idle":"2022-07-30T15:15:05.257567Z","shell.execute_reply.started":"2022-07-30T15:15:05.211431Z","shell.execute_reply":"2022-07-30T15:15:05.256246Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"The probability of 55Cancri e is a litte bit higher than others as well as overall probability, which is 61%.","metadata":{}},{"cell_type":"code","source":"train=pd.get_dummies(train,columns=['HomePlanet','Destination'])\ntest=pd.get_dummies(test,columns=['HomePlanet','Destination'])","metadata":{"execution":{"iopub.status.busy":"2022-07-30T15:15:05.259025Z","iopub.execute_input":"2022-07-30T15:15:05.259592Z","iopub.status.idle":"2022-07-30T15:15:05.287002Z","shell.execute_reply.started":"2022-07-30T15:15:05.259558Z","shell.execute_reply":"2022-07-30T15:15:05.285563Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"target=train.loc[:,['Cabin_desk','Transported']]\ntarget['Transported']=target['Transported'].astype(object)\ntarget=pd.get_dummies(target,columns=['Transported'])\ntarget=target.groupby('Cabin_desk',as_index=False).agg('sum')","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-07-30T15:15:05.289697Z","iopub.execute_input":"2022-07-30T15:15:05.290381Z","iopub.status.idle":"2022-07-30T15:15:05.310065Z","shell.execute_reply.started":"2022-07-30T15:15:05.290345Z","shell.execute_reply":"2022-07-30T15:15:05.308435Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pal, color=['seashell','aliceblue','mistyrose','cornsilk','honeydew','plum'], ['sandybrown','skyblue','salmon','gold','darkseagreen','blueviolet']\nrgb=['rgba'+str(matplotlib.colors.to_rgba(i,0.7)) for i in pal]\nfig=go.Figure()\nfig.add_trace(go.Bar(x=target.Cabin_desk, y=target.Transported_1, name='True',\n                     text=target.Transported_1, texttemplate='%{text:.0f}', \n                     textposition='inside',insidetextanchor=\"middle\",\n                     marker=dict(color=color[5],line=dict(color=pal[5],width=1.5)),\n                     hovertemplate = \"<b>%{x}</b><br>True accounts: %{y:.2f}\"))\nfig.add_trace(go.Bar(x=target.Cabin_desk, y=target.Transported_0, name='False',\n                     text=target.Transported_0, texttemplate='%{text:.0f}', \n                     textposition='inside',insidetextanchor=\"middle\",\n                     marker=dict(color=color[3],line=dict(color=pal[3],width=1.5)),\n                     hovertemplate = \"<b>%{x}</b><br>False accounts: %{y:.2f}\"))\nfig.update_layout(template=temp,title='Distribution of Transported in different Cabin_desk', \n                  barmode='relative', width=1400,\n                  legend=dict(orientation=\"h\", traceorder=\"reversed\", yanchor=\"bottom\",y=1.1,xanchor=\"left\", x=0))\nfig.show()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-07-30T15:15:05.311693Z","iopub.execute_input":"2022-07-30T15:15:05.312539Z","iopub.status.idle":"2022-07-30T15:15:05.344536Z","shell.execute_reply.started":"2022-07-30T15:15:05.312500Z","shell.execute_reply":"2022-07-30T15:15:05.343391Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"target=train.loc[:,['Cabin_side','Transported']]\ntarget['Transported']=target['Transported'].astype(object)\ntarget['Cabin_side']=target['Cabin_side'].astype(object)\ntarget=pd.get_dummies(target,columns=['Transported'])\ntarget=target.groupby('Cabin_side',as_index=False).agg('sum')\n","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-07-30T15:15:05.345736Z","iopub.execute_input":"2022-07-30T15:15:05.346885Z","iopub.status.idle":"2022-07-30T15:15:05.373960Z","shell.execute_reply.started":"2022-07-30T15:15:05.346839Z","shell.execute_reply":"2022-07-30T15:15:05.372758Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rgb=['rgba'+str(matplotlib.colors.to_rgba(i,0.7)) for i in pal]\nfig=go.Figure()\nfig.add_trace(go.Bar(x=target.Cabin_side, y=target.Transported_1, name='True',\n                     text=target.Transported_1, texttemplate='%{text:.0f}', \n                     textposition='inside',insidetextanchor=\"middle\",\n                     marker=dict(color=color[4],line=dict(color=pal[4],width=1.5)),\n                     hovertemplate = \"<b>%{x}</b><br>True accounts: %{y:.2f}\"))\nfig.add_trace(go.Bar(x=target.Cabin_side, y=target.Transported_0, name='False',\n                     text=target.Transported_0, texttemplate='%{text:.0f}', \n                     textposition='inside',insidetextanchor=\"middle\",\n                     marker=dict(color=color[3],line=dict(color=pal[3],width=1.5)),\n                     hovertemplate = \"<b>%{x}</b><br>False accounts: %{y:.2f}\"))\nfig.update_layout(template=temp,title='Distribution of Transported in different Cabin_side', \n                  barmode='relative', width=1400,\n                  legend=dict(orientation=\"h\", traceorder=\"reversed\", yanchor=\"bottom\",y=1.1,xanchor=\"left\", x=0))\nfig.show()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-07-30T15:15:05.375252Z","iopub.execute_input":"2022-07-30T15:15:05.376194Z","iopub.status.idle":"2022-07-30T15:15:05.408912Z","shell.execute_reply.started":"2022-07-30T15:15:05.376155Z","shell.execute_reply":"2022-07-30T15:15:05.407691Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"target=train.loc[:,['Cabin_zone','Transported']]\ntarget['Transported']=target['Transported'].astype(object)\ntarget=pd.get_dummies(target,columns=['Transported'])","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-07-30T15:15:05.410535Z","iopub.execute_input":"2022-07-30T15:15:05.410961Z","iopub.status.idle":"2022-07-30T15:15:05.437898Z","shell.execute_reply.started":"2022-07-30T15:15:05.410923Z","shell.execute_reply":"2022-07-30T15:15:05.436673Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rgb=['rgba'+str(matplotlib.colors.to_rgba(i,0.7)) for i in pal]\nfig=go.Figure()\nfig.add_trace(go.Bar(x=target.Cabin_zone, y=target.Transported_1, name='True',\n                     text=target.Transported_1, texttemplate='%{text:.0f}', \n                     textposition='inside',insidetextanchor=\"middle\",\n                     marker=dict(color=pal[5],line=dict(color=color[5],width=1.5)),\n                     hovertemplate = \"<b>%{x}</b><br>True accounts: %{y:.2f}\"))\nfig.add_trace(go.Bar(x=target.Cabin_zone, y=target.Transported_0, name='False',\n                     text=target.Transported_0, texttemplate='%{text:.0f}', \n                     textposition='inside',insidetextanchor=\"middle\",\n                     marker=dict(color=pal[3],line=dict(color=color[3],width=1.5)),\n                     hovertemplate = \"<b>%{x}</b><br>False accounts: %{y:.2f}\"))\nfig.update_layout(template=temp,title='Distribution of Transported in different Cabin_zone', \n                  barmode='relative', width=1400,\n                  legend=dict(orientation=\"h\", traceorder=\"reversed\", yanchor=\"bottom\",y=1.1,xanchor=\"left\", x=0))\nfig.show()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-07-30T15:15:05.439470Z","iopub.execute_input":"2022-07-30T15:15:05.439875Z","iopub.status.idle":"2022-07-30T15:15:05.477489Z","shell.execute_reply.started":"2022-07-30T15:15:05.439839Z","shell.execute_reply":"2022-07-30T15:15:05.474623Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"The probabilities that whether a person was transported in every  area(Cabin_num, Cabin_desk, Cabin_zone) are very close (40%~50%), except in Cabin_desk=2,3, the probability is about 70%.","metadata":{}},{"cell_type":"code","source":"Room=train.loc[:,['RoomService','Transported']]\nFood=train.loc[:,['FoodCourt','Transported']]\nshop=train.loc[:,['ShoppingMall','Transported']]\nspa=train.loc[:,['Spa','Transported']]\nvr=train.loc[:,['VRDeck','Transported']]\n\nRoom['consume_state']=0\nRoom.loc[Room['RoomService']>0,['consume_state']]=1\n\nFood['consume_state']=0\nFood.loc[Food['FoodCourt']>0,['consume_state']]=1\n\nshop['consume_state']=0\nshop.loc[shop['ShoppingMall']>0,['consume_state']]=1\n\nspa['consume_state']=0\nspa.loc[spa['Spa']>0,['consume_state']]=1\n\nvr['consume_state']=0\nvr.loc[vr['VRDeck']>0,['consume_state']]=1","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-07-30T15:15:05.479909Z","iopub.execute_input":"2022-07-30T15:15:05.480302Z","iopub.status.idle":"2022-07-30T15:15:05.509456Z","shell.execute_reply.started":"2022-07-30T15:15:05.480267Z","shell.execute_reply":"2022-07-30T15:15:05.508555Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.style.use('ggplot')\nf, (ax1, ax2,ax3,ax4,ax5) = plt.subplots(1, 5,figsize=(20, 10),dpi=100)\na=Room['consume_state'].sum()\nb=len(Room['consume_state'])-a\nax1.pie([a,b],labels=['consume','not consume'],colors=['skyblue','salmon'],autopct='%.1f%%')\nax1.set_title('RoomService')\n\na=Food['consume_state'].sum()\nb=len(Food['consume_state'])-a\nax2.pie([a,b],labels=['consume','not consume'],colors=['skyblue','salmon'],autopct='%.1f%%')\nax2.set_title('FoodCourt')\n\n\na=shop['consume_state'].sum()\nb=len(shop['consume_state'])-a\nax3.pie([a,b],labels=['consume','not consume'],colors=['skyblue','salmon'],autopct='%.1f%%')\nax3.set_title('ShoppingMall')\n\na=spa['consume_state'].sum()\nb=len(spa['consume_state'])-a\nax4.pie([a,b],labels=['consume','not consume'],colors=['skyblue','salmon'],autopct='%.1f%%')\nax4.set_title('SPA')\n\na=vr['consume_state'].sum()\nb=len(vr['consume_state'])-a\nax5.pie([a,b],labels=['consume','not consume'],colors=['skyblue','salmon'],autopct='%.1f%%')\nax5.set_title('VR')","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-07-30T15:15:05.510854Z","iopub.execute_input":"2022-07-30T15:15:05.511462Z","iopub.status.idle":"2022-07-30T15:15:05.970707Z","shell.execute_reply.started":"2022-07-30T15:15:05.511422Z","shell.execute_reply":"2022-07-30T15:15:05.969540Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"The proportions of passengers who choose to spend money on the given luxury amenities was very close.","metadata":{}},{"cell_type":"code","source":"df=pd.concat([Room,Food,shop,spa,vr],axis=1)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-07-30T15:15:05.972985Z","iopub.execute_input":"2022-07-30T15:15:05.973342Z","iopub.status.idle":"2022-07-30T15:15:05.981150Z","shell.execute_reply.started":"2022-07-30T15:15:05.973311Z","shell.execute_reply":"2022-07-30T15:15:05.979548Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['sum']=df.iloc[:,2]+df.iloc[:,5]+df.iloc[:,8]\ndf=df.iloc[:,[0,2,3,5,6,8,9,11,12,13,14,15]]","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-07-30T15:15:05.983526Z","iopub.execute_input":"2022-07-30T15:15:05.984177Z","iopub.status.idle":"2022-07-30T15:15:06.006388Z","shell.execute_reply.started":"2022-07-30T15:15:05.984130Z","shell.execute_reply":"2022-07-30T15:15:06.005335Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.style.use('ggplot')\nf, (ax1, ax2,ax3,ax4,ax5,ax6) = plt.subplots(1, 6,figsize=(30, 20),dpi=100)\na=df.loc[df['sum']==0,'Transported'].sum()\nb=8693-a\nax1.pie([a,b],labels=['True','False'],colors=['skyblue','salmon'],autopct='%.1f%%')\nax1.set_title('0 amenity')\n\na=df.loc[df['sum']==1,'Transported'].sum()\nb=8693-a\nax2.pie([a,b],labels=['True','False'],colors=['skyblue','salmon'],autopct='%.1f%%')\nax2.set_title('1 amenity')\n\na=df.loc[df['sum']==2,'Transported'].sum()\nb=8693-a\nax3.pie([a,b],labels=['True','False'],colors=['skyblue','salmon'],autopct='%.1f%%')\nax3.set_title('2 amenity')\n\na=df.loc[df['sum']==3,'Transported'].sum()\nb=8693-a\nax4.pie([a,b],labels=['True','False'],colors=['skyblue','salmon'],autopct='%.1f%%')\nax4.set_title('3 amenity')\n\na=df.loc[df['sum']==4,'Transported'].sum()\nb=8693-a\nax5.pie([a,b],labels=['True','False'],colors=['skyblue','salmon'],autopct='%.1f%%')\nax5.set_title('4 amenity')\n\na=df.loc[df['sum']==5,'Transported'].sum()\nb=8693-a\nax6.pie([a,b],labels=['True','False'],colors=['skyblue','salmon'],autopct='%.1f%%')\nax6.set_title('5 amenity')","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-07-30T15:15:06.007407Z","iopub.execute_input":"2022-07-30T15:15:06.007751Z","iopub.status.idle":"2022-07-30T15:15:06.578563Z","shell.execute_reply.started":"2022-07-30T15:15:06.007719Z","shell.execute_reply":"2022-07-30T15:15:06.577285Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"The more amenities a person spent, the less likely he will be sent to another dimension. This may be a important variable, add it to the data set.","metadata":{}},{"cell_type":"code","source":"train=pd.concat([train,df['sum']],axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-07-30T15:15:06.580163Z","iopub.execute_input":"2022-07-30T15:15:06.580510Z","iopub.status.idle":"2022-07-30T15:15:06.592629Z","shell.execute_reply.started":"2022-07-30T15:15:06.580471Z","shell.execute_reply":"2022-07-30T15:15:06.591188Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train","metadata":{"execution":{"iopub.status.busy":"2022-07-30T15:15:06.594513Z","iopub.execute_input":"2022-07-30T15:15:06.595018Z","iopub.status.idle":"2022-07-30T15:15:06.651749Z","shell.execute_reply.started":"2022-07-30T15:15:06.594971Z","shell.execute_reply":"2022-07-30T15:15:06.650883Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Delete the data of those who didn't spend mony on them, to see the price distribution of those amenities.","metadata":{}},{"cell_type":"code","source":"Room1=Room.loc[Room['consume_state']>0,:]\nFood1=Food.loc[Food['consume_state']>0,:]\nshop1=shop.loc[shop['consume_state']>0,:]\nspa1=spa.loc[spa['consume_state']>0,:]\nvr1=vr.loc[vr['consume_state']>0,:]\n\nRoom1=Room1.describe().T\nFood1=Food1.describe().T\nshop1=shop1.describe().T\nspa1=spa1.describe().T\nvr1=vr1.describe().T","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-07-30T15:15:06.652738Z","iopub.execute_input":"2022-07-30T15:15:06.653052Z","iopub.status.idle":"2022-07-30T15:15:06.716698Z","shell.execute_reply.started":"2022-07-30T15:15:06.653025Z","shell.execute_reply":"2022-07-30T15:15:06.715656Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df=pd.concat([Room1,Food1,shop1,spa1,vr1],)\ndf","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-07-30T15:15:06.717976Z","iopub.execute_input":"2022-07-30T15:15:06.718496Z","iopub.status.idle":"2022-07-30T15:15:06.749099Z","shell.execute_reply.started":"2022-07-30T15:15:06.718439Z","shell.execute_reply":"2022-07-30T15:15:06.747965Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Here we can see that the distributions of those luxury amenities are not very different, and have very wide range. In the above dataframe, the mean of 'Transported' is equal to the probability that a person will be transported to another dimension, and it's lower than the overall probability.","metadata":{}},{"cell_type":"code","source":"cor=train.corr()\n\nplt.figure(figsize=(10,10))\nsns.heatmap(cor,cmap='coolwarm', vmin=-1, vmax=1, center=0, annot=True, fmt='.2f', \n             annot_kws={'fontsize':10})","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-07-30T15:15:06.752692Z","iopub.execute_input":"2022-07-30T15:15:06.753057Z","iopub.status.idle":"2022-07-30T15:15:08.738569Z","shell.execute_reply.started":"2022-07-30T15:15:06.753027Z","shell.execute_reply":"2022-07-30T15:15:08.737128Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Variables not significantly correlated, except 'cabin_desk' and 'HomePlanet_Europa'. ","metadata":{}}]}