{"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-08-03T09:23:09.695704Z","iopub.execute_input":"2022-08-03T09:23:09.696097Z","iopub.status.idle":"2022-08-03T09:23:09.704791Z","shell.execute_reply.started":"2022-08-03T09:23:09.696058Z","shell.execute_reply":"2022-08-03T09:23:09.703647Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"thanks https://www.kaggle.com/code/cv13j0/tps-aug22-binary-classification","metadata":{}},{"cell_type":"code","source":"pd.set_option('display.max_columns', None)","metadata":{"execution":{"iopub.status.busy":"2022-08-03T09:23:09.709165Z","iopub.execute_input":"2022-08-03T09:23:09.709798Z","iopub.status.idle":"2022-08-03T09:23:09.713712Z","shell.execute_reply.started":"2022-08-03T09:23:09.709764Z","shell.execute_reply":"2022-08-03T09:23:09.712929Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = pd.read_csv('../input/tabular-playground-series-aug-2022/train.csv')\ntest = pd.read_csv('../input/tabular-playground-series-aug-2022/test.csv')","metadata":{"execution":{"iopub.status.busy":"2022-08-03T09:23:09.755585Z","iopub.execute_input":"2022-08-03T09:23:09.756190Z","iopub.status.idle":"2022-08-03T09:23:09.911370Z","shell.execute_reply.started":"2022-08-03T09:23:09.756155Z","shell.execute_reply":"2022-08-03T09:23:09.909957Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"display(train.isnull().sum())\nprint('\\r\\n', '='*30, '\\r\\n')\ndisplay(test.isnull().sum())","metadata":{"execution":{"iopub.status.busy":"2022-08-03T09:23:09.913722Z","iopub.execute_input":"2022-08-03T09:23:09.914085Z","iopub.status.idle":"2022-08-03T09:23:09.939226Z","shell.execute_reply.started":"2022-08-03T09:23:09.914053Z","shell.execute_reply":"2022-08-03T09:23:09.938116Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = train.drop(['product_code', 'attribute_0', 'attribute_1', 'attribute_2', 'attribute_3'], axis=1)\ntest = test.drop(['product_code', 'attribute_0', 'attribute_1', 'attribute_2', 'attribute_3'], axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-08-03T09:23:09.940930Z","iopub.execute_input":"2022-08-03T09:23:09.941245Z","iopub.status.idle":"2022-08-03T09:23:09.950477Z","shell.execute_reply.started":"2022-08-03T09:23:09.941216Z","shell.execute_reply":"2022-08-03T09:23:09.949308Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.failure.value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-08-03T09:23:09.953040Z","iopub.execute_input":"2022-08-03T09:23:09.953436Z","iopub.status.idle":"2022-08-03T09:23:09.963947Z","shell.execute_reply.started":"2022-08-03T09:23:09.953348Z","shell.execute_reply":"2022-08-03T09:23:09.962948Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_data = train.drop(['id', 'failure'], axis=1)\ny_data = train.failure\n\nx_test = test.drop('id', axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-08-03T09:23:09.965232Z","iopub.execute_input":"2022-08-03T09:23:09.965533Z","iopub.status.idle":"2022-08-03T09:23:09.974195Z","shell.execute_reply.started":"2022-08-03T09:23:09.965504Z","shell.execute_reply":"2022-08-03T09:23:09.973211Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.preprocessing import StandardScaler\n\nscaler = StandardScaler()\nx_data = scaler.fit_transform(x_data)\nx_test = scaler.transform(x_test)","metadata":{"execution":{"iopub.status.busy":"2022-08-03T09:23:09.975974Z","iopub.execute_input":"2022-08-03T09:23:09.976485Z","iopub.status.idle":"2022-08-03T09:23:10.006522Z","shell.execute_reply.started":"2022-08-03T09:23:09.976444Z","shell.execute_reply":"2022-08-03T09:23:10.005330Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.impute import KNNImputer\n\nimputer = KNNImputer(n_neighbors=3)\nx_data = imputer.fit_transform(x_data)\nx_test = imputer.transform(x_test)","metadata":{"execution":{"iopub.status.busy":"2022-08-03T09:23:10.008201Z","iopub.execute_input":"2022-08-03T09:23:10.008526Z","iopub.status.idle":"2022-08-03T09:24:06.034645Z","shell.execute_reply.started":"2022-08-03T09:23:10.008496Z","shell.execute_reply":"2022-08-03T09:24:06.033017Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.decomposition import PCA\n\npca = PCA(n_components=13)\nx_data = pca.fit_transform(x_data)\nx_test = pca.transform(x_test)","metadata":{"execution":{"iopub.status.busy":"2022-08-03T09:24:06.036497Z","iopub.execute_input":"2022-08-03T09:24:06.037140Z","iopub.status.idle":"2022-08-03T09:24:06.245286Z","shell.execute_reply.started":"2022-08-03T09:24:06.037099Z","shell.execute_reply":"2022-08-03T09:24:06.243487Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\n\nx_train, x_val, y_train, y_val = train_test_split(x_data, y_data)","metadata":{"execution":{"iopub.status.busy":"2022-08-03T09:24:06.248098Z","iopub.execute_input":"2022-08-03T09:24:06.249847Z","iopub.status.idle":"2022-08-03T09:24:06.284437Z","shell.execute_reply.started":"2022-08-03T09:24:06.249799Z","shell.execute_reply":"2022-08-03T09:24:06.282573Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.linear_model import LogisticRegression\n\nmodel = LogisticRegression()\nmodel.fit(x_train, y_train)\n\ny_train_pred = model.predict_proba(x_train)[:, 1]\ny_val_pred = model.predict_proba(x_val)[:,1]","metadata":{"execution":{"iopub.status.busy":"2022-08-03T09:24:06.291380Z","iopub.execute_input":"2022-08-03T09:24:06.293595Z","iopub.status.idle":"2022-08-03T09:24:06.351669Z","shell.execute_reply.started":"2022-08-03T09:24:06.293541Z","shell.execute_reply":"2022-08-03T09:24:06.350012Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import roc_auc_score\n\ntrain_score = roc_auc_score(y_train, y_train_pred)\nval_score = roc_auc_score(y_val, y_val_pred)\n\nprint('train_score:', train_score)\nprint('val_score', val_score)","metadata":{"execution":{"iopub.status.busy":"2022-08-03T09:24:06.353601Z","iopub.execute_input":"2022-08-03T09:24:06.354331Z","iopub.status.idle":"2022-08-03T09:24:06.384444Z","shell.execute_reply.started":"2022-08-03T09:24:06.354284Z","shell.execute_reply":"2022-08-03T09:24:06.383242Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.fit(x_data, y_data)","metadata":{"execution":{"iopub.status.busy":"2022-08-03T09:24:06.386393Z","iopub.execute_input":"2022-08-03T09:24:06.387122Z","iopub.status.idle":"2022-08-03T09:24:06.436427Z","shell.execute_reply.started":"2022-08-03T09:24:06.387074Z","shell.execute_reply":"2022-08-03T09:24:06.435106Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_train_pred = model.predict_proba(x_data)[:, 1]\nroc_auc_score(y_data, y_train_pred)\n","metadata":{"execution":{"iopub.status.busy":"2022-08-03T09:24:06.438364Z","iopub.execute_input":"2022-08-03T09:24:06.439072Z","iopub.status.idle":"2022-08-03T09:24:06.472780Z","shell.execute_reply.started":"2022-08-03T09:24:06.439024Z","shell.execute_reply":"2022-08-03T09:24:06.471575Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_test = model.predict_proba(x_test)[:, 1]","metadata":{"execution":{"iopub.status.busy":"2022-08-03T09:24:06.474703Z","iopub.execute_input":"2022-08-03T09:24:06.475426Z","iopub.status.idle":"2022-08-03T09:24:06.485941Z","shell.execute_reply.started":"2022-08-03T09:24:06.475381Z","shell.execute_reply":"2022-08-03T09:24:06.484241Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission = pd.read_csv('../input/tabular-playground-series-aug-2022/sample_submission.csv')\nsubmission.failure = y_test\nsubmission.to_csv('submission.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2022-08-03T09:24:06.488020Z","iopub.execute_input":"2022-08-03T09:24:06.488882Z","iopub.status.idle":"2022-08-03T09:24:06.620295Z","shell.execute_reply.started":"2022-08-03T09:24:06.488686Z","shell.execute_reply":"2022-08-03T09:24:06.619373Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}