{"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":"markdown","source":"<a href=\"https://github.com/AutoViML/featurewiz\"><img src=\"https://i.ibb.co/ZLdZMZg/featurewiz-logos.png\" alt=\"featurewiz-logos\" border=\"0\"></a>","metadata":{}},{"cell_type":"markdown","source":"### This notebook is derived from Kaggle Grandmaster Bojan Tunguz's NB\nhttps://www.kaggle.com/tunguz/elo-with-h2o-automl\n<br>This notebook merely builds on his fantastic feature engineering (194 features!) and tries to build a better model using featurewiz library's feature selection.<br>You can see its github here:\nGithub: https://github.com/AutoViML/featurewiz","metadata":{}},{"cell_type":"markdown","source":"# Warning: You must install xlrd after installing featurewiz without dependencies. That's the best way to install it smoothly.","metadata":{"execution":{"iopub.status.busy":"2021-07-02T20:26:32.428242Z","iopub.execute_input":"2021-07-02T20:26:32.42887Z","iopub.status.idle":"2021-07-02T20:26:32.434145Z","shell.execute_reply.started":"2021-07-02T20:26:32.428746Z","shell.execute_reply":"2021-07-02T20:26:32.433305Z"}}},{"cell_type":"code","source":"!pip install featurewiz --ignore-installed --no-deps","metadata":{"_kg_hide-output":true,"execution":{"iopub.status.busy":"2022-04-04T01:15:40.016385Z","iopub.execute_input":"2022-04-04T01:15:40.016736Z","iopub.status.idle":"2022-04-04T01:15:43.395273Z","shell.execute_reply.started":"2022-04-04T01:15:40.016654Z","shell.execute_reply":"2022-04-04T01:15:43.394341Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install xlrd","metadata":{"execution":{"iopub.status.busy":"2022-04-04T01:15:45.914288Z","iopub.execute_input":"2022-04-04T01:15:45.914725Z","iopub.status.idle":"2022-04-04T01:15:52.736270Z","shell.execute_reply.started":"2022-04-04T01:15:45.914684Z","shell.execute_reply":"2022-04-04T01:15:52.735338Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"### AFTER YOU INSTALL IT, YOU MUST COMMENT IT OUT AND RESTART THE KERNEL.\nimport featurewiz as FW","metadata":{"execution":{"iopub.status.busy":"2022-04-04T01:15:52.739791Z","iopub.execute_input":"2022-04-04T01:15:52.740072Z","iopub.status.idle":"2022-04-04T01:15:56.416388Z","shell.execute_reply.started":"2022-04-04T01:15:52.740044Z","shell.execute_reply":"2022-04-04T01:15:56.415276Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import 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-04-04T01:15:59.340678Z","iopub.execute_input":"2022-04-04T01:15:59.341006Z","iopub.status.idle":"2022-04-04T01:15:59.359250Z","shell.execute_reply.started":"2022-04-04T01:15:59.340976Z","shell.execute_reply":"2022-04-04T01:15:59.358258Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = pd.read_csv(\"../input/mitsuru-features-only-train-and-test/train_df_noindex.csv\")\ntest = pd.read_csv(\"../input/mitsuru-features-only-train-and-test/test_df_noindex.csv\")\nprint(train.shape)\ntrain.head()","metadata":{"execution":{"iopub.status.busy":"2022-04-04T01:16:02.627940Z","iopub.execute_input":"2022-04-04T01:16:02.628271Z","iopub.status.idle":"2022-04-04T01:16:15.966861Z","shell.execute_reply.started":"2022-04-04T01:16:02.628239Z","shell.execute_reply":"2022-04-04T01:16:15.965828Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# This is a dataset with large number of samples as well as features","metadata":{}},{"cell_type":"code","source":"print(test.shape)\ntest.head(1)","metadata":{"execution":{"iopub.status.busy":"2022-04-04T01:16:26.000420Z","iopub.execute_input":"2022-04-04T01:16:26.000785Z","iopub.status.idle":"2022-04-04T01:16:26.022276Z","shell.execute_reply.started":"2022-04-04T01:16:26.000752Z","shell.execute_reply":"2022-04-04T01:16:26.021307Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"target = \"target\"","metadata":{"execution":{"iopub.status.busy":"2022-04-04T01:16:28.049050Z","iopub.execute_input":"2022-04-04T01:16:28.049374Z","iopub.status.idle":"2022-04-04T01:16:28.054396Z","shell.execute_reply.started":"2022-04-04T01:16:28.049342Z","shell.execute_reply":"2022-04-04T01:16:28.053374Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Featurewiz needs a small sample for faster results. Let's start with 100K rows","metadata":{}},{"cell_type":"code","source":"train_best, test_best = FW.featurewiz(train, target, test_data=test,\n                              dask_xgboost_flag = False,\n                              nrows=200000)","metadata":{"execution":{"iopub.status.busy":"2022-04-04T01:16:32.468330Z","iopub.execute_input":"2022-04-04T01:16:32.468707Z","iopub.status.idle":"2022-04-04T01:24:50.759430Z","shell.execute_reply.started":"2022-04-04T01:16:32.468670Z","shell.execute_reply":"2022-04-04T01:24:50.758564Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(train_best.shape, test_best.shape)","metadata":{"execution":{"iopub.status.busy":"2022-04-04T01:25:07.435215Z","iopub.execute_input":"2022-04-04T01:25:07.435539Z","iopub.status.idle":"2022-04-04T01:25:07.441641Z","shell.execute_reply.started":"2022-04-04T01:25:07.435506Z","shell.execute_reply":"2022-04-04T01:25:07.439847Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"preds2  = test_best.columns.tolist()\nlen(preds2)","metadata":{"execution":{"iopub.status.busy":"2022-04-04T01:25:26.099254Z","iopub.execute_input":"2022-04-04T01:25:26.099674Z","iopub.status.idle":"2022-04-04T01:25:26.105630Z","shell.execute_reply.started":"2022-04-04T01:25:26.099637Z","shell.execute_reply":"2022-04-04T01:25:26.104450Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"outputs = FW.complex_XGBoost_model(train_best[preds2], \n                                   train_best[target],\n                               test_best[preds2], \n                                log_y=False, GPU_flag=True,\n                                   verbose= -1)","metadata":{"execution":{"iopub.status.busy":"2022-04-04T01:25:40.136934Z","iopub.execute_input":"2022-04-04T01:25:40.137365Z","iopub.status.idle":"2022-04-04T01:25:43.154170Z","shell.execute_reply.started":"2022-04-04T01:25:40.137323Z","shell.execute_reply":"2022-04-04T01:25:43.153372Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_preds = outputs[0]\ny_preds","metadata":{"execution":{"iopub.status.busy":"2022-04-04T01:25:48.295295Z","iopub.execute_input":"2022-04-04T01:25:48.295628Z","iopub.status.idle":"2022-04-04T01:25:48.301834Z","shell.execute_reply.started":"2022-04-04T01:25:48.295596Z","shell.execute_reply":"2022-04-04T01:25:48.300723Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub = pd.read_csv('/kaggle/input/elo-merchant-category-recommendation/sample_submission.csv')\nprint(sub.shape)\nsub.head()","metadata":{"execution":{"iopub.status.busy":"2022-04-04T01:25:52.497304Z","iopub.execute_input":"2022-04-04T01:25:52.497641Z","iopub.status.idle":"2022-04-04T01:25:52.607377Z","shell.execute_reply.started":"2022-04-04T01:25:52.497610Z","shell.execute_reply":"2022-04-04T01:25:52.606432Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub[target] = y_preds\nsub.head()","metadata":{"execution":{"iopub.status.busy":"2022-04-04T01:25:55.529905Z","iopub.execute_input":"2022-04-04T01:25:55.530311Z","iopub.status.idle":"2022-04-04T01:25:55.540512Z","shell.execute_reply.started":"2022-04-04T01:25:55.530263Z","shell.execute_reply":"2022-04-04T01:25:55.539585Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub.to_csv('submission.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2022-04-04T01:25:58.784123Z","iopub.execute_input":"2022-04-04T01:25:58.784458Z","iopub.status.idle":"2022-04-04T01:25:59.190221Z","shell.execute_reply.started":"2022-04-04T01:25:58.784428Z","shell.execute_reply":"2022-04-04T01:25:59.189285Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}