user3342643
user3342643

Reputation: 749

Operation not allowed on string vector in H2o package

I get the following error when I run a random forest model using H2o package.

Error: DistributedException from localhost/127.0.0.1:54321, caused by java.lang.IllegalArgumentException: Operation not allowed on string vector.

The code I ran was as follows:-

fit = h2o.randomForest(x = indep, y = dep, training_frame = QCAnalysis_sub_h2o, seed = 1234, ntrees = 500, mtries = 3, max_depth = 50)

Kindly clarify on the error.

Upvotes: 2

Views: 3096

Answers (2)

tylers
tylers

Reputation: 1

Some sample codes:

QCAnalysis_sub_h2o <- h2o.importFile(path = normalizePath("QCAnalysis_sub_h2o.csv"),header=T)

(if not, specify the dataframe with as.data.frame )

x and y should state the columns you want h2o.randomforest to read

Upvotes: 0

Erin LeDell
Erin LeDell

Reputation: 8819

Make sure that class(QCAnalysis_sub_h2o) is "H2OFrame" and that your indep vector doesn't contain any columns that are strings. Also, note that when converting an R data.frame to an H2O Frame using as.h2o(), it preserves the column types, so it won't automatically convert any string columns into factors. You will need to do that automatically using the as.factor() function on each column (e.g. df[,"mycol"] <- as.factor(df[,"mycol"]). You can do this on your R data.frame before you copy over to H2O, or you can fix the columns once they are in the H2O Frame.

If you read in a CSV file from disk directly into H2O using the h2o.importFile() command, it will turn any column containing strings into factors by default, so I assume that you probably copied this frame over from R.

Upvotes: 3

Related Questions