当我使用 H2o 包运行随机森林模型时,出现以下错误。
Error: DistributedException from localhost/127.0.0.1:54321, caused by java.lang.IllegalArgumentException: Operation not allowed on string vector.
我运行的代码如下:-
fit = h2o.randomForest(x = indep, y = dep, training_frame = QCAnalysis_sub_h2o, seed = 1234, ntrees = 500, mtries = 3, max_depth = 50)
请澄清错误。
最佳答案
确保class(QCAnalysis_sub_h2o)
是“H2OFrame”,您的 indep
矢量不包含任何字符串列。另请注意,使用 as.h2o()
将 R data.frame 转换为 H2O Frame 时,它保留列类型,因此不会自动将任何字符串列转换为因子。您需要使用 as.factor()
自动执行此操作每列上的函数(例如 df[,"mycol"] <- as.factor(df[,"mycol"]
)。您可以在复制到 H2O 之前在 R data.frame 上执行此操作,或者可以在列位于 H2O 框架中后修复它们。
如果您使用 h2o.importFile()
将 CSV 文件从磁盘直接读入 H2O命令,默认情况下它会将任何包含字符串的列转换为因子,因此我假设您可能从 R 复制了此框架。
关于r - 不允许对 H2o 包中的字符串向量进行操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43515721/