{"cells":[{"metadata":{},"cell_type":"markdown","source":"[H2O AutoML](http://docs.h2o.ai/h2o/latest-stable/h2o-docs/automl.html) is an automated machine learning meta-algorithm that is part of the [H2O software library](http://docs.h2o.ai/h2o/latest-stable/h2o-py/docs/intro.html#what-is-h2o). (It shold not be confused with [H2O DriverlessAI](https://www.h2o.ai/products/h2o-driverless-ai/), which is a commercial product and built from an entirely different code base.) H2O’s AutoML can be used for automating the machine learning workflow, which includes automatic training and tuning of many models within a user-specified time-limit. Stacked Ensembles – one based on all previously trained models, another one on the best model of each family – will be automatically trained on collections of individual models to produce highly predictive ensemble models which, in most cases, will be the top performing models in the AutoML Leaderboard."},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"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 in \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 \"../input/\" directory.\n# For example, running this (by clicking run or pressing Shift+Enter) will list the files in the input directory\n\nimport os\nprint(os.listdir(\"../input\"))\n\n# Any results you write to the current directory are saved as output.","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":true},"cell_type":"code","source":"print(os.listdir(\"../input/andrews-features-only\"))\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"0be78c0dd2e3a95f6f87bffafba9f138f70dd893"},"cell_type":"code","source":"import h2o\nprint(h2o.__version__)\nfrom h2o.automl import H2OAutoML\n\nh2o.init(max_mem_size='16G')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"82931a909e601f27dd14c6b8fa3706d378cd10a2"},"cell_type":"code","source":"train = h2o.import_file(\"../input/andrews-features-only/X_tr.csv\")\ntest = h2o.import_file(\"../input/andrews-features-only/X_test.csv\")\ny_train = h2o.import_file(\"../input/andrews-features-only/y_tr.csv\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"e9ad4c8900cef210b9f1d569f9d0f703dc03d8ec"},"cell_type":"code","source":"train.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"4e64dc8eae125d7901f85fe448b1a66d9826c7d9"},"cell_type":"code","source":"train['time_to_failure'] = y_train['time_to_failure']","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"61dbd6943bada1efc1b796f14bd3bebe4af9b82a"},"cell_type":"code","source":"train.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"85b81e540dc7dcf9318176ec414b3accf2271175"},"cell_type":"code","source":"test.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"76ded483948203283f906f3fbbb0989cb1f02eb7"},"cell_type":"code","source":"x = test.columns\ny = 'time_to_failure'","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"e52a9b27ef9c8d034a7f1c24e5ea35ff353a0d23"},"cell_type":"code","source":"aml = H2OAutoML(max_models=1000, seed=121, max_runtime_secs=31000)\naml.train(x=x, y=y, training_frame=train)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"f2ac0c86a2feaf02b60f6a598bafc8b107f416cc"},"cell_type":"code","source":"# View the AutoML Leaderboard\nlb = aml.leaderboard\nlb.head(rows=lb.nrows)  # Print all rows instead of default (10 rows)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"e0291089fc2252d5b629da28ceaee61636f816b2"},"cell_type":"code","source":"# The leader model is stored here\naml.leader","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"4e17f770534985ca65496f056a4ba12b2add0c52"},"cell_type":"code","source":"# If you need to generate predictions on a test set, you can make\n# predictions directly on the `\"H2OAutoML\"` object, or on the leader\n# model object directly\n\npreds = aml.predict(test)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"54e5d315397bf1ab5681a228555f7d9e6ad686da"},"cell_type":"code","source":"sample_submission = pd.read_csv('../input/LANL-Earthquake-Prediction/sample_submission.csv')\nsample_submission['time_to_failure'] = preds.as_data_frame().values.flatten()\nsample_submission.to_csv('h2o_submission_8.csv', index=False)","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.6.6","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat":4,"nbformat_minor":1}