{"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":"# 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)\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-14T12:10:33.138814Z","iopub.execute_input":"2022-07-14T12:10:33.139796Z","iopub.status.idle":"2022-07-14T12:10:33.175802Z","shell.execute_reply.started":"2022-07-14T12:10:33.139666Z","shell.execute_reply":"2022-07-14T12:10:33.174730Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data = pd.read_csv('../input/spaceship-titanic/train.csv')\ntest_data = pd.read_csv('../input/spaceship-titanic/test.csv')","metadata":{"execution":{"iopub.status.busy":"2022-07-14T12:10:33.177517Z","iopub.execute_input":"2022-07-14T12:10:33.177826Z","iopub.status.idle":"2022-07-14T12:10:33.256087Z","shell.execute_reply.started":"2022-07-14T12:10:33.177798Z","shell.execute_reply":"2022-07-14T12:10:33.255213Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.isnull().sum()\ntrain_data = train_data.drop(['Cabin','Name'],axis=1)\ntest_data = test_data.drop(['Cabin','Name'],axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-07-14T12:10:33.257774Z","iopub.execute_input":"2022-07-14T12:10:33.258230Z","iopub.status.idle":"2022-07-14T12:10:33.284680Z","shell.execute_reply.started":"2022-07-14T12:10:33.258200Z","shell.execute_reply":"2022-07-14T12:10:33.283503Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.impute import SimpleImputer\nimputer = SimpleImputer(missing_values=np.nan,strategy='most_frequent')\ntrain_data = pd.DataFrame(imputer.fit_transform(train_data),columns=train_data.columns)\ntest_data = pd.DataFrame(imputer.fit_transform(test_data),columns=test_data.columns)\n","metadata":{"execution":{"iopub.status.busy":"2022-07-14T12:10:33.287526Z","iopub.execute_input":"2022-07-14T12:10:33.288396Z","iopub.status.idle":"2022-07-14T12:10:34.666513Z","shell.execute_reply.started":"2022-07-14T12:10:33.288348Z","shell.execute_reply":"2022-07-14T12:10:34.665171Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data['CryoSleep'] = train_data['CryoSleep'].astype('int')\ntest_data['CryoSleep'] = test_data['CryoSleep'].astype('int')\ntrain_data['VIP'] = train_data['VIP'].astype('int')\ntest_data['VIP'] = test_data['VIP'].astype('int')\ntrain_data['Transported'] = train_data['Transported'].astype('int')\n","metadata":{"execution":{"iopub.status.busy":"2022-07-14T12:10:34.669488Z","iopub.execute_input":"2022-07-14T12:10:34.670225Z","iopub.status.idle":"2022-07-14T12:10:34.690755Z","shell.execute_reply.started":"2022-07-14T12:10:34.670176Z","shell.execute_reply":"2022-07-14T12:10:34.689555Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-14T12:10:34.692659Z","iopub.execute_input":"2022-07-14T12:10:34.693501Z","iopub.status.idle":"2022-07-14T12:10:34.719380Z","shell.execute_reply.started":"2022-07-14T12:10:34.693451Z","shell.execute_reply":"2022-07-14T12:10:34.718115Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data = pd.get_dummies(train_data,columns=['HomePlanet','Destination'])\ntest_data = pd.get_dummies(test_data,columns=['HomePlanet','Destination'])","metadata":{"execution":{"iopub.status.busy":"2022-07-14T12:10:34.720934Z","iopub.execute_input":"2022-07-14T12:10:34.722084Z","iopub.status.idle":"2022-07-14T12:10:34.745705Z","shell.execute_reply.started":"2022-07-14T12:10:34.722018Z","shell.execute_reply":"2022-07-14T12:10:34.744840Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-14T12:10:34.747128Z","iopub.execute_input":"2022-07-14T12:10:34.747728Z","iopub.status.idle":"2022-07-14T12:10:34.760698Z","shell.execute_reply.started":"2022-07-14T12:10:34.747696Z","shell.execute_reply":"2022-07-14T12:10:34.759628Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train = train_data.drop(['Transported'],axis=1)\ny_train = train_data['Transported']\nX_test = test_data","metadata":{"execution":{"iopub.status.busy":"2022-07-14T12:10:34.762592Z","iopub.execute_input":"2022-07-14T12:10:34.763390Z","iopub.status.idle":"2022-07-14T12:10:34.774237Z","shell.execute_reply.started":"2022-07-14T12:10:34.763346Z","shell.execute_reply":"2022-07-14T12:10:34.772858Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.ensemble import RandomForestClassifier\nrf = RandomForestClassifier()\nrf.fit(X_train,y_train)\n","metadata":{"execution":{"iopub.status.busy":"2022-07-14T12:10:34.778651Z","iopub.execute_input":"2022-07-14T12:10:34.779531Z","iopub.status.idle":"2022-07-14T12:10:35.995108Z","shell.execute_reply.started":"2022-07-14T12:10:34.779485Z","shell.execute_reply":"2022-07-14T12:10:35.993787Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred = rf.predict(X_test)\ny_pred = pd.Series(y_pred, name=\"Transported\" )\ny_pred","metadata":{"execution":{"iopub.status.busy":"2022-07-14T12:10:35.997431Z","iopub.execute_input":"2022-07-14T12:10:35.998441Z","iopub.status.idle":"2022-07-14T12:10:36.146324Z","shell.execute_reply.started":"2022-07-14T12:10:35.998358Z","shell.execute_reply":"2022-07-14T12:10:36.145189Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pass = pd.Series(test_data['PassengerId'])\ny_pass","metadata":{"execution":{"iopub.status.busy":"2022-07-14T12:10:36.148193Z","iopub.execute_input":"2022-07-14T12:10:36.149006Z","iopub.status.idle":"2022-07-14T12:10:36.158106Z","shell.execute_reply.started":"2022-07-14T12:10:36.148960Z","shell.execute_reply":"2022-07-14T12:10:36.157274Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred = pd.concat([y_pass,y_pred],axis=1)\ny_pred.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-14T12:10:36.159968Z","iopub.execute_input":"2022-07-14T12:10:36.160754Z","iopub.status.idle":"2022-07-14T12:10:36.174317Z","shell.execute_reply.started":"2022-07-14T12:10:36.160709Z","shell.execute_reply":"2022-07-14T12:10:36.172497Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred[\"Transported\"] = y_pred[\"Transported\"].astype('bool')\ny_pred.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-14T12:12:45.744114Z","iopub.execute_input":"2022-07-14T12:12:45.744588Z","iopub.status.idle":"2022-07-14T12:12:45.752774Z","shell.execute_reply.started":"2022-07-14T12:12:45.744548Z","shell.execute_reply":"2022-07-14T12:12:45.750364Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred.to_csv('submission.csv',index=False)","metadata":{"execution":{"iopub.status.busy":"2022-07-14T12:10:36.176925Z","iopub.execute_input":"2022-07-14T12:10:36.177409Z","iopub.status.idle":"2022-07-14T12:10:36.194267Z","shell.execute_reply.started":"2022-07-14T12:10:36.177360Z","shell.execute_reply":"2022-07-14T12:10:36.193247Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}