{"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":"importing libraries\n","metadata":{}},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport seaborn as sns\n","metadata":{"execution":{"iopub.status.busy":"2022-08-01T04:00:28.438303Z","iopub.execute_input":"2022-08-01T04:00:28.439530Z","iopub.status.idle":"2022-08-01T04:00:28.445903Z","shell.execute_reply.started":"2022-08-01T04:00:28.439475Z","shell.execute_reply":"2022-08-01T04:00:28.444769Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"loading 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-01T04:00:28.525269Z","iopub.execute_input":"2022-08-01T04:00:28.525689Z","iopub.status.idle":"2022-08-01T04:00:28.532970Z","shell.execute_reply.started":"2022-08-01T04:00:28.525652Z","shell.execute_reply":"2022-08-01T04:00:28.531765Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"reading files\n","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')\n","metadata":{"execution":{"iopub.status.busy":"2022-08-01T04:00:28.599463Z","iopub.execute_input":"2022-08-01T04:00:28.600248Z","iopub.status.idle":"2022-08-01T04:00:28.682529Z","shell.execute_reply.started":"2022-08-01T04:00:28.600208Z","shell.execute_reply":"2022-08-01T04:00:28.681531Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train","metadata":{"execution":{"iopub.status.busy":"2022-08-01T04:00:28.684941Z","iopub.execute_input":"2022-08-01T04:00:28.685731Z","iopub.status.idle":"2022-08-01T04:00:28.729018Z","shell.execute_reply.started":"2022-08-01T04:00:28.685682Z","shell.execute_reply":"2022-08-01T04:00:28.727858Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"analaysing training data set\n","metadata":{}},{"cell_type":"code","source":"train.isnull().sum()  #checking for null(missing) values in the training dataset and grouping by field names","metadata":{"execution":{"iopub.status.busy":"2022-08-01T04:00:28.731002Z","iopub.execute_input":"2022-08-01T04:00:28.731470Z","iopub.status.idle":"2022-08-01T04:00:28.744790Z","shell.execute_reply.started":"2022-08-01T04:00:28.731437Z","shell.execute_reply":"2022-08-01T04:00:28.743937Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_new = train.dropna()  #dropping the null(missing) values from the training data set\ntrain_new","metadata":{"execution":{"iopub.status.busy":"2022-08-01T04:00:28.824865Z","iopub.execute_input":"2022-08-01T04:00:28.825953Z","iopub.status.idle":"2022-08-01T04:00:28.864857Z","shell.execute_reply.started":"2022-08-01T04:00:28.825902Z","shell.execute_reply":"2022-08-01T04:00:28.863337Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_new['Transported'].replace({False: 0, True: 1},inplace=True) \ntrain_new['Transported']\n","metadata":{"execution":{"iopub.status.busy":"2022-08-01T04:00:28.867440Z","iopub.execute_input":"2022-08-01T04:00:28.867906Z","iopub.status.idle":"2022-08-01T04:00:28.889882Z","shell.execute_reply.started":"2022-08-01T04:00:28.867848Z","shell.execute_reply":"2022-08-01T04:00:28.889075Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.displot(train_new['Transported'])","metadata":{"execution":{"iopub.status.busy":"2022-08-01T04:00:28.894820Z","iopub.execute_input":"2022-08-01T04:00:28.895196Z","iopub.status.idle":"2022-08-01T04:00:29.199280Z","shell.execute_reply.started":"2022-08-01T04:00:28.895163Z","shell.execute_reply":"2022-08-01T04:00:29.197941Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transported_count = train_new['Transported'].value_counts()\ntransported_count\n\ntransported_percent = transported_count / len(train_new)\ntransported_percent","metadata":{"execution":{"iopub.status.busy":"2022-08-01T04:00:29.201161Z","iopub.execute_input":"2022-08-01T04:00:29.201524Z","iopub.status.idle":"2022-08-01T04:00:29.212844Z","shell.execute_reply.started":"2022-08-01T04:00:29.201491Z","shell.execute_reply":"2022-08-01T04:00:29.211508Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(25, 7))\nax = plt.subplot()\nax.scatter(train_new[train_new['Transported'] == 1]['Age'], train_new[train['Transported'] == 1]['FoodCourt'], c='green', s=train_new[train_new['Transported'] == 1]['VRDeck'])\nax.scatter(train_new[train_new['Transported'] == 0]['Age'], train_new[train['Transported'] == 0]['FoodCourt'], c='red', s=train_new[train_new['Transported'] == 0]['VRDeck']);","metadata":{"execution":{"iopub.status.busy":"2022-08-01T04:00:29.214624Z","iopub.execute_input":"2022-08-01T04:00:29.215458Z","iopub.status.idle":"2022-08-01T04:00:29.530337Z","shell.execute_reply.started":"2022-08-01T04:00:29.215412Z","shell.execute_reply":"2022-08-01T04:00:29.528940Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"target = train_new['Transported']\n\ntrain_new.drop(['Transported'], axis=1, inplace=True)\n\ntrain_new","metadata":{"execution":{"iopub.status.busy":"2022-08-01T04:00:29.533788Z","iopub.execute_input":"2022-08-01T04:00:29.534628Z","iopub.status.idle":"2022-08-01T04:00:29.569662Z","shell.execute_reply.started":"2022-08-01T04:00:29.534575Z","shell.execute_reply":"2022-08-01T04:00:29.568329Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"combine training and testing data set\n","metadata":{}},{"cell_type":"code","source":"combined = train_new.append(test)\ncombined","metadata":{"execution":{"iopub.status.busy":"2022-08-01T04:00:29.571035Z","iopub.execute_input":"2022-08-01T04:00:29.571859Z","iopub.status.idle":"2022-08-01T04:00:29.608906Z","shell.execute_reply.started":"2022-08-01T04:00:29.571804Z","shell.execute_reply":"2022-08-01T04:00:29.607410Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"combined.describe\n","metadata":{"execution":{"iopub.status.busy":"2022-08-01T04:00:29.610536Z","iopub.execute_input":"2022-08-01T04:00:29.611036Z","iopub.status.idle":"2022-08-01T04:00:29.628869Z","shell.execute_reply.started":"2022-08-01T04:00:29.610993Z","shell.execute_reply":"2022-08-01T04:00:29.627614Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"counting null values\n","metadata":{}},{"cell_type":"code","source":"combined.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-08-01T04:00:29.630348Z","iopub.execute_input":"2022-08-01T04:00:29.630910Z","iopub.status.idle":"2022-08-01T04:00:29.649568Z","shell.execute_reply.started":"2022-08-01T04:00:29.630876Z","shell.execute_reply":"2022-08-01T04:00:29.647308Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"replacing null values(imputing)","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 combined:\n    if combined[col].dtype==\"object\":\n        combined[col].fillna(\"not listed\", inplace=True)\n    if combined[col].dtype==\"int\":\n        combined[col].fillna(combined[col].mean(), inplace=True)\n    if combined[col].dtype=='float':\n       combined[col] = imp.fit_transform(combined[col].values.reshape(-1,1))\n    if combined[col].dtype==\"datetime64[ns]\":\n        combined[col].fillna(date, inplace=True)\ncombined","metadata":{"execution":{"iopub.status.busy":"2022-08-01T04:00:29.651709Z","iopub.execute_input":"2022-08-01T04:00:29.652438Z","iopub.status.idle":"2022-08-01T04:00:29.705183Z","shell.execute_reply.started":"2022-08-01T04:00:29.652395Z","shell.execute_reply":"2022-08-01T04:00:29.703997Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**analysing features**","metadata":{}},{"cell_type":"markdown","source":"Home Planet","metadata":{}},{"cell_type":"code","source":"sns.displot(combined['HomePlanet'])","metadata":{"execution":{"iopub.status.busy":"2022-08-01T04:00:29.706596Z","iopub.execute_input":"2022-08-01T04:00:29.706949Z","iopub.status.idle":"2022-08-01T04:00:29.915463Z","shell.execute_reply.started":"2022-08-01T04:00:29.706919Z","shell.execute_reply":"2022-08-01T04:00:29.914109Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"home_count = combined['HomePlanet'].value_counts()\nhome_count","metadata":{"execution":{"iopub.status.busy":"2022-08-01T04:00:29.918877Z","iopub.execute_input":"2022-08-01T04:00:29.920598Z","iopub.status.idle":"2022-08-01T04:00:29.935540Z","shell.execute_reply.started":"2022-08-01T04:00:29.920523Z","shell.execute_reply":"2022-08-01T04:00:29.933451Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"home_percent = home_count / len(combined)\nhome_percent","metadata":{"execution":{"iopub.status.busy":"2022-08-01T04:03:29.126947Z","iopub.execute_input":"2022-08-01T04:03:29.128060Z","iopub.status.idle":"2022-08-01T04:03:29.137398Z","shell.execute_reply.started":"2022-08-01T04:03:29.128019Z","shell.execute_reply":"2022-08-01T04:03:29.135743Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Cryo sleep","metadata":{}},{"cell_type":"code","source":"combined['CryoSleep'][combined['CryoSleep'] == 'not listed'] = False\n","metadata":{"execution":{"iopub.status.busy":"2022-08-01T04:05:33.622949Z","iopub.execute_input":"2022-08-01T04:05:33.623455Z","iopub.status.idle":"2022-08-01T04:05:33.636333Z","shell.execute_reply.started":"2022-08-01T04:05:33.623415Z","shell.execute_reply":"2022-08-01T04:05:33.634188Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"combined['CryoSleep'].replace({False : 0, True : 1})","metadata":{"execution":{"iopub.status.busy":"2022-08-01T04:09:20.081143Z","iopub.execute_input":"2022-08-01T04:09:20.082065Z","iopub.status.idle":"2022-08-01T04:09:20.095324Z","shell.execute_reply.started":"2022-08-01T04:09:20.082027Z","shell.execute_reply":"2022-08-01T04:09:20.094165Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.distplot(combined['CryoSleep'])","metadata":{"execution":{"iopub.status.busy":"2022-08-01T04:12:54.052173Z","iopub.execute_input":"2022-08-01T04:12:54.052910Z","iopub.status.idle":"2022-08-01T04:12:54.347686Z","shell.execute_reply.started":"2022-08-01T04:12:54.052868Z","shell.execute_reply":"2022-08-01T04:12:54.346876Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cryo_count = combined['CryoSleep'].value_counts()\ncryo_count","metadata":{"execution":{"iopub.status.busy":"2022-08-01T04:21:22.016855Z","iopub.execute_input":"2022-08-01T04:21:22.017406Z","iopub.status.idle":"2022-08-01T04:21:22.029579Z","shell.execute_reply.started":"2022-08-01T04:21:22.017366Z","shell.execute_reply":"2022-08-01T04:21:22.028171Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cryo_percent = cryo_count / len(combined)\ncryo_percent","metadata":{"execution":{"iopub.status.busy":"2022-08-01T04:26:16.900234Z","iopub.execute_input":"2022-08-01T04:26:16.900663Z","iopub.status.idle":"2022-08-01T04:26:16.908929Z","shell.execute_reply.started":"2022-08-01T04:26:16.900634Z","shell.execute_reply":"2022-08-01T04:26:16.908174Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"combined['CryoSleep'] = combined['CryoSleep'].astype(int)\ncombined['CryoSleep']","metadata":{"execution":{"iopub.status.busy":"2022-08-01T04:30:02.728693Z","iopub.execute_input":"2022-08-01T04:30:02.729156Z","iopub.status.idle":"2022-08-01T04:30:02.742066Z","shell.execute_reply.started":"2022-08-01T04:30:02.729122Z","shell.execute_reply":"2022-08-01T04:30:02.740471Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"destination\n","metadata":{}},{"cell_type":"code","source":"destination_count = combined['Destination'].value_counts()\ndestination_count","metadata":{"execution":{"iopub.status.busy":"2022-08-01T04:32:37.023222Z","iopub.execute_input":"2022-08-01T04:32:37.024249Z","iopub.status.idle":"2022-08-01T04:32:37.032528Z","shell.execute_reply.started":"2022-08-01T04:32:37.024211Z","shell.execute_reply":"2022-08-01T04:32:37.031679Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.displot(combined['Destination'])","metadata":{"execution":{"iopub.status.busy":"2022-08-01T04:31:52.055174Z","iopub.execute_input":"2022-08-01T04:31:52.055762Z","iopub.status.idle":"2022-08-01T04:31:52.327469Z","shell.execute_reply.started":"2022-08-01T04:31:52.055729Z","shell.execute_reply":"2022-08-01T04:31:52.326633Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"destination_percent = destination_count / len(combined)\ndestination_percent","metadata":{"execution":{"iopub.status.busy":"2022-08-01T04:33:01.526716Z","iopub.execute_input":"2022-08-01T04:33:01.527287Z","iopub.status.idle":"2022-08-01T04:33:01.536294Z","shell.execute_reply.started":"2022-08-01T04:33:01.527253Z","shell.execute_reply":"2022-08-01T04:33:01.535391Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mylabels = ['TRAPPIST-1e', '55 Cancri e', 'PSO J318.5-22', 'not listed']\nplt.pie(destination_percent, labels=mylabels)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-08-01T04:37:00.304089Z","iopub.execute_input":"2022-08-01T04:37:00.304531Z","iopub.status.idle":"2022-08-01T04:37:00.412415Z","shell.execute_reply.started":"2022-08-01T04:37:00.304499Z","shell.execute_reply":"2022-08-01T04:37:00.410346Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"combined['Destination'].replace({'TRAPPIST-1e': 0,'55 Cancri e':1, 'PSO J318.5-22' : 2, 'not listed:': 3})\ncombined['Destination']","metadata":{"execution":{"iopub.status.busy":"2022-08-01T04:40:06.809079Z","iopub.execute_input":"2022-08-01T04:40:06.809680Z","iopub.status.idle":"2022-08-01T04:40:06.823434Z","shell.execute_reply.started":"2022-08-01T04:40:06.809646Z","shell.execute_reply":"2022-08-01T04:40:06.821684Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"age","metadata":{}},{"cell_type":"markdown","source":"VIP","metadata":{}},{"cell_type":"code","source":"combined['VIP'].value_counts()\n","metadata":{"execution":{"iopub.status.busy":"2022-08-01T04:43:26.078565Z","iopub.execute_input":"2022-08-01T04:43:26.079653Z","iopub.status.idle":"2022-08-01T04:43:26.089072Z","shell.execute_reply.started":"2022-08-01T04:43:26.079599Z","shell.execute_reply":"2022-08-01T04:43:26.088202Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"combined['VIP'].replace({True : 1, False : 0, })","metadata":{"execution":{"iopub.status.busy":"2022-08-01T04:44:12.240075Z","iopub.execute_input":"2022-08-01T04:44:12.240523Z","iopub.status.idle":"2022-08-01T04:44:12.256596Z","shell.execute_reply.started":"2022-08-01T04:44:12.240490Z","shell.execute_reply":"2022-08-01T04:44:12.254726Z"},"trusted":true},"execution_count":null,"outputs":[]}]}