0

I am training a DRFModel and while evaluating receiving an exception: Exception in thread "main" java.lang.ClassCastException: hex.ModelMetricsRegression cannot be cast to hex.ModelMetricsBinomial.

The data has a column called "label" that contains 0 or 1, and that is the target column: dRFParameters._response_column = "label". Looks like the model treats the target column values as real numbers.

I had this problem with the python API as well and fixed by using the following on the H2OFrame: hdf['label'] = hdf['label'].asfactor(). I am new to scala and h2o. I was wondering what is the best way to force h2o to treat the target column in the H2OFrame to be binary (Integer).

(This is my first question on stack overflow. Let me know if I need to be more specific or attach the entire code. Thanks.)

S.P.
  • 41
  • 5

2 Answers2

1

If anyone can still provide an elegant answer to my original question, that'd be appreciated. But I found the .replace() methods on H2OFrame to be helpful. I had to use something like

for( i <- 0 until h2oFrame.numCols()) h2oFrame.replace(i, h2oFrame.vec(i).toCategoricalVec)

which solved my problem.

S.P.
  • 41
  • 5
0

The solution you mentioned is the one only available at the moment at H2O.

You can make it little better by removing the returned Vec if you don't need this Vec anymore. It deletes the previous Vector from internal H2O's DKV store. The deletion is not done automatically, since in some cases you may decide to keep old Vec as well.

for( i <- 0 until h2oFrame.numCols()){
  h2oFrame.replace(i, h2oFrame.vec(i).toCategoricalVec).remove()
}

If you just want to turn one column to categorial, you can do

h2oFrame.replace(h2oFrame.find("target"),h2oFrame.vec("target").toCategoricalVec).remove()
Jakub Háva
  • 228
  • 1
  • 5