{"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":"#### File and Data Field Descriptions\n\ntrain.csv : Approximately 8700 passengers' personal records from the train.csv file will be used as training data.\n\nPassengerId : Each passenger's individual ID. Each Id has the format gggg pp, where gggg stands for the group the passenger is travelling in and pp stands for their position inside the group. Family members are frequently, but not always, present in a gathering.\n\nHomePlanet : Usually the planet of the passenger's permanent domicile, from which they had just departed.\n\nCryoSleep : If the passenger chose to be put in suspended animation for the duration of the trip, it will be indicated. When in cryosleep, travellers are confined to their cabins.\n\nCabin : The passenger's accommodation's cabin number. consists of the elements deck/num/side, where side can either be P for Port or S for Starboard.\n\nDestination : The planet the passenger will be debarking to.\n\nAge : The age of the passenger.\n\nVIP : Whether the passenger has paid for special VIP service during the voyage.\n\nRoomService, FoodCourt, ShoppingMall, Spa, VRDeck : Amount the passenger has billed at each of the Spaceship Titanic's many luxury amenities.\n\nName : The first and last names of the passenger.\n\nTransported : Whether the passenger was transported to another dimension. This is the target, the column you are trying to predict.\n\ntest.csv : Records for the remaining 4300 passengers, or the remaining third of the passengers, to be utilised as test data. It is your responsibility to determine the value of Transported for each passenger in this set.\n\nsample_submission.csv : A submission file in the correct format.\n\nPassengerId : Id for each passenger in the test set.\n\nTransported : The target. For each passenger, predict either True or False.","metadata":{}},{"cell_type":"markdown","source":"#### decide whether a contestant was transported to a different dimension when the Spaceship Titanic collided with the anomaly in spacetime","metadata":{}},{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport seaborn as sns\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-07-09T16:30:18.537950Z","iopub.execute_input":"2022-07-09T16:30:18.538642Z","iopub.status.idle":"2022-07-09T16:30:18.554897Z","shell.execute_reply.started":"2022-07-09T16:30:18.538605Z","shell.execute_reply":"2022-07-09T16:30:18.553749Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df = pd.read_csv(\"../input/spaceship-titanic/train.csv\")\ntest_df = pd.read_csv(\"../input/spaceship-titanic/test.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:18.639495Z","iopub.execute_input":"2022-07-09T16:30:18.640103Z","iopub.status.idle":"2022-07-09T16:30:18.698758Z","shell.execute_reply.started":"2022-07-09T16:30:18.640069Z","shell.execute_reply":"2022-07-09T16:30:18.697646Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:18.751258Z","iopub.execute_input":"2022-07-09T16:30:18.751913Z","iopub.status.idle":"2022-07-09T16:30:18.776029Z","shell.execute_reply.started":"2022-07-09T16:30:18.751878Z","shell.execute_reply":"2022-07-09T16:30:18.774503Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:18.914523Z","iopub.execute_input":"2022-07-09T16:30:18.915586Z","iopub.status.idle":"2022-07-09T16:30:18.938817Z","shell.execute_reply.started":"2022-07-09T16:30:18.915531Z","shell.execute_reply":"2022-07-09T16:30:18.936916Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.concat([train_df,test_df],axis=0)\ndf.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:19.021618Z","iopub.execute_input":"2022-07-09T16:30:19.022134Z","iopub.status.idle":"2022-07-09T16:30:19.057706Z","shell.execute_reply.started":"2022-07-09T16:30:19.022098Z","shell.execute_reply":"2022-07-09T16:30:19.055860Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Exploratory Data Analysis","metadata":{}},{"cell_type":"code","source":"df.info()","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:19.117722Z","iopub.execute_input":"2022-07-09T16:30:19.118186Z","iopub.status.idle":"2022-07-09T16:30:19.151988Z","shell.execute_reply.started":"2022-07-09T16:30:19.118153Z","shell.execute_reply":"2022-07-09T16:30:19.150596Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.describe()","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:19.228313Z","iopub.execute_input":"2022-07-09T16:30:19.228782Z","iopub.status.idle":"2022-07-09T16:30:19.274209Z","shell.execute_reply.started":"2022-07-09T16:30:19.228739Z","shell.execute_reply":"2022-07-09T16:30:19.272909Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### Name is not useful in analysis","metadata":{}},{"cell_type":"code","source":"df.drop(['Name'],axis =1,inplace = True)\n","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:19.327844Z","iopub.execute_input":"2022-07-09T16:30:19.328240Z","iopub.status.idle":"2022-07-09T16:30:19.336030Z","shell.execute_reply.started":"2022-07-09T16:30:19.328210Z","shell.execute_reply":"2022-07-09T16:30:19.334813Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:19.428663Z","iopub.execute_input":"2022-07-09T16:30:19.429083Z","iopub.status.idle":"2022-07-09T16:30:19.451528Z","shell.execute_reply.started":"2022-07-09T16:30:19.429047Z","shell.execute_reply":"2022-07-09T16:30:19.450439Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def missing (df1):\n    missing_number = df1.isnull().sum().sort_values(ascending=False)\n    missing_percent = ((df1.isnull().sum()/df1.isnull().count())*100).sort_values(ascending=False)\n    missing_values = pd.concat([missing_number, missing_percent], axis=1, keys=['Missing_Number', 'Missing_Percent'])\n    return missing_values","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:19.576420Z","iopub.execute_input":"2022-07-09T16:30:19.576838Z","iopub.status.idle":"2022-07-09T16:30:19.583957Z","shell.execute_reply.started":"2022-07-09T16:30:19.576803Z","shell.execute_reply":"2022-07-09T16:30:19.582503Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"missing(df)","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:19.684930Z","iopub.execute_input":"2022-07-09T16:30:19.685392Z","iopub.status.idle":"2022-07-09T16:30:19.739280Z","shell.execute_reply.started":"2022-07-09T16:30:19.685359Z","shell.execute_reply":"2022-07-09T16:30:19.737907Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### Handling the null values and all the attributes of the Dataset","metadata":{}},{"cell_type":"markdown","source":"#### Handling the Numerical Attributes","metadata":{}},{"cell_type":"code","source":"df['Age'].fillna(df['Age'].mean(),inplace = True)\ndf['RoomService'].fillna(df['RoomService'].mean(),inplace = True)\ndf['FoodCourt'].fillna(df['FoodCourt'].mean(),inplace = True)\ndf['ShoppingMall'].fillna(df['ShoppingMall'].mean(),inplace = True)\ndf['Spa'].fillna(df['Spa'].mean(),inplace = True)\ndf['VRDeck'].fillna(df['VRDeck'].mean(),inplace = True)","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:19.785126Z","iopub.execute_input":"2022-07-09T16:30:19.785554Z","iopub.status.idle":"2022-07-09T16:30:19.800789Z","shell.execute_reply.started":"2022-07-09T16:30:19.785519Z","shell.execute_reply":"2022-07-09T16:30:19.799018Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:19.885626Z","iopub.execute_input":"2022-07-09T16:30:19.886009Z","iopub.status.idle":"2022-07-09T16:30:19.907789Z","shell.execute_reply.started":"2022-07-09T16:30:19.885976Z","shell.execute_reply":"2022-07-09T16:30:19.906717Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### Handling the Categorical Attributes","metadata":{}},{"cell_type":"code","source":"from sklearn.preprocessing import LabelEncoder\nle = LabelEncoder()","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:19.997412Z","iopub.execute_input":"2022-07-09T16:30:19.997800Z","iopub.status.idle":"2022-07-09T16:30:20.003575Z","shell.execute_reply.started":"2022-07-09T16:30:19.997769Z","shell.execute_reply":"2022-07-09T16:30:20.002076Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.HomePlanet.value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:20.126033Z","iopub.execute_input":"2022-07-09T16:30:20.126567Z","iopub.status.idle":"2022-07-09T16:30:20.138848Z","shell.execute_reply.started":"2022-07-09T16:30:20.126531Z","shell.execute_reply":"2022-07-09T16:30:20.137328Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['HomePlanet'].replace(to_replace = np.nan,value = 'Earth',inplace = True)\ndf['HomePlanet'] = le.fit_transform(df['HomePlanet'])\ndf.HomePlanet.value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:20.243809Z","iopub.execute_input":"2022-07-09T16:30:20.244625Z","iopub.status.idle":"2022-07-09T16:30:20.263008Z","shell.execute_reply.started":"2022-07-09T16:30:20.244578Z","shell.execute_reply":"2022-07-09T16:30:20.262147Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.CryoSleep.value_counts()       ","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:20.350364Z","iopub.execute_input":"2022-07-09T16:30:20.351019Z","iopub.status.idle":"2022-07-09T16:30:20.362048Z","shell.execute_reply.started":"2022-07-09T16:30:20.350984Z","shell.execute_reply":"2022-07-09T16:30:20.360899Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.CryoSleep.replace(to_replace = np.nan,value = False,inplace = True)\ndf.CryoSleep = le.fit_transform(df.CryoSleep)\ndf.CryoSleep.value_counts() ","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:20.454018Z","iopub.execute_input":"2022-07-09T16:30:20.455206Z","iopub.status.idle":"2022-07-09T16:30:20.472791Z","shell.execute_reply.started":"2022-07-09T16:30:20.455146Z","shell.execute_reply":"2022-07-09T16:30:20.471450Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:20.554669Z","iopub.execute_input":"2022-07-09T16:30:20.556433Z","iopub.status.idle":"2022-07-09T16:30:20.575190Z","shell.execute_reply.started":"2022-07-09T16:30:20.556384Z","shell.execute_reply":"2022-07-09T16:30:20.573434Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['Cabin'].fillna(df['Cabin'].mode()[0], inplace=True)\n","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:20.660478Z","iopub.execute_input":"2022-07-09T16:30:20.661301Z","iopub.status.idle":"2022-07-09T16:30:20.675853Z","shell.execute_reply.started":"2022-07-09T16:30:20.661260Z","shell.execute_reply":"2022-07-09T16:30:20.674516Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['Cabin'].isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:20.764717Z","iopub.execute_input":"2022-07-09T16:30:20.765354Z","iopub.status.idle":"2022-07-09T16:30:20.774692Z","shell.execute_reply.started":"2022-07-09T16:30:20.765294Z","shell.execute_reply":"2022-07-09T16:30:20.773417Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### PassengerId Handling","metadata":{}},{"cell_type":"code","source":"group_id = []\ngroup_num = []\nfor i in df['PassengerId']:\n    group_id.append(i.split('_')[0])\n    group_num.append(i.split('_')[1])\n    \ndf['group_id'] = pd.DataFrame(group_id)\ndf['group_num'] = pd.DataFrame(group_num)","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:20.866659Z","iopub.execute_input":"2022-07-09T16:30:20.867262Z","iopub.status.idle":"2022-07-09T16:30:20.895323Z","shell.execute_reply.started":"2022-07-09T16:30:20.867227Z","shell.execute_reply":"2022-07-09T16:30:20.894423Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['group_id'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:20.966596Z","iopub.execute_input":"2022-07-09T16:30:20.967224Z","iopub.status.idle":"2022-07-09T16:30:20.983932Z","shell.execute_reply.started":"2022-07-09T16:30:20.967190Z","shell.execute_reply":"2022-07-09T16:30:20.982715Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"deck = []\nnum = []\nside = []\nfor i in df['Cabin']:\n    deck.append(i.split(\"/\")[0])\n    num.append(i.split(\"/\")[1])\n    side.append(i.split(\"/\")[2])\n    \ndf['cabin_deck'] = pd.DataFrame(deck)\ndf['cabin_num'] = pd.DataFrame(num)\ndf['cabin_side'] = pd.DataFrame(side)","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:21.064800Z","iopub.execute_input":"2022-07-09T16:30:21.066131Z","iopub.status.idle":"2022-07-09T16:30:21.104002Z","shell.execute_reply.started":"2022-07-09T16:30:21.066076Z","shell.execute_reply":"2022-07-09T16:30:21.102735Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:21.569690Z","iopub.execute_input":"2022-07-09T16:30:21.571251Z","iopub.status.idle":"2022-07-09T16:30:21.595735Z","shell.execute_reply.started":"2022-07-09T16:30:21.571205Z","shell.execute_reply":"2022-07-09T16:30:21.594361Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['cabin_deck'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:21.598221Z","iopub.execute_input":"2022-07-09T16:30:21.599138Z","iopub.status.idle":"2022-07-09T16:30:21.617441Z","shell.execute_reply.started":"2022-07-09T16:30:21.599094Z","shell.execute_reply":"2022-07-09T16:30:21.615490Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.cabin_deck = le.fit_transform(df.cabin_deck)\ndf.cabin_side = le.fit_transform(df.cabin_side)","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:21.622577Z","iopub.execute_input":"2022-07-09T16:30:21.623277Z","iopub.status.idle":"2022-07-09T16:30:21.640988Z","shell.execute_reply.started":"2022-07-09T16:30:21.623239Z","shell.execute_reply":"2022-07-09T16:30:21.639621Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.cabin_deck.value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:21.644559Z","iopub.execute_input":"2022-07-09T16:30:21.645079Z","iopub.status.idle":"2022-07-09T16:30:21.656117Z","shell.execute_reply.started":"2022-07-09T16:30:21.645029Z","shell.execute_reply":"2022-07-09T16:30:21.654848Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.Destination.value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:21.658288Z","iopub.execute_input":"2022-07-09T16:30:21.659203Z","iopub.status.idle":"2022-07-09T16:30:21.674484Z","shell.execute_reply.started":"2022-07-09T16:30:21.659161Z","shell.execute_reply":"2022-07-09T16:30:21.673099Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.Destination.replace(to_replace = np.nan,value = 'TRAPPIST-1e',inplace = True)\ndf.Destination = le.fit_transform(df.Destination)\ndf.Destination.value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:21.677010Z","iopub.execute_input":"2022-07-09T16:30:21.677427Z","iopub.status.idle":"2022-07-09T16:30:21.697168Z","shell.execute_reply.started":"2022-07-09T16:30:21.677391Z","shell.execute_reply":"2022-07-09T16:30:21.696019Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.VIP.value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:21.754319Z","iopub.execute_input":"2022-07-09T16:30:21.756953Z","iopub.status.idle":"2022-07-09T16:30:21.767956Z","shell.execute_reply.started":"2022-07-09T16:30:21.756905Z","shell.execute_reply":"2022-07-09T16:30:21.766522Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.VIP.replace(to_replace = np.nan,value = False,inplace = True)\ndf.VIP = le.fit_transform(df.VIP)\ndf.VIP.value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:21.854057Z","iopub.execute_input":"2022-07-09T16:30:21.854475Z","iopub.status.idle":"2022-07-09T16:30:21.870487Z","shell.execute_reply.started":"2022-07-09T16:30:21.854441Z","shell.execute_reply":"2022-07-09T16:30:21.869210Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.drop(['Cabin'],axis =1,inplace = True)","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:21.952976Z","iopub.execute_input":"2022-07-09T16:30:21.954151Z","iopub.status.idle":"2022-07-09T16:30:21.966257Z","shell.execute_reply.started":"2022-07-09T16:30:21.954105Z","shell.execute_reply":"2022-07-09T16:30:21.964850Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:22.040111Z","iopub.execute_input":"2022-07-09T16:30:22.040842Z","iopub.status.idle":"2022-07-09T16:30:22.058273Z","shell.execute_reply.started":"2022-07-09T16:30:22.040804Z","shell.execute_reply":"2022-07-09T16:30:22.056581Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.info()","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:22.121427Z","iopub.execute_input":"2022-07-09T16:30:22.122573Z","iopub.status.idle":"2022-07-09T16:30:22.145283Z","shell.execute_reply.started":"2022-07-09T16:30:22.122528Z","shell.execute_reply":"2022-07-09T16:30:22.144174Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:22.203518Z","iopub.execute_input":"2022-07-09T16:30:22.204141Z","iopub.status.idle":"2022-07-09T16:30:22.226235Z","shell.execute_reply.started":"2022-07-09T16:30:22.204105Z","shell.execute_reply":"2022-07-09T16:30:22.225270Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:22.282716Z","iopub.execute_input":"2022-07-09T16:30:22.283098Z","iopub.status.idle":"2022-07-09T16:30:22.290922Z","shell.execute_reply.started":"2022-07-09T16:30:22.283058Z","shell.execute_reply":"2022-07-09T16:30:22.289455Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import seaborn as sns","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:22.394516Z","iopub.execute_input":"2022-07-09T16:30:22.394915Z","iopub.status.idle":"2022-07-09T16:30:22.400512Z","shell.execute_reply.started":"2022-07-09T16:30:22.394884Z","shell.execute_reply":"2022-07-09T16:30:22.398984Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['cabin_num'] = pd.to_numeric(df['cabin_num'])\ndf['group_id'] = pd.to_numeric(df['group_id'])\ndf['group_num'] = pd.to_numeric(df['group_num'])\ndf['Transported'] = pd.to_numeric(df['Transported'])","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:22.465876Z","iopub.execute_input":"2022-07-09T16:30:22.466294Z","iopub.status.idle":"2022-07-09T16:30:22.518811Z","shell.execute_reply.started":"2022-07-09T16:30:22.466259Z","shell.execute_reply":"2022-07-09T16:30:22.517442Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.info()","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:22.533079Z","iopub.execute_input":"2022-07-09T16:30:22.533495Z","iopub.status.idle":"2022-07-09T16:30:22.550476Z","shell.execute_reply.started":"2022-07-09T16:30:22.533461Z","shell.execute_reply":"2022-07-09T16:30:22.549429Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.kdeplot(x='cabin_num', data=df[df['Transported'].notnull()], hue='Transported')","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:22.620706Z","iopub.execute_input":"2022-07-09T16:30:22.621090Z","iopub.status.idle":"2022-07-09T16:30:22.895133Z","shell.execute_reply.started":"2022-07-09T16:30:22.621059Z","shell.execute_reply":"2022-07-09T16:30:22.893996Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.kdeplot(x='cabin_deck', data=df[df['Transported'].notnull()], hue='Transported')","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:22.897009Z","iopub.execute_input":"2022-07-09T16:30:22.897474Z","iopub.status.idle":"2022-07-09T16:30:23.155280Z","shell.execute_reply.started":"2022-07-09T16:30:22.897414Z","shell.execute_reply":"2022-07-09T16:30:23.154044Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.kdeplot(x='cabin_side', data=df[df['Transported'].notnull()], hue='Transported')","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:23.156883Z","iopub.execute_input":"2022-07-09T16:30:23.157229Z","iopub.status.idle":"2022-07-09T16:30:23.436369Z","shell.execute_reply.started":"2022-07-09T16:30:23.157197Z","shell.execute_reply":"2022-07-09T16:30:23.435443Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.kdeplot(x='group_id', data=df[df['Transported'].notnull()], hue='Transported')","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:23.438743Z","iopub.execute_input":"2022-07-09T16:30:23.439637Z","iopub.status.idle":"2022-07-09T16:30:23.715139Z","shell.execute_reply.started":"2022-07-09T16:30:23.439594Z","shell.execute_reply":"2022-07-09T16:30:23.713593Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.kdeplot(x='group_num', data=df[df['Transported'].notnull()], hue='Transported')","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:23.717550Z","iopub.execute_input":"2022-07-09T16:30:23.717992Z","iopub.status.idle":"2022-07-09T16:30:23.997130Z","shell.execute_reply.started":"2022-07-09T16:30:23.717958Z","shell.execute_reply":"2022-07-09T16:30:23.995775Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.kdeplot(x='Age', data=df[df['Transported'].notnull()], hue='Transported')","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:23.999031Z","iopub.execute_input":"2022-07-09T16:30:23.999990Z","iopub.status.idle":"2022-07-09T16:30:24.265325Z","shell.execute_reply.started":"2022-07-09T16:30:23.999945Z","shell.execute_reply":"2022-07-09T16:30:24.264414Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head(2)","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:24.266661Z","iopub.execute_input":"2022-07-09T16:30:24.267189Z","iopub.status.idle":"2022-07-09T16:30:24.288658Z","shell.execute_reply.started":"2022-07-09T16:30:24.267158Z","shell.execute_reply":"2022-07-09T16:30:24.287152Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.preprocessing import StandardScaler\nsc = StandardScaler()","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:24.290269Z","iopub.execute_input":"2022-07-09T16:30:24.290664Z","iopub.status.idle":"2022-07-09T16:30:24.296193Z","shell.execute_reply.started":"2022-07-09T16:30:24.290631Z","shell.execute_reply":"2022-07-09T16:30:24.295110Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['RoomService'] = sc.fit_transform(df[['RoomService']])\ndf['Age'] = sc.fit_transform(df[['Age']])\ndf['FoodCourt'] = sc.fit_transform(df[['FoodCourt']])\ndf['ShoppingMall'] = sc.fit_transform(df[['ShoppingMall']])","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:24.297894Z","iopub.execute_input":"2022-07-09T16:30:24.298525Z","iopub.status.idle":"2022-07-09T16:30:24.325831Z","shell.execute_reply.started":"2022-07-09T16:30:24.298392Z","shell.execute_reply":"2022-07-09T16:30:24.324564Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:24.330476Z","iopub.execute_input":"2022-07-09T16:30:24.330881Z","iopub.status.idle":"2022-07-09T16:30:24.357017Z","shell.execute_reply.started":"2022-07-09T16:30:24.330847Z","shell.execute_reply":"2022-07-09T16:30:24.355706Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.info()","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:24.358895Z","iopub.execute_input":"2022-07-09T16:30:24.360116Z","iopub.status.idle":"2022-07-09T16:30:24.379229Z","shell.execute_reply.started":"2022-07-09T16:30:24.360049Z","shell.execute_reply":"2022-07-09T16:30:24.377413Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:24.380915Z","iopub.execute_input":"2022-07-09T16:30:24.381322Z","iopub.status.idle":"2022-07-09T16:30:24.403091Z","shell.execute_reply.started":"2022-07-09T16:30:24.381287Z","shell.execute_reply":"2022-07-09T16:30:24.402164Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# age,foodcourt,shoppingmall","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:24.404560Z","iopub.execute_input":"2022-07-09T16:30:24.405104Z","iopub.status.idle":"2022-07-09T16:30:24.413853Z","shell.execute_reply.started":"2022-07-09T16:30:24.405071Z","shell.execute_reply":"2022-07-09T16:30:24.412639Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Training the actual model","metadata":{}},{"cell_type":"code","source":"from sklearn.ensemble import RandomForestClassifier","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:24.415227Z","iopub.execute_input":"2022-07-09T16:30:24.415771Z","iopub.status.idle":"2022-07-09T16:30:24.426557Z","shell.execute_reply.started":"2022-07-09T16:30:24.415737Z","shell.execute_reply":"2022-07-09T16:30:24.425552Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = RandomForestClassifier(max_depth = 12, random_state=42)","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:24.427857Z","iopub.execute_input":"2022-07-09T16:30:24.428450Z","iopub.status.idle":"2022-07-09T16:30:24.441380Z","shell.execute_reply.started":"2022-07-09T16:30:24.428412Z","shell.execute_reply":"2022-07-09T16:30:24.439827Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### splitting the data","metadata":{}},{"cell_type":"code","source":"train_df = df[df['Transported'].notnull()]\ntest_df = df[df['Transported'].isnull()]\ntest_df.drop(['Transported'],axis =1 ,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:24.443550Z","iopub.execute_input":"2022-07-09T16:30:24.443939Z","iopub.status.idle":"2022-07-09T16:30:24.460455Z","shell.execute_reply.started":"2022-07-09T16:30:24.443906Z","shell.execute_reply":"2022-07-09T16:30:24.458828Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:24.462550Z","iopub.execute_input":"2022-07-09T16:30:24.463180Z","iopub.status.idle":"2022-07-09T16:30:24.486667Z","shell.execute_reply.started":"2022-07-09T16:30:24.463130Z","shell.execute_reply":"2022-07-09T16:30:24.485416Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_train = train_df.drop(['Transported','PassengerId','group_id','cabin_num','Spa','VRDeck'],axis =1)\ny_train = train_df.Transported\nx_test = test_df.drop(['PassengerId','group_id','cabin_num','Spa','VRDeck'],axis =1)\n","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:24.488185Z","iopub.execute_input":"2022-07-09T16:30:24.489225Z","iopub.status.idle":"2022-07-09T16:30:24.498033Z","shell.execute_reply.started":"2022-07-09T16:30:24.489186Z","shell.execute_reply":"2022-07-09T16:30:24.496752Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_test","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:24.499541Z","iopub.execute_input":"2022-07-09T16:30:24.500778Z","iopub.status.idle":"2022-07-09T16:30:24.530882Z","shell.execute_reply.started":"2022-07-09T16:30:24.500724Z","shell.execute_reply":"2022-07-09T16:30:24.529286Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.fit(x_train,y_train)","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:24.532796Z","iopub.execute_input":"2022-07-09T16:30:24.533176Z","iopub.status.idle":"2022-07-09T16:30:25.342657Z","shell.execute_reply.started":"2022-07-09T16:30:24.533143Z","shell.execute_reply":"2022-07-09T16:30:25.341274Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.score(x_train,y_train)","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:25.344495Z","iopub.execute_input":"2022-07-09T16:30:25.344993Z","iopub.status.idle":"2022-07-09T16:30:25.518907Z","shell.execute_reply.started":"2022-07-09T16:30:25.344944Z","shell.execute_reply":"2022-07-09T16:30:25.517290Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mysubmission = pd.DataFrame(test_df['PassengerId'])","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:25.520586Z","iopub.execute_input":"2022-07-09T16:30:25.520993Z","iopub.status.idle":"2022-07-09T16:30:25.529210Z","shell.execute_reply.started":"2022-07-09T16:30:25.520959Z","shell.execute_reply":"2022-07-09T16:30:25.527146Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mysubmission['Transported'] = model.predict(x_test)","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:25.531132Z","iopub.execute_input":"2022-07-09T16:30:25.532203Z","iopub.status.idle":"2022-07-09T16:30:25.635976Z","shell.execute_reply.started":"2022-07-09T16:30:25.532144Z","shell.execute_reply":"2022-07-09T16:30:25.634448Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mysubmission","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:25.641240Z","iopub.execute_input":"2022-07-09T16:30:25.641723Z","iopub.status.idle":"2022-07-09T16:30:25.659069Z","shell.execute_reply.started":"2022-07-09T16:30:25.641687Z","shell.execute_reply":"2022-07-09T16:30:25.657580Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mysubmission['Transported'] = mysubmission['Transported'].astype(bool)","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:25.661389Z","iopub.execute_input":"2022-07-09T16:30:25.662268Z","iopub.status.idle":"2022-07-09T16:30:25.671154Z","shell.execute_reply.started":"2022-07-09T16:30:25.662213Z","shell.execute_reply":"2022-07-09T16:30:25.669794Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mysubmission","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:25.672660Z","iopub.execute_input":"2022-07-09T16:30:25.672992Z","iopub.status.idle":"2022-07-09T16:30:25.697277Z","shell.execute_reply.started":"2022-07-09T16:30:25.672962Z","shell.execute_reply":"2022-07-09T16:30:25.696256Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mysubmission.to_csv('my_submission.csv', index=False)\nprint(\"Your submission was successfully saved!\")","metadata":{"execution":{"iopub.status.busy":"2022-07-09T16:30:25.698827Z","iopub.execute_input":"2022-07-09T16:30:25.699746Z","iopub.status.idle":"2022-07-09T16:30:25.720682Z","shell.execute_reply.started":"2022-07-09T16:30:25.699696Z","shell.execute_reply":"2022-07-09T16:30:25.719716Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Please upvote to my work if you found it interesting and insightful","metadata":{}},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}