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

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

java 2次浏览

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

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

示例1: POJOPredictor

点赞 3

import hex.genmodel.easy.EasyPredictModelWrapper; //导入依赖的package包/类
public POJOPredictor(MLModel mlModel, String path) throws MLModelHandlerException {
    String dlModelName = extractModelName(path);
    dlModelName = dlModelName.replace('.', '_').replace('-', '_');
    String carbonHome = CarbonUtils.getCarbonHome();
    File f = new File(carbonHome + MLConstants.H2O_POJO_Path);

    try {
        URL[] cp = { f.toURI().toURL(),
                new File(carbonHome + MLConstants.H2O_POJO_Path + "h2o-genmodel.jar").toURI().toURL() };
        URLClassLoader urlcl = new URLClassLoader(cp, this.getClass().getClassLoader());

        rawModel = (hex.genmodel.GenModel) urlcl.loadClass(dlModelName).newInstance();
        model = new EasyPredictModelWrapper(rawModel);

        numberOfFeatures = mlModel.getFeatures().size();
        featureList = mlModel.getFeatures();
        this.mlModel = mlModel;

    } catch (MalformedURLException | ClassNotFoundException | IllegalAccessException | InstantiationException e) {
        throw new MLModelHandlerException("Error occurred while initializing POHOPredictor.", e);
    }
}
 

开发者ID:wso2-attic,
项目名称:carbon-ml,
代码行数:23,
代码来源:POJOPredictor.java

示例2: testPredictMultinomialProstate

点赞 3

import hex.genmodel.easy.EasyPredictModelWrapper; //导入依赖的package包/类
@Test
public void testPredictMultinomialProstate() throws Exception {
    URL mojoSource = StackedEnsembleRegressionMojoTest.class.getResource("multinomial.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);

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

    assertEquals(1, pred.labelIndex);
    assertEquals("1", pred.label);
    assertArrayEquals(new double[]{0.006592327, 0.901237, 0.09217069}, pred.classProbabilities, 1e-5);
}
 

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

示例3: testPredictBinomialProstate

点赞 3

import hex.genmodel.easy.EasyPredictModelWrapper; //导入依赖的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

示例4: testPredictRegressionProstate

点赞 3

import hex.genmodel.easy.EasyPredictModelWrapper; //导入依赖的package包/类
@Test
public void testPredictRegressionProstate() throws Exception {
    URL mojoSource = StackedEnsembleRegressionMojoTest.class.getResource("regression.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);

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

    assertEquals(66.29695, pred.value, 1e-5);
}
 

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

示例5: testPredictExtended

点赞 3

import hex.genmodel.easy.EasyPredictModelWrapper; //导入依赖的package包/类
@Test
public void testPredictExtended() throws Exception {
  EasyPredictModelWrapper.Config config = new EasyPredictModelWrapper.Config()
          .setModel(_mojo)
          .setUseExtendedOutput(true);
  EasyPredictModelWrapper wrapper = new EasyPredictModelWrapper(config);
  for (int i = 0; i < 3; i++) {
    // test easy-predict
    ClusteringModelPrediction p = (ClusteringModelPrediction) wrapper.predict(_rowData[i]);
    assertEquals(i, p.cluster);
    // test score0
    double[] preds = new double[1];
    double[] row = _rows[i].clone();
    _mojo.score0(row, preds); // this also normalizes the row object!
    assertEquals(i, preds[0], 0.0);
    // test distances
    double[] expDists = new double[3];
    GenModel.KMeans_distances(((KMeansMojoModel) _mojo)._centers, row, ((KMeansMojoModel) _mojo)._domains, expDists);
    double[] dists = new double[3];
    ((IClusteringModel) _mojo).distances(_rows[i].clone(), dists);
    assertArrayEquals(expDists, dists, 1e-10);
    assertArrayEquals(expDists, p.distances, 1e-10);
  }
}
 

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

示例6: testPOJOWithDistances

点赞 2

import hex.genmodel.easy.EasyPredictModelWrapper; //导入依赖的package包/类
@Test public void testPOJOWithDistances() {
  // Ignore test if the compiler failed to load
  Assume.assumeTrue(water.util.JCodeGen.canCompile());

  KMeansModel kmm = null;
  Frame fr = null, fr2= null;
  try {
    fr = parse_test_file("smalldata/iris/iris_wheader.csv");
    KMeansModel.KMeansParameters parms = new KMeansModel.KMeansParameters();
    parms._train = fr._key;
    parms._k = 3;
    parms._standardize = true;
    parms._max_iterations = 10;
    parms._init = KMeans.Initialization.Random;
    kmm = doSeed(parms,0);

    // Done building model; produce a score column with cluster choices
    fr2 = kmm.score(fr);
    EasyPredictModelWrapper.Config config = new EasyPredictModelWrapper.Config().setUseExtendedOutput(true);
    Assert.assertTrue(kmm.testJavaScoring(fr, fr2, config,1e-15, 1e-15, 0.1));

  } finally {
    if( fr  != null ) fr.delete();
    if( fr2 != null ) fr2.delete();
    if( kmm != null ) kmm.delete();
  }
}
 

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

示例7: testPredict

点赞 2

import hex.genmodel.easy.EasyPredictModelWrapper; //导入依赖的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

示例8: testPredict

点赞 2

import hex.genmodel.easy.EasyPredictModelWrapper; //导入依赖的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

示例9: testPredict

点赞 2

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

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

示例10: testMojoE2E

点赞 2

import hex.genmodel.easy.EasyPredictModelWrapper; //导入依赖的package包/类
private void testMojoE2E(CachingStrategy cachingStrategy) throws Exception {
  URL mojoSource = MojoReaderBackendFactoryTest.class.getResource("mojo.zip");
  assertNotNull(mojoSource);
  MojoReaderBackend reader = MojoReaderBackendFactory.createReaderBackend(mojoSource, cachingStrategy);
  MojoModel model = ModelMojoReader.readFrom(reader);
  EasyPredictModelWrapper modelWrapper = new EasyPredictModelWrapper(model);
  RowData testRow = makeTestRow();
  RegressionModelPrediction prediction = (RegressionModelPrediction) modelWrapper.predict(testRow);
  assertEquals(71.085d, prediction.value, 0.001d);
}
 

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

示例11: loadPojo

点赞 2

import hex.genmodel.easy.EasyPredictModelWrapper; //导入依赖的package包/类
private void loadPojo(String jarFileName, String modelName)
    throws Exception {
  GenModel rawModel = loadClassFromJar(jarFileName, modelName);
  model = new EasyPredictModelWrapper(rawModel);
}
 

开发者ID:h2oai,
项目名称:steam,
代码行数:6,
代码来源:H2OPredictor.java

示例12: loadMojo

点赞 2

import hex.genmodel.easy.EasyPredictModelWrapper; //导入依赖的package包/类
private void loadMojo(String zipFileName)
    throws Exception {
  GenModel rawModel = MojoModel.load(zipFileName);
  model = new EasyPredictModelWrapper(rawModel);
}
 

开发者ID:h2oai,
项目名称:steam,
代码行数:6,
代码来源:H2OPredictor.java

示例13: testJavaScoring

点赞 2

import hex.genmodel.easy.EasyPredictModelWrapper; //导入依赖的package包/类
public boolean testJavaScoring(Frame data, Frame model_predictions, double rel_epsilon, double abs_epsilon, double fraction) {
  return testJavaScoring(data, model_predictions, new EasyPredictModelWrapper.Config(), rel_epsilon, abs_epsilon, fraction);
}
 

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

示例14: loadPojo

点赞 2

import hex.genmodel.easy.EasyPredictModelWrapper; //导入依赖的package包/类
private void loadPojo(String className) throws Exception {
  GenModel genModel = (GenModel) Class.forName(className).newInstance();
  model = new EasyPredictModelWrapper(new EasyPredictModelWrapper.Config().setModel(genModel).setConvertUnknownCategoricalLevelsToNa(true).setConvertInvalidNumbersToNa(setInvNumNA));
}
 

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

示例15: loadMojo

点赞 2

import hex.genmodel.easy.EasyPredictModelWrapper; //导入依赖的package包/类
private void loadMojo(String modelName) throws IOException {
  GenModel genModel = MojoModel.load(modelName);
  model = new EasyPredictModelWrapper(new EasyPredictModelWrapper.Config().setModel(genModel).setConvertUnknownCategoricalLevelsToNa(true).setConvertInvalidNumbersToNa(setInvNumNA));
}
 

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


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