{"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","metadata":{"id":"powo4ir7IFgU","execution":{"iopub.status.busy":"2022-08-02T23:50:08.789043Z","iopub.execute_input":"2022-08-02T23:50:08.789985Z","iopub.status.idle":"2022-08-02T23:50:08.793911Z","shell.execute_reply.started":"2022-08-02T23:50:08.789948Z","shell.execute_reply":"2022-08-02T23:50:08.793124Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data = pd.read_csv(\"../input/tabular-playground-series-aug-2022/train.csv\",index_col=0)\ndata.head(20)","metadata":{"id":"md_kx3pFIWWF","outputId":"58f18ff2-534c-47ec-893a-323d204a3e6b","execution":{"iopub.status.busy":"2022-08-02T23:50:08.809665Z","iopub.execute_input":"2022-08-02T23:50:08.810059Z","iopub.status.idle":"2022-08-02T23:50:08.947395Z","shell.execute_reply.started":"2022-08-02T23:50:08.810025Z","shell.execute_reply":"2022-08-02T23:50:08.946134Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.columns","metadata":{"id":"4WQh5HWaMtn8","outputId":"f95b15f8-bd8b-4896-ca88-124e08067bf2","execution":{"iopub.status.busy":"2022-08-02T23:50:08.949490Z","iopub.execute_input":"2022-08-02T23:50:08.949850Z","iopub.status.idle":"2022-08-02T23:50:08.957731Z","shell.execute_reply.started":"2022-08-02T23:50:08.949819Z","shell.execute_reply":"2022-08-02T23:50:08.955388Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.dtypes","metadata":{"id":"7tZe4GQbMyEX","outputId":"21506c02-a995-41b4-ee96-9d4deed5bfba","execution":{"iopub.status.busy":"2022-08-02T23:50:08.959851Z","iopub.execute_input":"2022-08-02T23:50:08.961003Z","iopub.status.idle":"2022-08-02T23:50:08.971875Z","shell.execute_reply.started":"2022-08-02T23:50:08.960958Z","shell.execute_reply":"2022-08-02T23:50:08.970269Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#columns that contain other data types\notcl = data.select_dtypes(exclude=[\"int64\",\"float64\"]).columns\notcl","metadata":{"id":"E5dh_Rh7NJvA","outputId":"d61197c6-529e-4756-a19e-63bf45bf8d4c","execution":{"iopub.status.busy":"2022-08-02T23:50:08.975597Z","iopub.execute_input":"2022-08-02T23:50:08.975924Z","iopub.status.idle":"2022-08-02T23:50:08.985862Z","shell.execute_reply.started":"2022-08-02T23:50:08.975896Z","shell.execute_reply":"2022-08-02T23:50:08.984734Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.isnull().sum()","metadata":{"id":"4G2-mZEQOHhU","outputId":"c2607102-9c45-48a9-d345-631ef58c9825","execution":{"iopub.status.busy":"2022-08-02T23:50:08.987374Z","iopub.execute_input":"2022-08-02T23:50:08.988193Z","iopub.status.idle":"2022-08-02T23:50:09.004754Z","shell.execute_reply.started":"2022-08-02T23:50:08.988150Z","shell.execute_reply":"2022-08-02T23:50:09.003672Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.fillna(data.mean(),inplace=True)","metadata":{"id":"vElqCcoyOdV-","outputId":"f8fd605b-df53-4a2b-cf9d-6e4e5fccef37","execution":{"iopub.status.busy":"2022-08-02T23:50:09.006076Z","iopub.execute_input":"2022-08-02T23:50:09.006440Z","iopub.status.idle":"2022-08-02T23:50:09.342515Z","shell.execute_reply.started":"2022-08-02T23:50:09.006398Z","shell.execute_reply":"2022-08-02T23:50:09.341209Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.preprocessing import LabelEncoder\ndata[otcl] = LabelEncoder().fit_transform(otcl)\ndata","metadata":{"id":"BeXa_mp1Nmpb","outputId":"04c268b7-9785-4002-f4f1-64a22c146860","execution":{"iopub.status.busy":"2022-08-02T23:50:09.344628Z","iopub.execute_input":"2022-08-02T23:50:09.345068Z","iopub.status.idle":"2022-08-02T23:50:09.384788Z","shell.execute_reply.started":"2022-08-02T23:50:09.345026Z","shell.execute_reply":"2022-08-02T23:50:09.383451Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y = data[\"failure\"]\ndc = data.columns[:-1]\nx = data[dc].values","metadata":{"id":"deAOiM6X02a3","execution":{"iopub.status.busy":"2022-08-02T23:50:09.387502Z","iopub.execute_input":"2022-08-02T23:50:09.388471Z","iopub.status.idle":"2022-08-02T23:50:09.398481Z","shell.execute_reply.started":"2022-08-02T23:50:09.388434Z","shell.execute_reply":"2022-08-02T23:50:09.397434Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\ntrain_x,test_x,train_y,test_y = train_test_split(x,y,test_size=0.25,random_state=0)","metadata":{"id":"TGTR5NN41bTB","execution":{"iopub.status.busy":"2022-08-02T23:50:09.399952Z","iopub.execute_input":"2022-08-02T23:50:09.400252Z","iopub.status.idle":"2022-08-02T23:50:09.412039Z","shell.execute_reply.started":"2022-08-02T23:50:09.400224Z","shell.execute_reply":"2022-08-02T23:50:09.410913Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.ensemble import RandomForestClassifier\nclf = RandomForestClassifier()\nclf.fit(train_x,train_y)\nydash = clf.predict(test_x)","metadata":{"id":"InE8740R1pPA","execution":{"iopub.status.busy":"2022-08-02T23:50:09.415023Z","iopub.execute_input":"2022-08-02T23:50:09.415356Z","iopub.status.idle":"2022-08-02T23:50:19.506085Z","shell.execute_reply.started":"2022-08-02T23:50:09.415325Z","shell.execute_reply":"2022-08-02T23:50:19.505013Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"(ydash!=test_y).sum()","metadata":{"id":"nuHxFpz-17Do","outputId":"f4d0a4d8-aa0e-43ce-b24d-1282ff4140cd","execution":{"iopub.status.busy":"2022-08-02T23:50:19.507677Z","iopub.execute_input":"2022-08-02T23:50:19.508027Z","iopub.status.idle":"2022-08-02T23:50:19.515516Z","shell.execute_reply.started":"2022-08-02T23:50:19.507998Z","shell.execute_reply":"2022-08-02T23:50:19.514494Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data = pd.read_csv(\"../input/tabular-playground-series-aug-2022/test.csv\")\nid = train_data[\"id\"]\ntestd_xcl = train_data.columns[1:]\ntrain_data[otcl] = LabelEncoder().fit_transform(otcl)\ntrain_data.fillna(data.mean(),inplace=True)\ntestd_x = train_data[testd_xcl].values\ntestd_y = pd.DataFrame(clf.predict(testd_x),columns=[\"failure\"])\nfl = [id,testd_y]\nres = pd.concat(fl,axis=1)\nres","metadata":{"id":"73JN3cLE6nww","outputId":"1eaa03fe-2812-4c3d-e5de-f01e0d1aebcf","execution":{"iopub.status.busy":"2022-08-02T23:50:19.516854Z","iopub.execute_input":"2022-08-02T23:50:19.517159Z","iopub.status.idle":"2022-08-02T23:50:20.103719Z","shell.execute_reply.started":"2022-08-02T23:50:19.517131Z","shell.execute_reply":"2022-08-02T23:50:20.102717Z"},"trusted":true},"execution_count":null,"outputs":[]}]}