{"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-13T15:47:48.675896Z","iopub.execute_input":"2022-08-13T15:47:48.676385Z","iopub.status.idle":"2022-08-13T15:48:06.044053Z","shell.execute_reply.started":"2022-08-13T15:47:48.676289Z","shell.execute_reply":"2022-08-13T15:48:06.042311Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import sklearn                                                                                                                                           \nsklearn.__version__","metadata":{"execution":{"iopub.status.busy":"2022-08-13T15:48:06.049116Z","iopub.execute_input":"2022-08-13T15:48:06.049624Z","iopub.status.idle":"2022-08-13T15:48:06.637410Z","shell.execute_reply.started":"2022-08-13T15:48:06.049580Z","shell.execute_reply":"2022-08-13T15:48:06.635966Z"},"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-13T15:48:06.639110Z","iopub.execute_input":"2022-08-13T15:48:06.639519Z","iopub.status.idle":"2022-08-13T15:48:06.645886Z","shell.execute_reply.started":"2022-08-13T15:48:06.639485Z","shell.execute_reply":"2022-08-13T15:48:06.644623Z"},"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-13T15:48:06.648764Z","iopub.execute_input":"2022-08-13T15:48:06.649993Z","iopub.status.idle":"2022-08-13T15:48:11.103566Z","shell.execute_reply.started":"2022-08-13T15:48:06.649932Z","shell.execute_reply":"2022-08-13T15:48:11.101838Z"},"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-13T15:48:11.105647Z","iopub.execute_input":"2022-08-13T15:48:11.106147Z","iopub.status.idle":"2022-08-13T15:48:11.374816Z","shell.execute_reply.started":"2022-08-13T15:48:11.106093Z","shell.execute_reply":"2022-08-13T15:48:11.373739Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.concat([df_train,df_test])","metadata":{"execution":{"iopub.status.busy":"2022-08-13T15:48:16.256170Z","iopub.execute_input":"2022-08-13T15:48:16.256735Z","iopub.status.idle":"2022-08-13T15:48:16.288931Z","shell.execute_reply.started":"2022-08-13T15:48:16.256678Z","shell.execute_reply":"2022-08-13T15:48:16.287394Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train.describe(include = 'all')","metadata":{"execution":{"iopub.status.busy":"2022-08-13T15:48:19.057985Z","iopub.execute_input":"2022-08-13T15:48:19.058412Z","iopub.status.idle":"2022-08-13T15:48:19.202668Z","shell.execute_reply.started":"2022-08-13T15:48:19.058378Z","shell.execute_reply":"2022-08-13T15:48:19.201098Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.describe(include = 'all')","metadata":{"execution":{"iopub.status.busy":"2022-08-13T15:48:19.341691Z","iopub.execute_input":"2022-08-13T15:48:19.342491Z","iopub.status.idle":"2022-08-13T15:48:19.499562Z","shell.execute_reply.started":"2022-08-13T15:48:19.342440Z","shell.execute_reply":"2022-08-13T15:48:19.498332Z"},"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-13T15:48:21.649413Z","iopub.execute_input":"2022-08-13T15:48:21.649852Z","iopub.status.idle":"2022-08-13T15:48:22.465064Z","shell.execute_reply.started":"2022-08-13T15:48:21.649818Z","shell.execute_reply":"2022-08-13T15:48:22.463718Z"},"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-13T15:48:22.843639Z","iopub.execute_input":"2022-08-13T15:48:22.844524Z","iopub.status.idle":"2022-08-13T15:48:23.586718Z","shell.execute_reply.started":"2022-08-13T15:48:22.844475Z","shell.execute_reply":"2022-08-13T15:48:23.585315Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train = df_train.drop('product_code',axis=1)\ndf_test = df_test.drop('product_code',axis=1)\ndf_train = df_train.drop('attribute_1',axis=1)\ndf_test = df_test.drop('attribute_1',axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-08-13T15:50:37.445454Z","iopub.execute_input":"2022-08-13T15:50:37.445956Z","iopub.status.idle":"2022-08-13T15:50:37.469453Z","shell.execute_reply.started":"2022-08-13T15:50:37.445917Z","shell.execute_reply":"2022-08-13T15:50:37.467951Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"s = setup(data=df_train,target='failure',session_id=12,feature_selection=True,feature_interaction=True,feature_ratio=True,silent=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-13T15:53:47.027147Z","iopub.execute_input":"2022-08-13T15:53:47.027677Z","iopub.status.idle":"2022-08-13T15:53:59.528507Z","shell.execute_reply.started":"2022-08-13T15:53:47.027638Z","shell.execute_reply":"2022-08-13T15:53:59.527195Z"},"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-13T15:54:04.917049Z","iopub.execute_input":"2022-08-13T15:54:04.917856Z","iopub.status.idle":"2022-08-13T16:01:24.177999Z","shell.execute_reply.started":"2022-08-13T15:54:04.917817Z","shell.execute_reply":"2022-08-13T16:01:24.176762Z"},"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-13T16:01:24.180154Z","iopub.execute_input":"2022-08-13T16:01:24.181284Z","iopub.status.idle":"2022-08-13T16:01:28.106007Z","shell.execute_reply.started":"2022-08-13T16:01:24.181216Z","shell.execute_reply":"2022-08-13T16:01:28.104652Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tuned = tune_model(blended,optimize='AUC')","metadata":{"execution":{"iopub.status.busy":"2022-08-13T16:01:28.107693Z","iopub.execute_input":"2022-08-13T16:01:28.108076Z","iopub.status.idle":"2022-08-13T16:01:50.831534Z","shell.execute_reply.started":"2022-08-13T16:01:28.108042Z","shell.execute_reply":"2022-08-13T16:01:50.829998Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"final = finalize_model(tuned)","metadata":{"execution":{"iopub.status.busy":"2022-08-13T16:01:50.834741Z","iopub.execute_input":"2022-08-13T16:01:50.835162Z","iopub.status.idle":"2022-08-13T16:01:55.058722Z","shell.execute_reply.started":"2022-08-13T16:01:50.835126Z","shell.execute_reply":"2022-08-13T16:01:55.057436Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred = predict_model(final, data=df_test)","metadata":{"execution":{"iopub.status.busy":"2022-08-13T16:01:55.060440Z","iopub.execute_input":"2022-08-13T16:01:55.060866Z","iopub.status.idle":"2022-08-13T16:01:56.468941Z","shell.execute_reply.started":"2022-08-13T16:01:55.060830Z","shell.execute_reply":"2022-08-13T16:01:56.467648Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred[pred['Label'] == 0]","metadata":{"execution":{"iopub.status.busy":"2022-08-13T16:01:56.470825Z","iopub.execute_input":"2022-08-13T16:01:56.471956Z","iopub.status.idle":"2022-08-13T16:01:56.521135Z","shell.execute_reply.started":"2022-08-13T16:01:56.471906Z","shell.execute_reply":"2022-08-13T16:01:56.519713Z"},"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-13T16:01:56.522508Z","iopub.execute_input":"2022-08-13T16:01:56.522844Z","iopub.status.idle":"2022-08-13T16:01:56.551877Z","shell.execute_reply.started":"2022-08-13T16:01:56.522814Z","shell.execute_reply":"2022-08-13T16:01:56.550536Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred","metadata":{"execution":{"iopub.status.busy":"2022-08-13T16:01:56.553347Z","iopub.execute_input":"2022-08-13T16:01:56.554228Z","iopub.status.idle":"2022-08-13T16:01:56.595596Z","shell.execute_reply.started":"2022-08-13T16:01:56.554193Z","shell.execute_reply":"2022-08-13T16:01:56.594727Z"},"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-13T16:01:56.597191Z","iopub.execute_input":"2022-08-13T16:01:56.597654Z","iopub.status.idle":"2022-08-13T16:01:56.615402Z","shell.execute_reply.started":"2022-08-13T16:01:56.597614Z","shell.execute_reply":"2022-08-13T16:01:56.614316Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission['failure'] = pred['failure']","metadata":{"execution":{"iopub.status.busy":"2022-08-13T16:01:56.618627Z","iopub.execute_input":"2022-08-13T16:01:56.618998Z","iopub.status.idle":"2022-08-13T16:01:56.625511Z","shell.execute_reply.started":"2022-08-13T16:01:56.618965Z","shell.execute_reply":"2022-08-13T16:01:56.624267Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission","metadata":{"execution":{"iopub.status.busy":"2022-08-13T16:01:56.627073Z","iopub.execute_input":"2022-08-13T16:01:56.628012Z","iopub.status.idle":"2022-08-13T16:01:56.646611Z","shell.execute_reply.started":"2022-08-13T16:01:56.627956Z","shell.execute_reply":"2022-08-13T16:01:56.645229Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%rm -rf *","metadata":{"execution":{"iopub.status.busy":"2022-08-13T16:01:56.647754Z","iopub.execute_input":"2022-08-13T16:01:56.648740Z","iopub.status.idle":"2022-08-13T16:01:57.807928Z","shell.execute_reply.started":"2022-08-13T16:01:56.648706Z","shell.execute_reply":"2022-08-13T16:01:57.806464Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission.to_csv('submisson.csv',index=None)","metadata":{"execution":{"iopub.status.busy":"2022-08-13T16:01:57.810234Z","iopub.execute_input":"2022-08-13T16:01:57.810930Z","iopub.status.idle":"2022-08-13T16:01:57.870569Z","shell.execute_reply.started":"2022-08-13T16:01:57.810889Z","shell.execute_reply":"2022-08-13T16:01:57.869303Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}