Over a million developers have joined DZone.

Adding Hidden Layers to H2O-Based Deep Learning Algorithms [Code Snippet]

DZone's Guide to

Adding Hidden Layers to H2O-Based Deep Learning Algorithms [Code Snippet]

Get the Scala code snippet that is required for adding hidden layers in an H2O-based deep learning algorithm.

· AI Zone
Free Resource

Insight for I&O leaders on deploying AIOps platforms to enhance performance monitoring today. Read the Guide.

A hidden layer is a hyper parameter for a deep learning algorithm in H2O. To use the hidden layer setting in H2O-based deep learning, you should be using the _hidden parameter to specify the hidden later as shown in the hyper parameter as below:

val hyperParms = collection.immutable.HashMap("_hidden" -> hidden_layers)

Here is the code snippet in Scala to add hidden layers in an H2O-based deep learning algorithm:

val dlParams = new DeepLearningParameters()
dlParams._train = airlinesData
dlParams._activation =  DeepLearningModel.DeepLearningParameters.Activation.Tanh
dlParams._epochs = 1
dlParams._autoencoder = true

dlParams._ignore_const_cols = false
dlParams._stopping_rounds = 0

dlParams._score_training_samples = 0
dlParams._replicate_training_data = false
dlParams._standardize = true

import collection.JavaConversions._
val hidden_layers = Array(Array(1, 5, 1), Array(1, 6, 1), Array(1, 7, 1)).map(_.asInstanceOf[Object])
val hyperParms = collection.immutable.HashMap("_hidden" -> hidden_layers)

def let[A](in: A)(body: A => Unit) = {

import _root_.hex.grid.GridSearch
import _root_.hex.grid.HyperSpaceSearchCriteria.RandomDiscreteValueSearchCriteria
import _root_.hex.ScoreKeeper
    val intRateHyperSpaceCriteria = let(new RandomDiscreteValueSearchCriteria) { c =>
      c.set_max_runtime_secs(40 * 60 /* seconds */)

val intRateGrid = GridSearch.startGridSearch(Key.make("intRateGridModel                                                dlParams,
                                                 new GridSearch.SimpleParametersBuilderFactory[DeepLearningParameters],
val count = intRateGrid.getModelCount()

That's it. Enjoy!

TrueSight is an AIOps platform, powered by machine learning and analytics, that elevates IT operations to address multi-cloud complexity and the speed of digital transformation.

ai ,algorithm ,scala ,h2o ,deep learning ,parameters

Published at DZone with permission of Avkash Chauhan, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}