{"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 matplotlib.pyplot as plt\nimport seaborn as sns","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-08-01T09:25:10.387376Z","iopub.execute_input":"2022-08-01T09:25:10.387838Z","iopub.status.idle":"2022-08-01T09:25:10.393829Z","shell.execute_reply.started":"2022-08-01T09:25:10.387792Z","shell.execute_reply":"2022-08-01T09:25:10.392700Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data = pd.read_csv('../input/tabular-playground-series-aug-2022/train.csv')\ntest_data = pd.read_csv('../input/tabular-playground-series-aug-2022/test.csv')\nsub = pd.read_csv('../input/tabular-playground-series-aug-2022/sample_submission.csv')","metadata":{"execution":{"iopub.status.busy":"2022-08-01T09:25:10.476897Z","iopub.execute_input":"2022-08-01T09:25:10.477366Z","iopub.status.idle":"2022-08-01T09:25:10.707364Z","shell.execute_reply.started":"2022-08-01T09:25:10.477328Z","shell.execute_reply":"2022-08-01T09:25:10.706133Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-08-01T09:25:10.709771Z","iopub.execute_input":"2022-08-01T09:25:10.710163Z","iopub.status.idle":"2022-08-01T09:25:10.730660Z","shell.execute_reply.started":"2022-08-01T09:25:10.710100Z","shell.execute_reply":"2022-08-01T09:25:10.729497Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.info()","metadata":{"execution":{"iopub.status.busy":"2022-08-01T09:25:10.732118Z","iopub.execute_input":"2022-08-01T09:25:10.733000Z","iopub.status.idle":"2022-08-01T09:25:10.759636Z","shell.execute_reply.started":"2022-08-01T09:25:10.732961Z","shell.execute_reply":"2022-08-01T09:25:10.758638Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.preprocessing import LabelEncoder\nle = LabelEncoder()\ncols = ['product_code','attribute_0','attribute_1']\nfor i in cols:\n    train_data[i]=le.fit_transform(train_data[i])\n    test_data[i]=le.fit_transform(test_data[i])","metadata":{"execution":{"iopub.status.busy":"2022-08-01T09:25:10.762218Z","iopub.execute_input":"2022-08-01T09:25:10.762878Z","iopub.status.idle":"2022-08-01T09:25:10.815633Z","shell.execute_reply.started":"2022-08-01T09:25:10.762839Z","shell.execute_reply":"2022-08-01T09:25:10.814723Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cols1 = train_data.columns\ncols2 = test_data.columns","metadata":{"execution":{"iopub.status.busy":"2022-08-01T09:25:10.817355Z","iopub.execute_input":"2022-08-01T09:25:10.818073Z","iopub.status.idle":"2022-08-01T09:25:10.823168Z","shell.execute_reply.started":"2022-08-01T09:25:10.818028Z","shell.execute_reply":"2022-08-01T09:25:10.822180Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.impute import SimpleImputer\nsi = SimpleImputer(missing_values=np.nan, strategy='mean')\nfor i in cols1:\n    train_data[i]=si.fit_transform(train_data[[i]])\nfor i in cols2:\n    test_data[i]=si.fit_transform(test_data[[i]])\n","metadata":{"execution":{"iopub.status.busy":"2022-08-01T09:25:10.824376Z","iopub.execute_input":"2022-08-01T09:25:10.825191Z","iopub.status.idle":"2022-08-01T09:25:11.061517Z","shell.execute_reply.started":"2022-08-01T09:25:10.825149Z","shell.execute_reply":"2022-08-01T09:25:11.060318Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data = train_data.drop(['id'],axis=1)\ntest_data = test_data.drop(['id'],axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-08-01T09:25:11.064031Z","iopub.execute_input":"2022-08-01T09:25:11.064352Z","iopub.status.idle":"2022-08-01T09:25:11.075406Z","shell.execute_reply.started":"2022-08-01T09:25:11.064324Z","shell.execute_reply":"2022-08-01T09:25:11.074345Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data","metadata":{"execution":{"iopub.status.busy":"2022-08-01T09:25:11.076885Z","iopub.execute_input":"2022-08-01T09:25:11.077288Z","iopub.status.idle":"2022-08-01T09:25:11.120543Z","shell.execute_reply.started":"2022-08-01T09:25:11.077256Z","shell.execute_reply":"2022-08-01T09:25:11.119685Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data['failure'] = train_data['failure'].astype('int')","metadata":{"execution":{"iopub.status.busy":"2022-08-01T09:25:11.121713Z","iopub.execute_input":"2022-08-01T09:25:11.122177Z","iopub.status.idle":"2022-08-01T09:25:11.128534Z","shell.execute_reply.started":"2022-08-01T09:25:11.122147Z","shell.execute_reply":"2022-08-01T09:25:11.127534Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X = train_data.drop(['failure'],axis=1)\ny = train_data['failure']","metadata":{"execution":{"iopub.status.busy":"2022-08-01T09:25:11.130086Z","iopub.execute_input":"2022-08-01T09:25:11.130795Z","iopub.status.idle":"2022-08-01T09:25:11.140172Z","shell.execute_reply.started":"2022-08-01T09:25:11.130748Z","shell.execute_reply":"2022-08-01T09:25:11.139216Z"},"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.2)","metadata":{"execution":{"iopub.status.busy":"2022-08-01T09:25:11.141800Z","iopub.execute_input":"2022-08-01T09:25:11.142515Z","iopub.status.idle":"2022-08-01T09:25:11.158846Z","shell.execute_reply.started":"2022-08-01T09:25:11.142458Z","shell.execute_reply":"2022-08-01T09:25:11.157903Z"},"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-08-01T09:25:11.160364Z","iopub.execute_input":"2022-08-01T09:25:11.160893Z","iopub.status.idle":"2022-08-01T09:25:20.747365Z","shell.execute_reply.started":"2022-08-01T09:25:11.160862Z","shell.execute_reply":"2022-08-01T09:25:20.746586Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rf.score(X_test,y_test)","metadata":{"execution":{"iopub.status.busy":"2022-08-01T09:25:20.748890Z","iopub.execute_input":"2022-08-01T09:25:20.749583Z","iopub.status.idle":"2022-08-01T09:25:20.923241Z","shell.execute_reply.started":"2022-08-01T09:25:20.749541Z","shell.execute_reply":"2022-08-01T09:25:20.922453Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred = rf.predict(test_data)\ny_pred","metadata":{"execution":{"iopub.status.busy":"2022-08-01T09:25:57.211696Z","iopub.execute_input":"2022-08-01T09:25:57.212163Z","iopub.status.idle":"2022-08-01T09:25:57.738560Z","shell.execute_reply.started":"2022-08-01T09:25:57.212114Z","shell.execute_reply":"2022-08-01T09:25:57.737158Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred = pd.Series(y_pred,name='failure')\ny_pred.value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-08-01T09:27:22.297115Z","iopub.execute_input":"2022-08-01T09:27:22.298065Z","iopub.status.idle":"2022-08-01T09:27:22.307934Z","shell.execute_reply.started":"2022-08-01T09:27:22.298011Z","shell.execute_reply":"2022-08-01T09:27:22.306838Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub['failure'] = y_pred","metadata":{"execution":{"iopub.status.busy":"2022-08-01T09:28:22.183328Z","iopub.execute_input":"2022-08-01T09:28:22.183693Z","iopub.status.idle":"2022-08-01T09:28:22.188862Z","shell.execute_reply.started":"2022-08-01T09:28:22.183664Z","shell.execute_reply":"2022-08-01T09:28:22.187916Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub","metadata":{"execution":{"iopub.status.busy":"2022-08-01T09:28:28.092363Z","iopub.execute_input":"2022-08-01T09:28:28.093899Z","iopub.status.idle":"2022-08-01T09:28:28.111119Z","shell.execute_reply.started":"2022-08-01T09:28:28.093825Z","shell.execute_reply":"2022-08-01T09:28:28.108116Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub.to_csv('submission.csv',index=False)","metadata":{"execution":{"iopub.status.busy":"2022-08-01T09:29:01.127943Z","iopub.execute_input":"2022-08-01T09:29:01.128363Z","iopub.status.idle":"2022-08-01T09:29:01.170112Z","shell.execute_reply.started":"2022-08-01T09:29:01.128331Z","shell.execute_reply":"2022-08-01T09:29:01.169224Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}