{"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":"!pip install ../input/pycaret-239/scikit_learn-0.23.2-cp37-cp37m-manylinux1_x86_64.whl","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-08-12T00:06:07.206589Z","iopub.execute_input":"2022-08-12T00:06:07.207168Z","iopub.status.idle":"2022-08-12T00:06:28.038118Z","shell.execute_reply.started":"2022-08-12T00:06:07.207040Z","shell.execute_reply":"2022-08-12T00:06:28.036675Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import sklearn                                                                                                                                           \nsklearn.__version__","metadata":{"execution":{"iopub.status.busy":"2022-08-12T00:06:28.041557Z","iopub.execute_input":"2022-08-12T00:06:28.041984Z","iopub.status.idle":"2022-08-12T00:06:28.712272Z","shell.execute_reply.started":"2022-08-12T00:06:28.041948Z","shell.execute_reply":"2022-08-12T00:06:28.710875Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import sys\nsys.path.append('../input/pycaret-239/pycaret-master/pycaret-master')\nsys.path.append('../input/pycaret-239/pyod-master/pyod-master')","metadata":{"execution":{"iopub.status.busy":"2022-08-12T00:06:28.713979Z","iopub.execute_input":"2022-08-12T00:06:28.714392Z","iopub.status.idle":"2022-08-12T00:06:28.722792Z","shell.execute_reply.started":"2022-08-12T00:06:28.714356Z","shell.execute_reply":"2022-08-12T00:06:28.720602Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\n\nimport matplotlib.pyplot as plt\nimport seaborn as sns\n\nfrom pycaret.classification import *\n","metadata":{"execution":{"iopub.status.busy":"2022-08-12T00:06:28.725868Z","iopub.execute_input":"2022-08-12T00:06:28.726906Z","iopub.status.idle":"2022-08-12T00:06:34.306513Z","shell.execute_reply.started":"2022-08-12T00:06:28.726860Z","shell.execute_reply":"2022-08-12T00:06:34.304389Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train = pd.read_csv('../input/tabular-playground-series-aug-2022/train.csv')\ndf_test = pd.read_csv('../input/tabular-playground-series-aug-2022/test.csv')","metadata":{"execution":{"iopub.status.busy":"2022-08-12T00:06:34.310010Z","iopub.execute_input":"2022-08-12T00:06:34.310597Z","iopub.status.idle":"2022-08-12T00:06:34.653309Z","shell.execute_reply.started":"2022-08-12T00:06:34.310540Z","shell.execute_reply":"2022-08-12T00:06:34.651721Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train","metadata":{"execution":{"iopub.status.busy":"2022-08-12T00:06:34.655078Z","iopub.execute_input":"2022-08-12T00:06:34.655721Z","iopub.status.idle":"2022-08-12T00:06:34.717610Z","shell.execute_reply.started":"2022-08-12T00:06:34.655641Z","shell.execute_reply":"2022-08-12T00:06:34.716156Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.concat([df_train,df_test])","metadata":{"execution":{"iopub.status.busy":"2022-08-12T00:07:53.365444Z","iopub.execute_input":"2022-08-12T00:07:53.368195Z","iopub.status.idle":"2022-08-12T00:07:53.404171Z","shell.execute_reply.started":"2022-08-12T00:07:53.367724Z","shell.execute_reply":"2022-08-12T00:07:53.402559Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train.describe(include = 'all')","metadata":{"execution":{"iopub.status.busy":"2022-08-12T00:06:34.719472Z","iopub.execute_input":"2022-08-12T00:06:34.720111Z","iopub.status.idle":"2022-08-12T00:06:34.885972Z","shell.execute_reply.started":"2022-08-12T00:06:34.720056Z","shell.execute_reply":"2022-08-12T00:06:34.884235Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.describe(include = 'all')","metadata":{"execution":{"iopub.status.busy":"2022-08-12T00:08:17.973070Z","iopub.execute_input":"2022-08-12T00:08:17.973639Z","iopub.status.idle":"2022-08-12T00:08:18.217720Z","shell.execute_reply.started":"2022-08-12T00:08:17.973597Z","shell.execute_reply":"2022-08-12T00:08:18.215881Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train['attribute_1'].unique()","metadata":{"execution":{"iopub.status.busy":"2022-08-12T00:09:18.899380Z","iopub.execute_input":"2022-08-12T00:09:18.899819Z","iopub.status.idle":"2022-08-12T00:09:18.913856Z","shell.execute_reply.started":"2022-08-12T00:09:18.899784Z","shell.execute_reply":"2022-08-12T00:09:18.912055Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['attribute_1'].unique()","metadata":{"execution":{"iopub.status.busy":"2022-08-12T00:09:03.401176Z","iopub.execute_input":"2022-08-12T00:09:03.401655Z","iopub.status.idle":"2022-08-12T00:09:03.414484Z","shell.execute_reply.started":"2022-08-12T00:09:03.401620Z","shell.execute_reply":"2022-08-12T00:09:03.413421Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_corr = df_train.corr()\n\nfig, ax = plt.subplots(figsize=(12, 9)) \nsns.heatmap(train_corr, square=True, vmax=1, vmin=-1, center=0)\n","metadata":{"execution":{"iopub.status.busy":"2022-08-12T00:10:04.057989Z","iopub.execute_input":"2022-08-12T00:10:04.059286Z","iopub.status.idle":"2022-08-12T00:10:05.180203Z","shell.execute_reply.started":"2022-08-12T00:10:04.059221Z","shell.execute_reply":"2022-08-12T00:10:05.178077Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_corr = df.corr()\n\nfig, ax = plt.subplots(figsize=(12, 9)) \nsns.heatmap(df_corr, square=True, vmax=1, vmin=-1, center=0)","metadata":{"execution":{"iopub.status.busy":"2022-08-12T00:10:35.200240Z","iopub.execute_input":"2022-08-12T00:10:35.201121Z","iopub.status.idle":"2022-08-12T00:10:36.353178Z","shell.execute_reply.started":"2022-08-12T00:10:35.201061Z","shell.execute_reply":"2022-08-12T00:10:36.350867Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\ndf_train = df_train.drop(['product_code','attribute_1'],axis=1)\ndf_test = df_test.drop(['product_code','attribute_1'],axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-08-12T00:12:43.104899Z","iopub.execute_input":"2022-08-12T00:12:43.105492Z","iopub.status.idle":"2022-08-12T00:12:43.127025Z","shell.execute_reply.started":"2022-08-12T00:12:43.105453Z","shell.execute_reply":"2022-08-12T00:12:43.125077Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"s = setup(data=df_train,target='failure',session_id=12,silent=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-12T00:12:51.410218Z","iopub.execute_input":"2022-08-12T00:12:51.410660Z","iopub.status.idle":"2022-08-12T00:12:53.465738Z","shell.execute_reply.started":"2022-08-12T00:12:51.410626Z","shell.execute_reply":"2022-08-12T00:12:53.463597Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# モデルの比較を実施\ntop3 = compare_models(sort='AUC',n_select=3)","metadata":{"execution":{"iopub.status.busy":"2022-08-12T00:13:05.123175Z","iopub.execute_input":"2022-08-12T00:13:05.123698Z","iopub.status.idle":"2022-08-12T00:17:54.893626Z","shell.execute_reply.started":"2022-08-12T00:13:05.123660Z","shell.execute_reply":"2022-08-12T00:17:54.891755Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"blended = blend_models(estimator_list=top3, optimize='AUC')","metadata":{"execution":{"iopub.status.busy":"2022-08-12T00:27:20.257104Z","iopub.execute_input":"2022-08-12T00:27:20.257635Z","iopub.status.idle":"2022-08-12T00:28:21.126401Z","shell.execute_reply.started":"2022-08-12T00:27:20.257597Z","shell.execute_reply":"2022-08-12T00:28:21.125068Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tuned = tune_model(blended,optimize='AUC')","metadata":{"execution":{"iopub.status.busy":"2022-08-12T00:28:21.128572Z","iopub.execute_input":"2022-08-12T00:28:21.129178Z","iopub.status.idle":"2022-08-12T00:35:51.568365Z","shell.execute_reply.started":"2022-08-12T00:28:21.129137Z","shell.execute_reply":"2022-08-12T00:35:51.566583Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"final = finalize_model(tuned)","metadata":{"execution":{"iopub.status.busy":"2022-08-12T00:35:51.570458Z","iopub.execute_input":"2022-08-12T00:35:51.570973Z","iopub.status.idle":"2022-08-12T00:37:07.340056Z","shell.execute_reply.started":"2022-08-12T00:35:51.570932Z","shell.execute_reply":"2022-08-12T00:37:07.338983Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred = predict_model(final, data=df_test)","metadata":{"execution":{"iopub.status.busy":"2022-08-12T00:37:07.342385Z","iopub.execute_input":"2022-08-12T00:37:07.342828Z","iopub.status.idle":"2022-08-12T00:37:08.152519Z","shell.execute_reply.started":"2022-08-12T00:37:07.342796Z","shell.execute_reply":"2022-08-12T00:37:08.151310Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred[pred['Label'] == 0]","metadata":{"execution":{"iopub.status.busy":"2022-08-12T00:37:08.154054Z","iopub.execute_input":"2022-08-12T00:37:08.154424Z","iopub.status.idle":"2022-08-12T00:37:08.198508Z","shell.execute_reply.started":"2022-08-12T00:37:08.154391Z","shell.execute_reply":"2022-08-12T00:37:08.197358Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred['failure'] = [1 - x[1] if x[0] == 0 else x[1] for x in pred[['Label','Score']].values]","metadata":{"execution":{"iopub.status.busy":"2022-08-12T00:37:08.200080Z","iopub.execute_input":"2022-08-12T00:37:08.200408Z","iopub.status.idle":"2022-08-12T00:37:08.225999Z","shell.execute_reply.started":"2022-08-12T00:37:08.200379Z","shell.execute_reply":"2022-08-12T00:37:08.225094Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred","metadata":{"execution":{"iopub.status.busy":"2022-08-12T00:37:08.227078Z","iopub.execute_input":"2022-08-12T00:37:08.228180Z","iopub.status.idle":"2022-08-12T00:37:08.270741Z","shell.execute_reply.started":"2022-08-12T00:37:08.228144Z","shell.execute_reply":"2022-08-12T00:37:08.269620Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission = pd.read_csv('../input/tabular-playground-series-aug-2022/sample_submission.csv')","metadata":{"execution":{"iopub.status.busy":"2022-08-12T00:37:08.272143Z","iopub.execute_input":"2022-08-12T00:37:08.272505Z","iopub.status.idle":"2022-08-12T00:37:08.291688Z","shell.execute_reply.started":"2022-08-12T00:37:08.272473Z","shell.execute_reply":"2022-08-12T00:37:08.290652Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission['failure'] = pred['failure']","metadata":{"execution":{"iopub.status.busy":"2022-08-12T00:37:08.292951Z","iopub.execute_input":"2022-08-12T00:37:08.293315Z","iopub.status.idle":"2022-08-12T00:37:08.299355Z","shell.execute_reply.started":"2022-08-12T00:37:08.293277Z","shell.execute_reply":"2022-08-12T00:37:08.298227Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission","metadata":{"execution":{"iopub.status.busy":"2022-08-12T00:37:08.302301Z","iopub.execute_input":"2022-08-12T00:37:08.302641Z","iopub.status.idle":"2022-08-12T00:37:08.323241Z","shell.execute_reply.started":"2022-08-12T00:37:08.302612Z","shell.execute_reply":"2022-08-12T00:37:08.322395Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%rm -rf *","metadata":{"execution":{"iopub.status.busy":"2022-08-12T00:37:08.325109Z","iopub.execute_input":"2022-08-12T00:37:08.325980Z","iopub.status.idle":"2022-08-12T00:37:09.473408Z","shell.execute_reply.started":"2022-08-12T00:37:08.325934Z","shell.execute_reply":"2022-08-12T00:37:09.472074Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission.to_csv('submisson.csv',index=None)","metadata":{"execution":{"iopub.status.busy":"2022-08-12T00:37:09.475350Z","iopub.execute_input":"2022-08-12T00:37:09.475701Z","iopub.status.idle":"2022-08-12T00:37:09.533920Z","shell.execute_reply.started":"2022-08-12T00:37:09.475670Z","shell.execute_reply":"2022-08-12T00:37:09.532830Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}