{"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 pycaret==2.3.6","metadata":{"execution":{"iopub.status.busy":"2022-02-27T04:59:12.532549Z","iopub.execute_input":"2022-02-27T04:59:12.532935Z","iopub.status.idle":"2022-02-27T04:59:48.914635Z","shell.execute_reply.started":"2022-02-27T04:59:12.532852Z","shell.execute_reply":"2022-02-27T04:59:48.913767Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nfrom pycaret.classification import setup","metadata":{"execution":{"iopub.status.busy":"2022-02-27T05:02:27.920663Z","iopub.execute_input":"2022-02-27T05:02:27.920968Z","iopub.status.idle":"2022-02-27T05:02:32.990955Z","shell.execute_reply.started":"2022-02-27T05:02:27.92092Z","shell.execute_reply":"2022-02-27T05:02:32.990195Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data = pd.read_csv(\"../input/titanic/train.csv\")  # Training data: 訓練データ\ntest_data = pd.read_csv(\"../input/titanic/test.csv\") # Test data: テストデータ\n\ntrain_data.head()","metadata":{"execution":{"iopub.status.busy":"2022-02-27T05:02:35.953476Z","iopub.execute_input":"2022-02-27T05:02:35.953759Z","iopub.status.idle":"2022-02-27T05:02:36.058052Z","shell.execute_reply.started":"2022-02-27T05:02:35.953728Z","shell.execute_reply":"2022-02-27T05:02:36.05705Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"clf = setup(data=train_data, target=\"Survived\", session_id=123,\n            numeric_imputation=\"mean\", categorical_imputation=\"mode\")","metadata":{"execution":{"iopub.status.busy":"2022-02-27T05:02:40.712395Z","iopub.execute_input":"2022-02-27T05:02:40.713077Z","iopub.status.idle":"2022-02-27T05:04:42.95384Z","shell.execute_reply.started":"2022-02-27T05:02:40.713037Z","shell.execute_reply":"2022-02-27T05:04:42.953135Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from pycaret.classification import compare_models\n\nbest_model = compare_models()  # Evaluate every model: モデルを訓練し評価","metadata":{"execution":{"iopub.status.busy":"2022-02-27T05:04:50.160305Z","iopub.execute_input":"2022-02-27T05:04:50.160562Z","iopub.status.idle":"2022-02-27T05:06:43.251459Z","shell.execute_reply.started":"2022-02-27T05:04:50.160534Z","shell.execute_reply":"2022-02-27T05:06:43.250795Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from pycaret.classification import create_model\nfrom pycaret.classification import tune_model\nfrom pycaret.classification import blend_models\n\n# make each model: 個々のモデルの作成\ncat = create_model('catboost')\ngbc = create_model('gbc')\nrf = create_model('rf')\nlr = create_model('lr')\n\n# Tuning for each model: 個々のモデルのチューニング\ntuned_cat = tune_model(cat)\ntuned_gbc = tune_model(gbc)\ntuned_rf = tune_model(rf)\ntuned_lr = tune_model(lr)\n\n# Blend: ブレンド実施\nblender_specific = blend_models(estimator_list = [tuned_cat,tuned_gbc,tuned_rf,tuned_lr], method = 'soft')","metadata":{"execution":{"iopub.status.busy":"2022-02-27T05:33:39.858026Z","iopub.execute_input":"2022-02-27T05:33:39.858577Z","iopub.status.idle":"2022-02-27T05:37:59.007644Z","shell.execute_reply.started":"2022-02-27T05:33:39.858541Z","shell.execute_reply":"2022-02-27T05:37:59.006919Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(blender_specific)","metadata":{"execution":{"iopub.status.busy":"2022-02-27T05:38:13.268748Z","iopub.execute_input":"2022-02-27T05:38:13.269129Z","iopub.status.idle":"2022-02-27T05:38:13.281536Z","shell.execute_reply.started":"2022-02-27T05:38:13.269083Z","shell.execute_reply":"2022-02-27T05:38:13.280061Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from pycaret.classification import finalize_model\n\nfinal_model = finalize_model(blender_specific)\nprint(final_model)","metadata":{"execution":{"iopub.status.busy":"2022-02-27T05:17:05.483874Z","iopub.execute_input":"2022-02-27T05:17:05.484475Z","iopub.status.idle":"2022-02-27T05:17:33.490503Z","shell.execute_reply.started":"2022-02-27T05:17:05.484441Z","shell.execute_reply":"2022-02-27T05:17:33.489762Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from pycaret.classification import predict_model\n\ntest_pred = predict_model(blender_specific, data=test_data)  # Predict: 予測\ntest_pred.head()","metadata":{"execution":{"iopub.status.busy":"2022-02-27T05:38:49.231128Z","iopub.execute_input":"2022-02-27T05:38:49.231596Z","iopub.status.idle":"2022-02-27T05:38:50.065574Z","shell.execute_reply.started":"2022-02-27T05:38:49.231557Z","shell.execute_reply":"2022-02-27T05:38:50.064855Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Submission\nsubm_data = test_pred[[\"PassengerId\", \"Label\"]] \nsubm_data = subm_data.rename(columns={\"Label\" : \"Survived\"}) \n\n# save as submission file: 提出用のcsvファイルを保存\nsubm_data.to_csv(\"submission_titanic3.csv\", index=False)\n\nsubm_data","metadata":{"execution":{"iopub.status.busy":"2022-02-27T05:38:57.518485Z","iopub.execute_input":"2022-02-27T05:38:57.518735Z","iopub.status.idle":"2022-02-27T05:38:57.534812Z","shell.execute_reply.started":"2022-02-27T05:38:57.518707Z","shell.execute_reply":"2022-02-27T05:38:57.53401Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}