• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java BinomialModelPrediction类的典型用法和代码示例

java 2次浏览

本文整理汇总了Java中hex.genmodel.easy.prediction.BinomialModelPrediction的典型用法代码示例。如果您正苦于以下问题:Java BinomialModelPrediction类的具体用法?Java BinomialModelPrediction怎么用?Java BinomialModelPrediction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

BinomialModelPrediction类属于hex.genmodel.easy.prediction包,在下文中一共展示了BinomialModelPrediction类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: doGet

点赞 3

import hex.genmodel.easy.prediction.BinomialModelPrediction; //导入依赖的package包/类
public void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  RowData row = new RowData();
  fillRowDataFromHttpRequest(request, row);

  try {
    BinomialModelPrediction p = predictBadLoan(row);
    RegressionModelPrediction p2 = predictInterestRate(row);
    String s = createJsonResponse(p, p2);

    // Emit the prediction to the servlet response.
    response.getWriter().write(s);
    response.setStatus(HttpServletResponse.SC_OK);

    if (VERBOSE) System.out.println("prediction(bad loan)     : " + p.classProbabilities[1]);
    if (VERBOSE) System.out.println("prediction(interest rate): " + p2.value);
  }
  catch (Exception e) {
    // Prediction failed.
    System.out.println(e.getMessage());
    response.sendError(HttpServletResponse.SC_NOT_ACCEPTABLE, e.getMessage());
  }
}
 

开发者ID:h2oai,
项目名称:qcon2015,
代码行数:23,
代码来源:PredictServlet.java

示例2: testPredictBinomialProstate

点赞 3

import hex.genmodel.easy.prediction.BinomialModelPrediction; //导入依赖的package包/类
@Test
public void testPredictBinomialProstate() throws Exception {
    URL mojoSource = StackedEnsembleRegressionMojoTest.class.getResource("binomial.zip");
    assertNotNull(mojoSource);
    System.out.println(mojoSource);
    MojoReaderBackend reader = MojoReaderBackendFactory.createReaderBackend(mojoSource, MojoReaderBackendFactory.CachingStrategy.DISK);
    MojoModel model = ModelMojoReader.readFrom(reader);
    EasyPredictModelWrapper modelWrapper = new EasyPredictModelWrapper(model);

    BinomialModelPrediction pred = (BinomialModelPrediction) modelWrapper.predict(new RowData() {{
        put("AGE", "65");
        put("RACE", "1");
        put("DPROS", "2");
        put("DCAPS", "1");
        put("PSA", "1.4");
        put("VOL", "0");
        put("GLEASON", "6");
    }});

    assertEquals(0, pred.labelIndex);
    assertEquals("0", pred.label);
    assertArrayEquals(new double[]{0.8222695, 0.1777305}, pred.classProbabilities, 1e-5);
}
 

开发者ID:h2oai,
项目名称:h2o-3,
代码行数:24,
代码来源:StackedEnsembleBinomialMojoTest.java

示例3: createJsonResponse

点赞 2

import hex.genmodel.easy.prediction.BinomialModelPrediction; //导入依赖的package包/类
private String createJsonResponse(BinomialModelPrediction p, RegressionModelPrediction p2) {
  StringBuilder sb = new StringBuilder();
  sb.append("{\n");
  sb.append("  \"labelIndex\" : ").append(p.labelIndex).append(",\n");
  sb.append("  \"label\" : \"").append(p.label).append("\",\n");
  sb.append("  \"classProbabilities\" : ").append("[\n");
  for (int i = 0; i < p.classProbabilities.length; i++) {
    double d = p.classProbabilities[i];
    if (Double.isNaN(d)) {
      throw new RuntimeException("Probability is NaN");
    }
    else if (Double.isInfinite(d)) {
      throw new RuntimeException("Probability is infinite");
    }

    sb.append("    ").append(d);
    if (i != (p.classProbabilities.length - 1)) {
      sb.append(",");
    }
    sb.append("\n");
  }
  sb.append("  ],\n");
  sb.append("\n");
  sb.append("  \"interestRate\" : ").append(p2.value).append("\n");
  sb.append("}\n");

  return sb.toString();
}
 

开发者ID:h2oai,
项目名称:qcon2015,
代码行数:29,
代码来源:PredictServlet.java

示例4: testPredict

点赞 2

import hex.genmodel.easy.prediction.BinomialModelPrediction; //导入依赖的package包/类
@Test
public void testPredict() throws Exception {

  GbmMojoModel mojo = (GbmMojoModel) ModelMojoReader.readFrom(new ClasspathReaderBackend());
  assertNotNull(mojo);

  EasyPredictModelWrapper wrapper = new EasyPredictModelWrapper(mojo);

  BinomialModelPrediction pred = (BinomialModelPrediction) wrapper.predict(new RowData() {{
    put("SegSumT", 18.7);
    put("SegTSeas", 1.51);
    put("SegLowFlow", 1.003);
    put("DSDist", 132.53);
    put("DSMaxSlope", 1.15);
    put("USAvgT", 0.2);
    put("USRainDays", 1.153);
    put("USSlope", 8.3);
    put("USNative", 0.34);
    put("DSDam", 0.0);
    put("Method", "electric");
  }});

  assertEquals(1, pred.labelIndex);
  assertEquals("1", pred.label);
  assertArrayEquals(new double[]{0.5416688, 0.4583312}, pred.classProbabilities, 1e-5);
  assertArrayEquals(new double[]{0.3920402, 0.6079598}, pred.calibratedClassProbabilities, 1e-5);
}
 

开发者ID:h2oai,
项目名称:h2o-3,
代码行数:28,
代码来源:GbmMojoModelTest.java

示例5: testPredict

点赞 2

import hex.genmodel.easy.prediction.BinomialModelPrediction; //导入依赖的package包/类
@Test
public void testPredict() throws Exception {
    EasyPredictModelWrapper wrapper = new EasyPredictModelWrapper(_mojo);
    for (int i = 0; i < _rows.length; i++) {
        // test easy-predict
        BinomialModelPrediction p = (BinomialModelPrediction) wrapper.predict(_rowData[i]);
        assertEquals((int)expectedPreds[i], p.labelIndex);
        // test score0
        double[] preds = new double[3];
        _mojo.score0(_rows[i], preds);
        assertEquals(expectedPreds[i], preds[0], 0.0);
    }
}
 

开发者ID:h2oai,
项目名称:h2o-3,
代码行数:14,
代码来源:SvmMojoModelTest.java

示例6: predictBadLoan

点赞 2

import hex.genmodel.easy.prediction.BinomialModelPrediction; //导入依赖的package包/类
private BinomialModelPrediction predictBadLoan (RowData row) throws Exception {
  return badLoanModel.predictBinomial(row);
}
 

开发者ID:h2oai,
项目名称:qcon2015,
代码行数:4,
代码来源:PredictServlet.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)