使用h2o.randomForest保存模型的预测

时间:2016-07-21 17:19:11

标签: r random-forest h2o

我已经在Rstudio中使用h2o库训练了一个随机森林模型,然后我将其保存为.rda文件,现在我想使用模型buildt对其他数据进行评分。 所以我加载模型我已经在H2OFrame中转换了新数据集,并尝试使用 ERROR: Unexpected HTTP Status code: 404 Not Found (url = http://localhost:54321/4/Predictions/models/DRF_model_R_1468754145815_1/frames/file1840210c1889_sid_9b90_2) water.exceptions.H2OKeyNotFoundArgumentException [1] "water.exceptions.H2OKeyNotFoundArgumentException: Object 'DRF_model_R_1468754145815_1' not found in function: predict for argument: model" [2] " water.api.ModelMetricsHandler.predict2(ModelMetricsHandler.java:239)" [3] " sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)" [4] " sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)" [5] " sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)" [6] " java.lang.reflect.Method.invoke(Method.java:498)" [7] " water.api.Handler.handle(Handler.java:62)" [8] " water.api.RequestServer.handle(RequestServer.java:655)" [9] " water.api.RequestServer.serve(RequestServer.java:596)" [10] " water.JettyHTTPD$H2oDefaultServlet.doGeneric(JettyHTTPD.java:745)" [11] " water.JettyHTTPD$H2oDefaultServlet.doPost(JettyHTTPD.java:681)" [12] " javax.servlet.http.HttpServlet.service(HttpServlet.java:755)" [13] " javax.servlet.http.HttpServlet.service(HttpServlet.java:848)" [14] " org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:684)" [15] " org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:503)" [16] " org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)" [17] " org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:557)" [18] " org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)" [19] " org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1086)" [20] " org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:429)" [21] " org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)" [22] " org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1020)" [23] " org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)" [24] " org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:154)" [25] " org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)" [26] " org.eclipse.jetty.server.Server.handle(Server.java:370)" [27] " org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:494)" [28] " org.eclipse.jetty.server.BlockingHttpConnection.handleRequest(BlockingHttpConnection.java:53)" [29] " org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:971)" [30] " org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:1033)" [31] " org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:644)" [32] " org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)" [33] " org.eclipse.jetty.server.BlockingHttpConnection.handle(BlockingHttpConnection.java:72)" [34] " org.eclipse.jetty.server.bio.SocketConnector$ConnectorEndPoint.run(SocketConnector.java:264)" [35] " org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)" [36] " org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)" [37] " java.lang.Thread.run(Thread.java:745)" Error in .h2o.doSafeREST(h2oRestApiVersion = h2oRestApiVersion, urlSuffix = page, : ERROR MESSAGE: Object 'DRF_model_R_1468754145815_1' not found in function: predict for argument: model 函数获得分数。 我得到的是以下错误消息:

{{1}}

我是H2O的新手..对于出了什么问题的任何想法?

1 个答案:

答案 0 :(得分:1)

您无法从R内部将其另存为rda文件。模型存在于H2O群集中,您必须使用h2o.saveModel()进行保存。然后h2o.loadModel()再次加载它。请参阅?h2o.saveModel?h2o.loadModel

BTW,请注意函数之间的不对称性:给saveModel一个目录,然后给loadModel一个文件名。 (文件名将是型号ID。)