简体   繁体   English

在使用 H2O R model 进行预测时使用 optim package 时出错

[英]Error using optim package while predicting with an H2O R model

In R, there is a very convenient optimization package called "optim" .在 R 中,有一个非常方便的优化 package 叫做“optim” You can feed it a function, an initial position, and sometimes other control input, and it will optimize your function.你可以给它一个 function,一个初始的 position,有时还有其他控制输入,它会优化你的 function。

I am trying to use this with h2o.ai model in the following way:我正在尝试通过以下方式将其与 h2o.ai model 一起使用:

make_model <- h2o.stuff(x,y,training, parameters)
f <- function(x,make_model){ h2o.predict() %>% ...}
f2 <- function(x){f(x,make_model)}

optim(start, function=f2, ...)

When I run test cases they work:当我运行测试用例时,它们会起作用:

f2(start_point) 
f2(known_values)

These return exactly what I'm looking for.这些返回正是我正在寻找的。 They return the values they should.它们返回应有的值。

When I try to run the optim on the function, it doesn't want to work, and gives this error:当我尝试在 function 上运行 optim 时,它不想工作,并给出此错误:

java.lang.IllegalArgumentException: Test/Validation dataset has no columns in common with the training set

java.lang.IllegalArgumentException: Test/Validation dataset has no columns in common with the training set
    at hex.Model.adaptTestForTrain(Model.java:1383)
    at hex.Model.adaptTestForTrain(Model.java:1222)
    at hex.Model.score(Model.java:1509)
    at water.api.ModelMetricsHandler$1.compute2(ModelMetricsHandler.java:396)
    at water.H2O$H2OCountedCompleter.compute(H2O.java:1557)
    at jsr166y.CountedCompleter.exec(CountedCompleter.java:468)
    at jsr166y.ForkJoinTask.doExec(ForkJoinTask.java:263)
    at jsr166y.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:974)
    at jsr166y.ForkJoinPool.runWorker(ForkJoinPool.java:1477)
    at jsr166y.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:104)

Error: java.lang.IllegalArgumentException: Test/Validation dataset has no columns in common with the training set
Called from: doTryCatch(return(expr), name, parentenv, handler)

Now it looks to me like the C-based optim and the Java based h2o.ai don't want to play well together.现在在我看来,基于 C 的 optim 和基于 Java 的 h2o.ai 并不想一起玩得很好。 The function is a bit nonlinear, but it evaluates the known points directly and properly. function 有点非线性,但它可以直接正确地评估已知点。

Is there a decent way to get around this without changing architectures?有没有一种体面的方法可以在不改变架构的情况下解决这个问题?

I don't think this error has anything to do with using the optim package.我认为这个错误与使用 optim package 没有任何关系。 That is an error from the H2O package which just that "Test/Validation dataset has no columns in common with the training set" .这是来自 H2O package 的错误,它只是"Test/Validation dataset has no columns in common with the training set"

So you should check the column names of your test set (or whatever dataset you're passing to the h2o.predict() function) to make sure it looks like your training set (all training columns should be present in test set).因此,您应该检查测试集的列名(或您传递给h2o.predict()函数的任何数据集),以确保它看起来像您的训练集(所有训练列都应该存在于测试集中)。 If you can post a reproducible example, I can probably be more helpful.如果您可以发布一个可重现的示例,我可能会更有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM