@Test public void testScore() { FraudScorerServlet servlet = new FraudScorerServlet(); double score = servlet.score(60000, 40, 30); System.out.println(score); }
double score(double balance, double numTrans, double creditLine) { ScriptEngine engine = ENGINE.get(); if(engine == null) { engine = initEngine(); ENGINE.set(engine); } double score; Bindings bindings = engine.getBindings(ENGINE_SCOPE); bindings.put("balance", balance); bindings.put("numTrans", numTrans); bindings.put("creditLine", creditLine); try { engine.eval("score <- data.frame(balance=balance,numTrans=numTrans,creditLine=creditLine)"); engine.eval("x <- predict(fraudModel, score)"); DoubleVector x = (DoubleVector) bindings.get("x"); score = x.getElementAsDouble(0); } catch (ScriptException e) { throw new RuntimeException("Prediction failed"); } return score; }
FraudScorerServlet extends HttpServlet { double score(double balance, double numTrans, double creditLine) { ScriptEngine engine = ENGINE.get(); if(engine == null) { engine = initEngine(); ENGINE.set(engine); } double score; Bindings bindings = engine.getBindings(ENGINE_SCOPE); bindings.put("balance", balance); bindings.put("numTrans", numTrans); bindings.put("creditLine", creditLine); try { engine.eval("score <- data.frame(balance=balance,numTrans=numTrans,creditLine=creditLine)"); engine.eval("x <- predict(fraudModel, score)"); DoubleVector x = (DoubleVector) bindings.get("x"); score = x.getElementAsDouble(0); } catch (ScriptException e) { throw new RuntimeException("Prediction failed"); } return score; } }
FraudScorerServlet extends HttpServlet { double score(double balance, double numTrans, double creditLine) { ScriptEngine engine = ENGINE.get(); if(engine == null) { engine = initEngine(); ENGINE.set(engine); } double score; Bindings bindings = engine.getBindings(ENGINE_SCOPE); bindings.put("balance", balance); bindings.put("numTrans", numTrans); bindings.put("creditLine", creditLine); try { engine.eval("score <- data.frame(balance=balance,numTrans=numTrans,creditLine=creditLine)"); engine.eval("x <- predict(fraudModel, score)"); DoubleVector x = (DoubleVector) bindings.get("x"); score = x.getElementAsDouble(0); } catch (ScriptException e) { throw new RuntimeException("Prediction failed"); } return score; }  }
FraudScorerServlet extends HttpServlet { double score(double balance, double numTrans, double creditLine) { ScriptEngine engine = ENGINE.get(); if(engine == null) { engine = initEngine(); ENGINE.set(engine); } double score; Bindings bindings = engine.getBindings(ENGINE_SCOPE); bindings.put("balance", balance); bindings.put("numTrans", numTrans); bindings.put("creditLine", creditLine); try { engine.eval("score <- data.frame(balance=balance,numTrans=numTrans,creditLine=creditLine)"); engine.eval("x <- predict(fraudModel, score)"); DoubleVector x = (DoubleVector) bindings.get("x"); score = x.getElementAsDouble(0); } catch (ScriptException e) { throw new RuntimeException("Prediction failed"); } return score; }   }
FraudScorerServlet extends HttpServlet { double score(double balance, double numTrans, double creditLine) { ScriptEngine engine = ENGINE.get(); if(engine == null) { engine = initEngine(); ENGINE.set(engine); } double score; Bindings bindings = engine.getBindings(ENGINE_SCOPE); bindings.put("balance", balance); bindings.put("numTrans", numTrans); bindings.put("creditLine", creditLine); try { engine.eval("score <- data.frame(balance=balance,numTrans=numTrans,creditLine=creditLine)"); engine.eval("x <- predict(fraudModel, score)"); DoubleVector x = (DoubleVector) bindings.get("x"); score = x.getElementAsDouble(0); } catch (ScriptException e) { throw new RuntimeException("Prediction failed"); } return score; }    }