{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false, "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Checking whether there is an H2O instance running at http://localhost:54321. connected.\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
H2O cluster uptime:57 mins 57 secs
H2O cluster version:3.11.0.99999
H2O cluster version age:20 hours and 30 minutes
H2O cluster name:arno
H2O cluster total nodes:1
H2O cluster free memory:13.57 Gb
H2O cluster total cores:12
H2O cluster allowed cores:12
H2O cluster status:locked, healthy
H2O connection url:http://localhost:54321
H2O connection proxy:None
Python version:2.7.12 final
" ], "text/plain": [ "-------------------------- -----------------------\n", "H2O cluster uptime: 57 mins 57 secs\n", "H2O cluster version: 3.11.0.99999\n", "H2O cluster version age: 20 hours and 30 minutes\n", "H2O cluster name: arno\n", "H2O cluster total nodes: 1\n", "H2O cluster free memory: 13.57 Gb\n", "H2O cluster total cores: 12\n", "H2O cluster allowed cores: 12\n", "H2O cluster status: locked, healthy\n", "H2O connection url: http://localhost:54321\n", "H2O connection proxy:\n", "Python version: 2.7.12 final\n", "-------------------------- -----------------------" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import h2o\n", "import os.path\n", "from collections import OrderedDict\n", "from builtins import range\n", "from h2o.estimators.deepwater import H2ODeepWaterEstimator\n", "from h2o.grid.grid_search import H2OGridSearch\n", "h2o.init(nthreads=-1)\n", "\n", "PATH=os.path.expanduser(\"~/h2o-3/\")" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Sun Oct 23 23:16:00 2016 \r\n", "+-----------------------------------------------------------------------------+\r\n", "| NVIDIA-SMI 367.44 Driver Version: 367.44 |\r\n", "|-------------------------------+----------------------+----------------------+\r\n", "| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |\r\n", "| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |\r\n", "|===============================+======================+======================|\r\n", "| 0 GeForce GTX 980 Ti Off | 0000:01:00.0 On | N/A |\r\n", "| 9% 62C P0 74W / 275W | 854MiB / 6076MiB | 2% Default |\r\n", "+-------------------------------+----------------------+----------------------+\r\n", "| 1 TITAN X (Pascal) Off | 0000:02:00.0 Off | N/A |\r\n", "| 27% 48C P2 53W / 250W | 456MiB / 12189MiB | 0% Default |\r\n", "+-------------------------------+----------------------+----------------------+\r\n", " \r\n", "+-----------------------------------------------------------------------------+\r\n", "| Processes: GPU Memory |\r\n", "| GPU PID Type Process name Usage |\r\n", "|=============================================================================|\r\n", "| 0 1642 G /usr/lib/xorg/Xorg 588MiB |\r\n", "| 0 2590 G compiz 183MiB |\r\n", "| 0 10779 G ...ivePortalInterstitial/Enabled/ChildAccoun 78MiB |\r\n", "| 1 13724 C /usr/lib/jvm/java-8-oracle/bin/java 453MiB |\r\n", "+-----------------------------------------------------------------------------+\r\n" ] } ], "source": [ "!nvidia-smi" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Parse progress: |█████████████████████████████████████████████████████████████████████████████| 100%\n" ] } ], "source": [ "train = h2o.import_file(PATH + \"smalldata/iris/iris_wheader.csv\")\n", "predictors = list(range(0,4))\n", "response_col = 4" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{'learning_rate': [0.001, 0.002, 0.003, 0.004, 0.005, 0.006, 0.007, 0.008, 0.009], 'hidden': [[20, 20], [50, 50, 50], [200, 200], [50, 50, 50, 50, 50]], 'activation': ['tanh', 'rectifier']}\n" ] } ], "source": [ "hyper_parameters = {\n", " 'hidden' : [[20,20],[50,50,50],[200,200],[50,50,50,50,50]],\n", " 'activation' : [\"tanh\",\"rectifier\"],\n", " 'learning_rate' : [lr/1e3 for lr in range(1,10)] \n", "}\n", "\n", "parameters = {\n", " 'seed' : 42,\n", " 'epochs' : 500,\n", " 'nfolds' : 3,\n", " 'stopping_rounds' : 3, ## enable early stopping of each model in the hyperparameter search\n", " 'stopping_metric' : \"logloss\",\n", " 'stopping_tolerance' : 1e-3 ## stop once validation logloss of the cv models doesn't improve enough\n", "}\n", "\n", "search_criteria = {\n", " 'strategy': \"RandomDiscrete\",\n", " 'max_runtime_secs': 30, ## limit the runtime to 30 seconds\n", " 'max_models': 100, ## build no more than 100 models\n", " 'seed' : 42,\n", " 'stopping_rounds' : 5, ## enable early stopping of the overall leaderboard\n", " 'stopping_metric' : \"logloss\",\n", " 'stopping_tolerance': 1e-4\n", "} \n", "print(hyper_parameters)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "deepwater Grid Build progress: |██████████████████████████████████████████████████████████████| 100%\n" ] } ], "source": [ "gs = H2OGridSearch(H2ODeepWaterEstimator,\n", " hyper_params=hyper_parameters,\n", " search_criteria=search_criteria)\n", "gs.train(x=predictors, y=response_col, training_frame=train, **parameters)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " activation hidden learning_rate \\\n", "0 Tanh [20, 20] 0.009 \n", "1 Tanh [20, 20] 0.007 \n", "2 Tanh [50, 50, 50] 0.004 \n", "3 Tanh [200, 200] 0.006 \n", "4 Tanh [50, 50, 50, 50, 50] 0.003 \n", "5 Tanh [200, 200] 0.002 \n", "6 Rectifier [200, 200] 0.001 \n", "7 Rectifier [200, 200] 0.004 \n", "8 Rectifier [20, 20] 0.001 \n", "\n", " model_ids \\\n", "0 Grid_DeepWater_iris_wheader4.hex_model_python_1477286246751_9_model_3 \n", "1 Grid_DeepWater_iris_wheader4.hex_model_python_1477286246751_9_model_4 \n", "2 Grid_DeepWater_iris_wheader4.hex_model_python_1477286246751_9_model_1 \n", "3 Grid_DeepWater_iris_wheader4.hex_model_python_1477286246751_9_model_2 \n", "4 Grid_DeepWater_iris_wheader4.hex_model_python_1477286246751_9_model_7 \n", "5 Grid_DeepWater_iris_wheader4.hex_model_python_1477286246751_9_model_6 \n", "6 Grid_DeepWater_iris_wheader4.hex_model_python_1477286246751_9_model_0 \n", "7 Grid_DeepWater_iris_wheader4.hex_model_python_1477286246751_9_model_5 \n", "8 Grid_DeepWater_iris_wheader4.hex_model_python_1477286246751_9_model_8 \n", "\n", " logloss \n", "0 0.174867823409404 \n", "1 0.2548120069902128 \n", "2 0.2847309554355027 \n", "3 0.5744841418551249 \n", "4 0.6931066094644429 \n", "5 0.6965300796568423 \n", "6 1.7458040234667165 \n", "7 2.747305024267217 \n", "8 6.0184638863365345 \n" ] }, { "data": { "text/plain": [] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "gs.get_grid(\"logloss\")" ] } ], "metadata": { "anaconda-cloud": {}, "kernelspec": { "display_name": "Python [default]", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.12" } }, "nbformat": 4, "nbformat_minor": 1 }