{"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\npd.set_option('display.max_columns', None)","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-08-03T16:46:47.853413Z","iopub.execute_input":"2022-08-03T16:46:47.853822Z","iopub.status.idle":"2022-08-03T16:46:47.862311Z","shell.execute_reply.started":"2022-08-03T16:46:47.853791Z","shell.execute_reply":"2022-08-03T16:46:47.860122Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.read_csv(\"../input/tabular-playground-series-aug-2022/train.csv\")\ntest_df = pd.read_csv('../input/tabular-playground-series-aug-2022/test.csv')","metadata":{"execution":{"iopub.status.busy":"2022-08-03T16:46:48.065546Z","iopub.execute_input":"2022-08-03T16:46:48.065989Z","iopub.status.idle":"2022-08-03T16:46:48.280852Z","shell.execute_reply.started":"2022-08-03T16:46:48.065954Z","shell.execute_reply":"2022-08-03T16:46:48.279608Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-03T16:46:48.283155Z","iopub.execute_input":"2022-08-03T16:46:48.283608Z","iopub.status.idle":"2022-08-03T16:46:48.320256Z","shell.execute_reply.started":"2022-08-03T16:46:48.283572Z","shell.execute_reply":"2022-08-03T16:46:48.318551Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.info()","metadata":{"execution":{"iopub.status.busy":"2022-08-03T16:46:48.674233Z","iopub.execute_input":"2022-08-03T16:46:48.674621Z","iopub.status.idle":"2022-08-03T16:46:48.697777Z","shell.execute_reply.started":"2022-08-03T16:46:48.674591Z","shell.execute_reply":"2022-08-03T16:46:48.696722Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cat_columns = ['product_code', 'attribute_0', 'attribute_1']","metadata":{"execution":{"iopub.status.busy":"2022-08-03T16:46:48.877051Z","iopub.execute_input":"2022-08-03T16:46:48.877600Z","iopub.status.idle":"2022-08-03T16:46:48.883838Z","shell.execute_reply.started":"2022-08-03T16:46:48.877562Z","shell.execute_reply":"2022-08-03T16:46:48.882688Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cat_df = df[cat_columns]\nnum_df = df.drop(cat_columns, axis = 1)\n\ncat_test_df = test_df[cat_columns]\nnum_test_df =test_df.drop(cat_columns, axis = 1)\n","metadata":{"execution":{"iopub.status.busy":"2022-08-03T16:47:26.051378Z","iopub.execute_input":"2022-08-03T16:47:26.051797Z","iopub.status.idle":"2022-08-03T16:47:26.067926Z","shell.execute_reply.started":"2022-08-03T16:47:26.051764Z","shell.execute_reply":"2022-08-03T16:47:26.066218Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cat_df.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-03T16:46:49.193343Z","iopub.execute_input":"2022-08-03T16:46:49.193720Z","iopub.status.idle":"2022-08-03T16:46:49.206589Z","shell.execute_reply.started":"2022-08-03T16:46:49.193690Z","shell.execute_reply":"2022-08-03T16:46:49.205294Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cat_df['product_code'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-08-03T16:46:49.553242Z","iopub.execute_input":"2022-08-03T16:46:49.553659Z","iopub.status.idle":"2022-08-03T16:46:49.566069Z","shell.execute_reply.started":"2022-08-03T16:46:49.553625Z","shell.execute_reply":"2022-08-03T16:46:49.564859Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cat_test_df['product_code'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-08-03T16:46:49.718572Z","iopub.execute_input":"2022-08-03T16:46:49.719008Z","iopub.status.idle":"2022-08-03T16:46:49.731551Z","shell.execute_reply.started":"2022-08-03T16:46:49.718973Z","shell.execute_reply":"2022-08-03T16:46:49.730221Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cat_columns.pop(0)\ncat_df = cat_df.drop('product_code', axis=1)\ncat_test_df = cat_test_df.drop('product_code', axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-08-03T16:46:49.950836Z","iopub.execute_input":"2022-08-03T16:46:49.951772Z","iopub.status.idle":"2022-08-03T16:46:49.957296Z","shell.execute_reply.started":"2022-08-03T16:46:49.951731Z","shell.execute_reply":"2022-08-03T16:46:49.955252Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cat_df['attribute_0'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-08-03T16:46:50.188639Z","iopub.execute_input":"2022-08-03T16:46:50.189315Z","iopub.status.idle":"2022-08-03T16:46:50.202125Z","shell.execute_reply.started":"2022-08-03T16:46:50.189261Z","shell.execute_reply":"2022-08-03T16:46:50.200209Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cat_test_df['attribute_0'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-08-03T16:46:50.498822Z","iopub.execute_input":"2022-08-03T16:46:50.499516Z","iopub.status.idle":"2022-08-03T16:46:50.510756Z","shell.execute_reply.started":"2022-08-03T16:46:50.499471Z","shell.execute_reply":"2022-08-03T16:46:50.509009Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cat_df['attribute_1'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-08-03T16:46:50.852855Z","iopub.execute_input":"2022-08-03T16:46:50.853327Z","iopub.status.idle":"2022-08-03T16:46:50.866665Z","shell.execute_reply.started":"2022-08-03T16:46:50.853290Z","shell.execute_reply":"2022-08-03T16:46:50.865271Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cat_test_df['attribute_1'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-08-03T16:46:51.172617Z","iopub.execute_input":"2022-08-03T16:46:51.173209Z","iopub.status.idle":"2022-08-03T16:46:51.187873Z","shell.execute_reply.started":"2022-08-03T16:46:51.173042Z","shell.execute_reply":"2022-08-03T16:46:51.186570Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# cat_columns.pop(1)\n# cat_df = cat_df.drop('attribute_1', axis=1)\n# cat_test_df = cat_test_df.drop('attribute_1', axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-08-03T16:46:51.704358Z","iopub.execute_input":"2022-08-03T16:46:51.704786Z","iopub.status.idle":"2022-08-03T16:46:51.709768Z","shell.execute_reply.started":"2022-08-03T16:46:51.704753Z","shell.execute_reply":"2022-08-03T16:46:51.708700Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.preprocessing import OneHotEncoder\nenc = OneHotEncoder(handle_unknown='ignore')\ncat_df = enc.fit_transform(cat_df).toarray()\ncat_test_df = enc.transform(cat_test_df).toarray()","metadata":{"execution":{"iopub.status.busy":"2022-08-03T16:47:30.511968Z","iopub.execute_input":"2022-08-03T16:47:30.512489Z","iopub.status.idle":"2022-08-03T16:47:30.585908Z","shell.execute_reply.started":"2022-08-03T16:47:30.512454Z","shell.execute_reply":"2022-08-03T16:47:30.584136Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cat_df = pd.DataFrame(cat_df)\ncat_test_df = pd.DataFrame(cat_test_df)","metadata":{"execution":{"iopub.status.busy":"2022-08-03T16:47:37.254150Z","iopub.execute_input":"2022-08-03T16:47:37.254579Z","iopub.status.idle":"2022-08-03T16:47:37.262850Z","shell.execute_reply.started":"2022-08-03T16:47:37.254546Z","shell.execute_reply":"2022-08-03T16:47:37.261634Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.concat([num_df, cat_df], axis=1)\ntest_df = pd.concat([num_test_df, cat_test_df], axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-08-03T16:47:43.616008Z","iopub.execute_input":"2022-08-03T16:47:43.616573Z","iopub.status.idle":"2022-08-03T16:47:43.631732Z","shell.execute_reply.started":"2022-08-03T16:47:43.616536Z","shell.execute_reply":"2022-08-03T16:47:43.630677Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-03T16:47:46.074248Z","iopub.execute_input":"2022-08-03T16:47:46.074786Z","iopub.status.idle":"2022-08-03T16:47:46.120940Z","shell.execute_reply.started":"2022-08-03T16:47:46.074753Z","shell.execute_reply":"2022-08-03T16:47:46.119175Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-03T16:47:54.246870Z","iopub.execute_input":"2022-08-03T16:47:54.247302Z","iopub.status.idle":"2022-08-03T16:47:54.289198Z","shell.execute_reply.started":"2022-08-03T16:47:54.247268Z","shell.execute_reply":"2022-08-03T16:47:54.287482Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y = df['failure']\nx = df.drop('failure', axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-08-03T16:38:36.229577Z","iopub.execute_input":"2022-08-03T16:38:36.230576Z","iopub.status.idle":"2022-08-03T16:38:36.250008Z","shell.execute_reply.started":"2022-08-03T16:38:36.230537Z","shell.execute_reply":"2022-08-03T16:38:36.248901Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\nx_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.20, random_state=42)","metadata":{"execution":{"iopub.status.busy":"2022-08-03T16:38:36.256420Z","iopub.execute_input":"2022-08-03T16:38:36.257141Z","iopub.status.idle":"2022-08-03T16:38:36.272540Z","shell.execute_reply.started":"2022-08-03T16:38:36.257075Z","shell.execute_reply":"2022-08-03T16:38:36.271089Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import xgboost as xgb\nclf = xgb.XGBClassifier()\nclf.fit(x_train, y_train)\nprint(clf.score(x_test, y_test))","metadata":{"execution":{"iopub.status.busy":"2022-08-03T16:59:26.778041Z","iopub.execute_input":"2022-08-03T16:59:26.779022Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred = clf.predict(test_df)","metadata":{"execution":{"iopub.status.busy":"2022-08-03T16:38:36.814904Z","iopub.execute_input":"2022-08-03T16:38:36.815627Z","iopub.status.idle":"2022-08-03T16:38:36.867892Z","shell.execute_reply.started":"2022-08-03T16:38:36.815588Z","shell.execute_reply":"2022-08-03T16:38:36.866929Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"output = pd.DataFrame({'id': test_df.id,\n                       'failure': pred})\noutput.to_csv('submission.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2022-08-03T16:38:36.869852Z","iopub.execute_input":"2022-08-03T16:38:36.870689Z","iopub.status.idle":"2022-08-03T16:38:36.903026Z","shell.execute_reply.started":"2022-08-03T16:38:36.870646Z","shell.execute_reply":"2022-08-03T16:38:36.901732Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}