Search code examples
rsaveh2ofeature-engineering

R H2O target encoding model - Saving and Loading


I'm using H2O target encoding to treat some of my factor variables. However, I think I stumble into a problem.

I can use the function easily, and had thus both created and applyed a target encoding "model". However, I need to be able to save said model and use it latter (as one does for example with actual H2O models).

I have save the model object with R's save function, and now I can not use it after loading (Got

ERROR: Unexpected HTTP Status code: 404 Not Found (url = http://localhost:54014/3/Frames/RTMP_sid_93aa_3?row_count=10)

water.exceptions.H2OKeyNotFoundArgumentException
 [1] "water.exceptions.H2OKeyNotFoundArgumentException: Object 'RTMP_sid_93aa_3' not found for argument: key"             
 [2] "    water.api.FramesHandler.getFromDKV(FramesHandler.java:135)"                                                     
 [3] "    water.api.FramesHandler.doFetch(FramesHandler.java:225)"                                                        
 [4] "    water.api.FramesHandler.doFetch(FramesHandler.java:220)"                                                        
 [5] "    water.api.FramesHandler.fetch(FramesHandler.java:199)"                                                          
 [6] "    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)"                                                    
 [7] "    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)"                                  
 [8] "    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)"                          
 [9] "    java.lang.reflect.Method.invoke(Method.java:497)"                                                               
[10] "    water.api.Handler.handle(Handler.java:63)"                                                                      
[11] "    water.api.RequestServer.serve(RequestServer.java:482)"                                                          
[12] "    water.api.RequestServer.doGeneric(RequestServer.java:327)"                                                      
[13] "    water.api.RequestServer.doGet(RequestServer.java:251)"                                                          
[14] "    javax.servlet.http.HttpServlet.service(HttpServlet.java:735)"                                                   
[15] "    javax.servlet.http.HttpServlet.service(HttpServlet.java:848)"                                                   
[16] "    org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:684)"                                         
[17] "    org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:501)"                                     
[18] "    org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1086)"                             
[19] "    org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:427)"                                      
[20] "    org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1020)"                              
[21] "    org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)"                                  
[22] "    org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:154)"                          
[23] "    org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)"                                
[24] "    water.webserver.jetty8.Jetty8ServerAdapter$LoginHandler.handle(Jetty8ServerAdapter.java:119)"                   
[25] "    org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:154)"                          
[26] "    org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)"                                
[27] "    org.eclipse.jetty.server.Server.handle(Server.java:370)"                                                        
[28] "    org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:494)"                 
[29] "    org.eclipse.jetty.server.BlockingHttpConnection.handleRequest(BlockingHttpConnection.java:53)"                  
[30] "    org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:973)"                
[31] "    org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:1035)"
[32] "    org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:641)"                                               
[33] "    org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:231)"                                          
[34] "    org.eclipse.jetty.server.BlockingHttpConnection.handle(BlockingHttpConnection.java:72)"                         
[35] "    org.eclipse.jetty.server.bio.SocketConnector$ConnectorEndPoint.run(SocketConnector.java:264)"                   
[36] "    org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)"                               
[37] "    org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)"                                
[38] "    java.lang.Thread.run(Thread.java:745)"                                                                          

Error in .h2o.doSafeREST(h2oRestApiVersion = h2oRestApiVersion, urlSuffix = page,  : 


ERROR MESSAGE:

Object 'RTMP_sid_93aa_3' not found for argument: key

Two questions:

1 - Is there a way to still use the encoding I save this way?

2 - How should I save it and load it?


Solution

  • Unfortunately, there is no support for saving encoding maps in the model yet. But this is something we are working on right now. To answer your questions:

    1. No, for now model object has no information about encoding maps. Model takes data as input and have no idea about whether target encoding was applied or not.
    2. As for now you can't save encodings along with the model.