Step 5 - Preparing the H2O DataFrame

Up to this point, our DataFrame (that is, t4) is in Spark DataFrame. But it cannot be consumed by the H2O model. So, we have to convert it to an H2O frame. So let's do it:

val creditcard_hf: H2OFrame = h2oContext.asH2OFrame(t4.orderBy(rand()))

We split the dataset to, say, 40% supervised training, 40% unsupervised training, and 20% test using H2O built-in splitter called FrameSplitter:

val sf = new FrameSplitter(creditcard_hf, Array(.4, .4), 
Array("train_unsupervised", "train_supervised", "test")
.map(Key.make[Frame](_)), null)

water.H2O.submitTask(sf)
val splits = sf.getResult
val (train_unsupervised, train_supervised, test) = (splits(0), splits(1), splits(2))

In the above code segment, Key.make[Frame](_) is used as a low-level task to split the frame based on the split ratio that also help attain distributed Key/Value pairs.

Keys are very crucial in H2O computing. H2O supports a distributed Key/Value store, with exact Java memory model consistency. The thing is that Keys are a means to find a link value somewhere in the Cloud, to cache it locally, to allow globally consistent updates to a link Value.   

Finally, we need to convert the Time column from String to Categorical (that is, enum) explicitly:

toCategorical(train_unsupervised, 30)
toCategorical(train_supervised, 30)
toCategorical(test, 30)
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset