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

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

java 2次浏览

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

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

示例1: defaultSearchGLM

点赞 3

import hex.deeplearning.DeepLearningModel; //导入依赖的package包/类
public Job<Grid> defaultSearchGLM() {
  ///////////////////////////////////////////////////////////
  // do a random hyperparameter search with GLM
  ///////////////////////////////////////////////////////////
  // TODO: convert to using the REST API
  Key<Grid> gridKey = Key.make("GLM_grid_default_" + this._key.toString());

  HyperSpaceSearchCriteria.RandomDiscreteValueSearchCriteria searchCriteria = buildSpec.build_control.stopping_criteria;

  // TODO: put this into a Provider, which can return multiple searches
  GLMModel.GLMParameters glmParameters = new GLMModel.GLMParameters();
      setCommonModelBuilderParams(glmParameters);

  glmParameters._lambda_search = true;
  glmParameters._family = getResponseColumn().isBinary() && !(getResponseColumn().isNumeric()) ? GLMModel.GLMParameters.Family.binomial :
          getResponseColumn().isCategorical() ? GLMModel.GLMParameters.Family.multinomial :
                  GLMModel.GLMParameters.Family.gaussian;  // TODO: other continuous distributions!

  Map<String, Object[]> searchParams = new HashMap<>();
  glmParameters._alpha = new double[] {0.0, 0.2, 0.4, 0.6, 0.8, 1.0};  // Note: standard GLM parameter is an array; don't use searchParams!
  // NOTE: removed MissingValuesHandling.Skip for now because it's crashing.  See https://0xdata.atlassian.net/browse/PUBDEV-4974
  searchParams.put("_missing_values_handling", new DeepLearningModel.DeepLearningParameters.MissingValuesHandling[] {DeepLearningModel.DeepLearningParameters.MissingValuesHandling.MeanImputation /* , DeepLearningModel.DeepLearningParameters.MissingValuesHandling.Skip */});

  Job<Grid>glmJob = hyperparameterSearch("GLM", glmParameters, searchParams);
  return glmJob;
}
 

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

示例2: execImpl

点赞 3

import hex.deeplearning.DeepLearningModel; //导入依赖的package包/类
@Override
protected final void execImpl() {
  if (dl_model == null) throw new IllegalArgumentException("Deep Learning Model must be specified.");
  DeepLearningModel dlm = UKV.get(dl_model);
  if (dlm == null) throw new IllegalArgumentException("Deep Learning Model not found.");

  StringBuilder sb = new StringBuilder();
  if (layer < -1 || layer > dlm.get_params().hidden.length-1) throw new IllegalArgumentException("Layer must be either -1 or between 0 and " + (dlm.get_params().hidden.length-1));
  if (layer == -1) layer = dlm.get_params().hidden.length-1;
  int features = dlm.get_params().hidden[layer];
  sb.append("\nTransforming frame '" + source._key.toString() + "' with " + source.numCols() + " into " + features + " features with model '" + dl_model + "'\n");

  Frame df = dlm.scoreDeepFeatures(source, layer);
  sb.append("Storing the new features under: " + dest() + ".\n");
  Frame output = new Frame(dest(), df.names(), df.vecs());
  output.delete_and_lock(null);
  output.unlock(null);
}
 

开发者ID:h2oai,
项目名称:h2o-2,
代码行数:19,
代码来源:DeepFeatures.java

示例3: readExternal

点赞 2

import hex.deeplearning.DeepLearningModel; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    storageLocation = (String) in.readObject();
    labelToH2OEnumMap = (HashMap<Double, Double>) in.readObject();
    @SuppressWarnings("rawtypes")
    List<Key> keys = new ObjectTreeBinarySerializer().load(FileUtils.getURI(storageLocation));
    this.dlModel = (DeepLearningModel) keys.get(0).get();
}
 

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

示例4: testSparse

点赞 2

import hex.deeplearning.DeepLearningModel; //导入依赖的package包/类
@Test
  public void testSparse() {
    double [] exp_coefs = new double [] {0.0233151691783671,-0.00543776852277619,-0.0137359312181047,0.00770037200907652,0.0328856331139761,-0.0242845468071283,-0.0101698117745265,0.00868844870137727,0.000349121513384513,-0.0106962199761512,-0.00705001448025939,0.00821574637914086,0.00601015905212279,0.0021278467162546,-0.0233079168835112,0.00535473896013676,-0.00897667301004576,0.00788272228017582,0.00237442711371947,-0.013136425134371,0.00134003869245749,0.0240118046676911,0.000607214787933269,-0.0112908513868027,0.000443119443631777,0.00749330452744921,-0.00558704122833295,0.000533036850835694,0.0130008059852934,-4.40634889376063e-05,-0.00580285872202347,0.0117029111583238,-0.00685480666428133,0.00809526311326634,-0.0088567165389072,-0.0363126456378731,-0.00267237519808936,-0.01669554043682,0.00556943053195684,0.0178196407614288,-0.000903204442155076,-0.0085363297586185,-0.00421147221966977,-0.00828702756129772,0.017027928644479,0.00710126315700672,0.019819043342772,-0.0165232485929677,0.00439570108491533,0.0188325734374437,0.00799712968759025,-0.0100388875424171,-0.0062415137856855,-0.00258013659839137,-6.58516379178382e-05,0.0135032332096949,-0.00776869619293087,-0.00544035128543343,-0.0110626226606883,-0.00768490011210769,-0.00684181016695251,-0.0144627862333649,-0.0262830557415184,-0.0102290180164706,0.00368252955770187,0.015824495748353,0.00383484095683782,0.0151193905626625,-0.00615077094420626,0.0142842231522414,0.00150448184871646,0.0521491615912011,0.0128661232226479,0.00225580439739044,-0.0117476427864401,-0.0059792656068627,0.000787012740598272,0.00255419488737936,0.00406033118385186,0.0102551045653601,0.00423949002681056,-0.0116986428989079,0.00232448128787425,-0.00296198808290357,-0.00793738689381332,-0.000771158906679964,0.00435708760153937,-0.0138922325725763,0.00264561130131037,-0.0156128295187466,-0.0102023187068811,0.0074744189329328,0.0102377749189598,-0.0304739969497646,0.00692556661464647,0.00151065993974025,0.0133704258946895,-0.0167391228441308,0.0111804482435337,-0.0062469732087272,-0.00930165243463748,-0.00418698783410104,0.00190918091726462,0.00632982717347925,-0.00277608255480933,-0.00175463261672652,-0.00267223587651978,-0.00329264073314718,0.000960091877616874,-0.00946014799557438,-0.0112302467393988,-0.00870512647578646,-0.00238582834931644,-0.0100845163232815,-0.00675861103174491,-0.000689229731411459,0.0127651588318169,-0.0062753105816655,-0.00240575758827749,0.00439570108491531,0.00934971690544427,-0.0184380964678117,-0.00474253892124699,0.00522916014066936,-0.0105148336464531,0.0088372219244051,0.0100429095740915,-0.0107657032259033,-0.00512476269437683,-0.00558487620671732,-0.000637298812579742,-0.00118460090105795,-0.00369801350318738,-0.00556276860695209,0.00789011470305446,-0.00248367841256358,0.00677762904717052,-0.00640135771848287,0.00797532960057465,-0.00117508910987595,0.000986931150778778,-0.0148237721063735,0.0053001635341953,-0.0139698571439444,-0.0172255105183439,-0.0177416268392445,-0.0107062660197562,-0.00735448768491512,-0.00418482390542493,0.00933957546887131,-0.00761657876743367,0.0107862806984669,6.99667442150322e-05,-0.00151054027221715,0.00941377216029456,0.0112882845381545,0.0014423575345095,0.00845773223444363,-0.00675939077916714,-0.00329806028742896,0.000276998824889068,0.00206337643122044,-0.00173085772672239,0.00169616445468346,0.00281297187309321,-0.0152343998246272,0.0126261762792184,-0.000224959505615703,-0.00476466349783071,-0.0102541605421868,-0.000561674281900828,0.00367777757696579,-0.000960272764476094,0.00255704179717728,-0.000696266184051808,0.0470920125432207,0.0115016691642458,-0.00287666464467251,-0.00132912286075637,0.00201932482935891,0.00119899092739739,0.00380417340899902,-0.00394363983208331,-0.00294543812868618,-1.77894150438862e-05,-0.00455002740798846,0.000613307426862812,0.00348274063618593,0.00161877234851832,0.0231608701706833,-0.00390062462708628,0.00244047437999614,-0.00143984617445982,-0.00221831741496412,-0.00744853810342609,-0.00575689075773469,-0.00567890661011033,0.00384589889309526,-0.00173241442296732,-0.00526995531653655,-0.00310819786514896,0.00740596461822877,-0.0790037392468225,0.0239744234187787,0.0514310481067108,0.034335426530007,0.0254604884688754,0.0531375235023675,-0.0228335779154641,0.546865402727144};
    GLMModel model1 = null;
    GLMParameters parms = new GLMParameters(Family.gaussian);
    _airlinesMM.add("weights",_airlinesMM.anyVec().makeCon(1.0));
    DKV.put(_airlinesMM._key,_airlinesMM);
    parms._weights_column = "weights";
    parms._train = _airlinesMM._key;
    parms._lambda = new double[]{1e-2};
    parms._alpha = new double[]{0};
    parms._solver = Solver.IRLSM;
    parms._ignored_columns = new String[]{"C1"};
//    parms._remove_collinear_columns = true;
    parms._response_column = "IsDepDelayed";
    parms._standardize = true;
    parms._objective_epsilon = 0;
    parms._gradient_epsilon = 1e-10;
    parms._max_iterations = 1000;
    parms._missing_values_handling = DeepLearningModel.DeepLearningParameters.MissingValuesHandling.Skip;
    try {
      model1 = new GLM(parms).trainModel().get();
      for(int i = 0; i < model1._output._coefficient_names.length; ++i)
        assertEquals(exp_coefs[i],model1._output.getNormBeta()[i],Math.abs(exp_coefs[i])*1e-8);
    } finally {
      if (model1 != null) model1.delete();
    }
  }
 

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

示例5: if

点赞 2

import hex.deeplearning.DeepLearningModel; //导入依赖的package包/类
Job<DeepLearningModel>defaultDeepLearning() {
  if (exceededSearchLimits("DeepLearning")) return null;

  DeepLearningModel.DeepLearningParameters deepLearningParameters = new DeepLearningModel.DeepLearningParameters();
  setCommonModelBuilderParams(deepLearningParameters);

  deepLearningParameters._stopping_tolerance = this.buildSpec.build_control.stopping_criteria.stopping_tolerance();
  deepLearningParameters._hidden = new int[]{ 10, 10, 10 };

  Job deepLearningJob = trainModel(null, "deeplearning", deepLearningParameters);
  return deepLearningJob;
}
 

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

示例6: defaultSearchDL1

点赞 2

import hex.deeplearning.DeepLearningModel; //导入依赖的package包/类
public Job<Grid> defaultSearchDL1(Key<Grid> gridKey) {
  ///////////////////////////////////////////////////////////
  // do a random hyperparameter search with DL
  ///////////////////////////////////////////////////////////

  HyperSpaceSearchCriteria.RandomDiscreteValueSearchCriteria searchCriteria = buildSpec.build_control.stopping_criteria;

  // TODO: put this into a Provider, which can return multiple searches
  DeepLearningModel.DeepLearningParameters dlParameters = new DeepLearningModel.DeepLearningParameters();
  setCommonModelBuilderParams(dlParameters);

  dlParameters._epochs = 10000; // early stopping takes care of epochs - no need to tune!
  dlParameters._adaptive_rate = true;
  dlParameters._activation = RectifierWithDropout;

  Map<String, Object[]> searchParams = new HashMap<>();
  // common:
  searchParams.put("_rho", new Double[] { 0.9, 0.95, 0.99 });
  searchParams.put("_epsilon", new Double[] { 1e-6, 1e-7, 1e-8, 1e-9 });
  searchParams.put("_input_dropout_ratio", new Double[] { 0.0, 0.05, 0.1, 0.15, 0.2 });

  // unique:
  searchParams.put("_hidden", new Integer[][] { {50}, {200}, {500} });
  searchParams.put("_hidden_dropout_ratios", new Double[][] { { 0.0 }, { 0.1 }, { 0.2 }, { 0.3 }, { 0.4 }, { 0.5 } });

  Job<Grid>dlJob = hyperparameterSearch(gridKey, "DL", dlParameters, searchParams);
  return dlJob;
}
 

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

示例7: defaultSearchDL2

点赞 2

import hex.deeplearning.DeepLearningModel; //导入依赖的package包/类
public Job<Grid> defaultSearchDL2(Key<Grid> gridKey) {
  ///////////////////////////////////////////////////////////
  // do a random hyperparameter search with DL
  ///////////////////////////////////////////////////////////

  HyperSpaceSearchCriteria.RandomDiscreteValueSearchCriteria searchCriteria = buildSpec.build_control.stopping_criteria;

  // TODO: put this into a Provider, which can return multiple searches
  DeepLearningModel.DeepLearningParameters dlParameters = new DeepLearningModel.DeepLearningParameters();
  setCommonModelBuilderParams(dlParameters);

  dlParameters._epochs = 10000; // early stopping takes care of epochs - no need to tune!
  dlParameters._adaptive_rate = true;
  dlParameters._activation = RectifierWithDropout;

  Map<String, Object[]> searchParams = new HashMap<>();
  // common:
  searchParams.put("_rho", new Double[] { 0.9, 0.95, 0.99 });
  searchParams.put("_epsilon", new Double[] { 1e-6, 1e-7, 1e-8, 1e-9 });
  searchParams.put("_input_dropout_ratio", new Double[] { 0.0, 0.05, 0.1, 0.15, 0.2 });

  // unique:
  searchParams.put("_hidden", new Integer[][] { {50, 50}, {200, 200}, {500, 500} });
  searchParams.put("_hidden_dropout_ratios", new Double[][] { { 0.0, 0.0 }, { 0.1, 0.1 }, { 0.2, 0.2 }, { 0.3, 0.3 }, { 0.4, 0.4 }, { 0.5, 0.5 } });

  Job<Grid>dlJob = hyperparameterSearch(gridKey, "DL", dlParameters, searchParams);
  return dlJob;
}
 

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

示例8: defaultSearchDL3

点赞 2

import hex.deeplearning.DeepLearningModel; //导入依赖的package包/类
public Job<Grid> defaultSearchDL3(Key<Grid> gridKey) {
  ///////////////////////////////////////////////////////////
  // do a random hyperparameter search with DL
  ///////////////////////////////////////////////////////////

  HyperSpaceSearchCriteria.RandomDiscreteValueSearchCriteria searchCriteria = buildSpec.build_control.stopping_criteria;

  // TODO: put this into a Provider, which can return multiple searches
  DeepLearningModel.DeepLearningParameters dlParameters = new DeepLearningModel.DeepLearningParameters();
  setCommonModelBuilderParams(dlParameters);

  dlParameters._epochs = 10000; // early stopping takes care of epochs - no need to tune!
  dlParameters._adaptive_rate = true;
  dlParameters._activation = RectifierWithDropout;

  Map<String, Object[]> searchParams = new HashMap<>();
  // common:
  searchParams.put("_rho", new Double[] { 0.9, 0.95, 0.99 });
  searchParams.put("_epsilon", new Double[] { 1e-6, 1e-7, 1e-8, 1e-9 });
  searchParams.put("_input_dropout_ratio", new Double[] { 0.0, 0.05, 0.1, 0.15, 0.2 });

  // unique:
  searchParams.put("_hidden", new Integer[][] { {50, 50, 50}, {200, 200, 200}, {500, 500, 500} });
  searchParams.put("_hidden_dropout_ratios", new Double[][] { { 0.0, 0.0, 0.0 }, { 0.1, 0.1, 0.1 }, { 0.2, 0.2, 0.2 }, { 0.3, 0.3, 0.3 }, { 0.4, 0.4, 0.4 }, { 0.5, 0.5, 0.5 } });

  Job<Grid>dlJob = hyperparameterSearch(gridKey, "DL", dlParameters, searchParams);
  return dlJob;
}
 

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

示例9: toHTML

点赞 2

import hex.deeplearning.DeepLearningModel; //导入依赖的package包/类
@Override public boolean toHTML( StringBuilder sb ) {
  Job jjob = Job.findJob(job_key);
  if (jjob ==null) return true;
  DeepLearningModel m = UKV.get(jjob.dest());
  if (m!=null) m.generateHTML("Deep Learning Model", sb);
  else DocGen.HTML.paragraph(sb, "Pending...");
  return true;
}
 

开发者ID:h2oai,
项目名称:h2o-2,
代码行数:9,
代码来源:DeepLearningProgressPage.java

示例10: visualize

点赞 2

import hex.deeplearning.DeepLearningModel; //导入依赖的package包/类
static public void visualize(final DeepLearningModel dlm) {
  Neurons[] neurons = DeepLearningTask.makeNeuronsForTesting(dlm.model_info());
  frame.dispose();
  frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
  DeepLearningVisualization canvas = new DeepLearningVisualization(neurons);
  frame.setContentPane(canvas.init());
  frame.pack();
  frame.setLocationRelativeTo(null);
  frame.setVisible(true);
}
 

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

示例11: MLDeeplearningModel

点赞 2

import hex.deeplearning.DeepLearningModel; //导入依赖的package包/类
public MLDeeplearningModel(DeepLearningModel dlModel) {
    this.dlModel = dlModel;
}
 

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

示例12: getDlModel

点赞 2

import hex.deeplearning.DeepLearningModel; //导入依赖的package包/类
public DeepLearningModel getDlModel() {
    return dlModel;
}
 

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

示例13: buildStackedAutoencodersModel

点赞 2

import hex.deeplearning.DeepLearningModel; //导入依赖的package包/类
/**
 * Build the stacked autoencoder model
 * 
 * @param sparkContext
 * @param modelID model ID
 * @param trainingData training data to train the classifier
 * @param testingData testing data to test the classifier and get metrics
 * @param workflow workflow
 * @param mlModel MLModel to be updated with calcualted values
 * @param includedFeatures Included features
 * @return
 * @throws MLModelBuilderException
 */
private ModelSummary buildStackedAutoencodersModel(JavaSparkContext sparkContext, long modelID,
        JavaRDD<LabeledPoint> trainingData, JavaRDD<LabeledPoint> testingData, Workflow workflow, MLModel mlModel,
        SortedMap<Integer, String> includedFeatures) throws MLModelBuilderException {
    try {
        StackedAutoencodersClassifier saeClassifier = new StackedAutoencodersClassifier();
        Map<String, String> hyperParameters = workflow.getHyperParameters();

        // train the stacked autoencoder
        DeepLearningModel deeplearningModel = saeClassifier.train(trainingData,
                Integer.parseInt(hyperParameters.get(MLConstants.BATCH_SIZE)),
                stringArrToIntArr(hyperParameters.get(MLConstants.LAYER_SIZES)),
                hyperParameters.get(MLConstants.ACTIVATION_TYPE),
                Integer.parseInt(hyperParameters.get(MLConstants.EPOCHS)),
                Integer.parseInt(hyperParameters.get(MLConstants.SEED)),
                workflow.getResponseVariable(),
                getContext().getModel().getName(), mlModel, modelID);

        if (deeplearningModel == null) {
            throw new MLModelBuilderException("DeeplearningModel is Null.");
        }

        // remove from cache
        trainingData.unpersist();
        // add to cache
        testingData.cache();

        // make predictions with the trained model
        JavaPairRDD<Double, Double> predictionsAndLabels = saeClassifier
                .test(sparkContext, deeplearningModel, testingData, mlModel).cache();

        // get model summary
        DeeplearningModelSummary deeplearningModelSummary = DeeplearningModelUtils
                .getDeeplearningModelSummary(sparkContext, testingData, predictionsAndLabels);

        // remove from cache
        testingData.unpersist();

        mlModel.setModel(new MLDeeplearningModel(deeplearningModel));

        deeplearningModelSummary.setFeatures(includedFeatures.values().toArray(new String[0]));
        deeplearningModelSummary.setAlgorithm(MLConstants.DEEPLEARNING_ALGORITHM.STACKED_AUTOENCODERS.toString());

        // set accuracy values
        MulticlassMetrics multiclassMetrics = getMulticlassMetrics(sparkContext, predictionsAndLabels);

        // remove from cache
        predictionsAndLabels.unpersist();

        deeplearningModelSummary
                .setMulticlassConfusionMatrix(getMulticlassConfusionMatrix(multiclassMetrics, mlModel));
        Double modelAccuracy = getModelAccuracy(multiclassMetrics);
        deeplearningModelSummary.setModelAccuracy(modelAccuracy);
        deeplearningModelSummary.setDatasetVersion(workflow.getDatasetVersion());

        return deeplearningModelSummary;

    } catch (Exception e) {
        throw new MLModelBuilderException(
                "An error occurred while building stacked autoencoders model: " + e.getMessage(), e);
    }

}
 

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

示例14: persistModel

点赞 2

import hex.deeplearning.DeepLearningModel; //导入依赖的package包/类
private void persistModel(long modelId, String modelName, MLModel model) throws MLModelBuilderException {
    try {
        MLStorage storage = valueHolder.getDatabaseService().getModelStorage(modelId);
        if (storage == null) {
            throw new MLModelBuilderException("Invalid model ID: " + modelId);
        }
        if (!MLUtils.isValidName(modelName)) {
            throw new MLModelBuilderException("Model name: " + modelName + " contains restricted path elements.");
        }
        String storageType = storage.getType();
        String storageLocation = storage.getLocation();
        String outPath = storageLocation + File.separator + modelName;

        // if this is a deeplearning model, need to set the storage location for writing
        // then the sparkdeeplearning model will use ObjectTreeBinarySerializer to write it to the given directory
        // the DeeplearningModel will be saved as a .bin file
        if (MLConstants.DEEPLEARNING.equalsIgnoreCase(model.getAlgorithmClass())) {
            MLDeeplearningModel mlDeeplearningModel = (MLDeeplearningModel) model.getModel();
            mlDeeplearningModel.setStorageLocation(storageLocation);
            model.setModel(mlDeeplearningModel);

            // Write POJO if it is a Deep Learning model
            // convert model name
            String dlModelName = modelName.replace('.', '_').replace('-', '_');
            File file = new File(storageLocation + "/" + dlModelName + "_dl" + ".java");
            FileOutputStream fileOutputStream = new FileOutputStream(file);
            DeepLearningModel deepLearningModel = mlDeeplearningModel.getDlModel();
            deepLearningModel.toJava(fileOutputStream, false, false);
            fileOutputStream.close();

            MLModel dlModel = new MLModel();
            dlModel.setAlgorithmClass(model.getAlgorithmClass());
            dlModel.setAlgorithmName(model.getAlgorithmName());
            dlModel.setEncodings(model.getEncodings());
            dlModel.setFeatures(model.getFeatures());
            dlModel.setResponseIndex(model.getResponseIndex());
            dlModel.setResponseVariable(model.getResponseVariable());
            dlModel.setNewToOldIndicesList(model.getNewToOldIndicesList());

            // Writing the DL model without Deep Learning logic
            // For prediction with POJO
            MLIOFactory ioFactoryDl = new MLIOFactory(valueHolder.getMlProperties());
            MLOutputAdapter outputAdapterDl = ioFactoryDl.getOutputAdapter(storageType + MLConstants.OUT_SUFFIX);
            ByteArrayOutputStream baosDl = new ByteArrayOutputStream();
            ObjectOutputStream oosDl = new ObjectOutputStream(baosDl);
            oosDl.writeObject(dlModel);
            oosDl.flush();
            oosDl.close();
            InputStream isDl = new ByteArrayInputStream(baosDl.toByteArray());
            // adapter will write the model and close the stream.
            outputAdapterDl.write(outPath + "_dl", isDl);
        }

        MLIOFactory ioFactory = new MLIOFactory(valueHolder.getMlProperties());
        MLOutputAdapter outputAdapter = ioFactory.getOutputAdapter(storageType + MLConstants.OUT_SUFFIX);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(baos);
        oos.writeObject(model);
        oos.flush();
        oos.close();
        InputStream is = new ByteArrayInputStream(baos.toByteArray());
        // adapter will write the model and close the stream.
        outputAdapter.write(outPath, is);
        valueHolder.getDatabaseService().updateModelStorage(modelId, storageType, outPath);
        log.info(String.format("Successfully persisted the model [id] %s", modelId));
    } catch (Exception e) {
        throw new MLModelBuilderException("Failed to persist the model [id] " + modelId + ". " + e.getMessage(), e);
    }
}
 

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

示例15: createImpl

点赞 2

import hex.deeplearning.DeepLearningModel; //导入依赖的package包/类
@Override public DeepLearningModel createImpl() {
  DeepLearningParameters parms = parameters.createImpl();
  return new DeepLearningModel(Key.make() /*dest*/, parms, new DeepLearningModel.DeepLearningModelOutput(null), null, null, 0);
}
 

开发者ID:kyoren,
项目名称:https-github.com-h2oai-h2o-3,
代码行数:5,
代码来源:DeepLearningModelV3.java

示例16: computeDeepLearningMetalearner

点赞 2

import hex.deeplearning.DeepLearningModel; //导入依赖的package包/类
void computeDeepLearningMetalearner(){
    //DeepLearning Metalearner
    DeepLearning metaDeepLearningBuilder;
    metaDeepLearningBuilder = ModelBuilder.make("DeepLearning", _metalearnerJob, _metalearnerKey);
    DeepLearningV3.DeepLearningParametersV3 params = new DeepLearningV3.DeepLearningParametersV3();
    params.init_meta();
    params.fillFromImpl(metaDeepLearningBuilder._parms); // Defaults for this builder into schema

    //Metalearner parameters
    if (_hasMetalearnerParams) {
        Properties p = new Properties();
        HashMap<String, String[]> map = new Gson().fromJson(_metalearner_params, new TypeToken<HashMap<String, String[]>>() {
        }.getType());
        for (Map.Entry<String, String[]> param : map.entrySet()) {
            String[] paramVal = param.getValue();
            if (paramVal.length == 1) {
                p.setProperty(param.getKey(), paramVal[0]);
            } else {
                p.setProperty(param.getKey(), Arrays.toString(paramVal));
            }
            params.fillFromParms(p, true);
        }
        DeepLearningModel.DeepLearningParameters dlParams = params.createAndFillImpl();
        metaDeepLearningBuilder._parms = dlParams;
    }
    metaDeepLearningBuilder._parms._train = _levelOneTrainingFrame._key;
    metaDeepLearningBuilder._parms._valid = (_levelOneValidationFrame == null ? null : _levelOneValidationFrame._key);
    metaDeepLearningBuilder._parms._response_column = _model.responseColumn;
    metaDeepLearningBuilder._parms._nfolds = _model._parms._metalearner_nfolds;  //cross-validation of the metalearner
    if (_model._parms._metalearner_fold_column == null) {
        metaDeepLearningBuilder._parms._nfolds = _model._parms._metalearner_nfolds;  //cross-validation of the metalearner
        if (_model._parms._metalearner_nfolds > 1) {
            if (_model._parms._metalearner_fold_assignment == null) {
                metaDeepLearningBuilder._parms._fold_assignment = Model.Parameters.FoldAssignmentScheme.AUTO;
            } else {
                metaDeepLearningBuilder._parms._fold_assignment = _model._parms._metalearner_fold_assignment;  //cross-validation of the metalearner
            }
        }
    } else {
        metaDeepLearningBuilder._parms._fold_column = _model._parms._metalearner_fold_column;  //cross-validation of the metalearner
    }

    metaDeepLearningBuilder.init(false);

    Job<DeepLearningModel> j = metaDeepLearningBuilder.trainModel();

    while (j.isRunning()) {
        try {
            _job.update(j._work, "training metalearner(" + _model._parms._metalearner_algorithm + ")");
            Thread.sleep(100);
        } catch (InterruptedException e) {
        }
    }

    Log.info("Finished training metalearner model(" + _model._parms._metalearner_algorithm + ").");

    _model._output._metalearner = metaDeepLearningBuilder.get();
    _model.doScoreOrCopyMetrics(_job);
    if (_parms._keep_levelone_frame) {
        _model._output._levelone_frame_id = _levelOneTrainingFrame; //Keep Level One Training Frame in Stacked Ensemble model object
    } else {
        DKV.remove(_levelOneTrainingFrame._key); //Remove Level One Training Frame from DKV
    }
    if (null != _levelOneValidationFrame) {
        DKV.remove(_levelOneValidationFrame._key); //Remove Level One Validation Frame from DKV
    }
    _model.update(_job);
    _model.unlock(_job);
}
 

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

示例17: createImpl

点赞 2

import hex.deeplearning.DeepLearningModel; //导入依赖的package包/类
@Override public DeepLearningModel createImpl() {
  DeepLearningModel.DeepLearningParameters parms = parameters.createImpl();
  return new DeepLearningModel(Key.make() /*dest*/, parms, new DeepLearningModel.DeepLearningModelOutput(null), null, null, 0);
}
 

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

示例18: testPValuesTweedie

点赞 2

import hex.deeplearning.DeepLearningModel; //导入依赖的package包/类
@Test
  public void testPValuesTweedie() {
//    Call:
//    glm(formula = Infections ~ ., family = tweedie(var.power = 1.5),
//      data = D)
//
//    Deviance Residuals:
//    Min       1Q   Median       3Q      Max
//    -2.6355  -2.0931  -1.8183   0.5046   4.9458
//
//    Coefficients:
//    Estimate Std. Error t value Pr(>|t|)
//    (Intercept)       1.05665    0.11120   9.502  < 2e-16 ***
//    SwimmerOccas     -0.25891    0.08455  -3.062  0.00241 **
//    LocationNonBeach -0.22185    0.08393  -2.643  0.00867 **
//    Age20-24          0.15325    0.10041   1.526  0.12808
//    Age25-29          0.07624    0.10099   0.755  0.45096
//    SexMale           0.03908    0.08619   0.453  0.65058
//      ---
//      Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
//
//    (Dispersion parameter for Tweedie family taken to be 2.896306)
//
//    Null deviance: 967.05  on 286  degrees of freedom
//    Residual deviance: 908.86  on 281  degrees of freedom
//    AIC: NA
//
//    Number of Fisher Scoring iterations: 7
    double [] sderr_exp = new double[]{ 0.11120211,       0.08454967,       0.08393315,       0.10041150,       0.10099231,      0.08618960};
    double [] zvals_exp = new double[]{ 9.5021062,       -3.0622693,       -2.6431794,       1.5262357,        0.7548661,        0.4534433};
    double [] pvals_exp = new double[]{ 9.508400e-19,     2.409514e-03,     8.674149e-03,     1.280759e-01,     4.509615e-01,     6.505795e-01 };

    GLMParameters parms = new GLMParameters(Family.tweedie);
    parms._tweedie_variance_power = 1.5;
    parms._tweedie_link_power = 1 - parms._tweedie_variance_power;
    parms._train = _earinf._key;
    parms._standardize = false;
    parms._lambda = new double[]{0};
    parms._alpha = new double[]{0};
    parms._response_column = "Infections";
    parms._compute_p_values = true;
    parms._objective_epsilon = 0;
    parms._missing_values_handling = DeepLearningModel.DeepLearningParameters.MissingValuesHandling.Skip;

    GLMModel model = null;
    Frame predict = null;
    try {
      model = new GLM(parms).trainModel().get();
      String[] names_expected = new String[]{"Intercept", "Swimmer.Occas", "Location.NonBeach", "Age.20-24", "Age.25-29", "Sex.Male"};
      String[] names_actual = model._output.coefficientNames();
      HashMap<String, Integer> coefMap = new HashMap<>();
      for (int i = 0; i < names_expected.length; ++i)
        coefMap.put(names_expected[i], i);
      double[] stder_actual = model._output.stdErr();
      double[] zvals_actual = model._output.zValues();
      double[] pvals_actual = model._output.pValues();
      for (int i = 0; i < sderr_exp.length; ++i) {
        int id = coefMap.get(names_actual[i]);
        assertEquals(sderr_exp[id], stder_actual[i], sderr_exp[id] * 1e-3);
        assertEquals(zvals_exp[id], zvals_actual[i], Math.abs(zvals_exp[id]) * 1e-3);
        assertEquals(pvals_exp[id], pvals_actual[i], Math.max(1e-8,pvals_exp[id]) * 5e-3);
      }
      predict = model.score(parms._train.get());
      Vec.Reader r = predict.vec("StdErr").new Reader();
      for(int i = 0; i < 10; i++)
        System.out.println(tweedie_se_fit[i] + " ?=? " + r.at(i));
      for(int i = 0; i < tweedie_se_fit.length; ++i)
        assertEquals(tweedie_se_fit[i],r.at(i),1e-4);
    } finally {
      if(model != null) model.delete();
      if(predict != null) predict.delete();
    }
  }
 

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

示例19: testPValuesPoisson

点赞 2

import hex.deeplearning.DeepLearningModel; //导入依赖的package包/类
@Test
  public void testPValuesPoisson() {
//    Coefficients:
//    Estimate Std. Error z value Pr(>|z|)
//    (Intercept) -1.279e+00  3.481e-01  -3.673 0.000239 ***
//    Merit1      -1.498e-01  2.972e-02  -5.040 4.64e-07 ***
//    Merit2      -2.364e-01  3.859e-02  -6.127 8.96e-10 ***
//    Merit3      -3.197e-01  5.095e-02  -6.274 3.52e-10 ***
//    Class2       6.899e-02  8.006e-02   0.862 0.388785
//    Class3       2.892e-01  6.333e-02   4.566 4.97e-06 ***
//    Class4       2.708e-01  4.911e-02   5.515 3.49e-08 ***
//    Class5      -4.468e-02  1.048e-01  -0.427 0.669732
//    Insured      1.617e-06  5.069e-07   3.191 0.001420 **
//    Premium     -3.630e-05  1.087e-05  -3.339 0.000840 ***
//    Cost         2.021e-05  6.869e-06   2.943 0.003252 **
//    logInsured   9.390e-01  2.622e-02  35.806  < 2e-16 ***
//    ---
//      Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
//
//    (Dispersion parameter for poisson family taken to be 1)
//
//    Null deviance: 961181.685  on 19  degrees of freedom
//    Residual deviance:     42.671  on  8  degrees of freedom
//    AIC: 277.08

    double [] sderr_exp = new double[]{ 3.480733e-01, 2.972063e-02, 3.858825e-02, 5.095260e-02,8.005579e-02, 6.332867e-02, 4.910690e-02, 1.047531e-01, 5.068602e-07, 1.086939e-05, 6.869142e-06 ,2.622370e-02};
    double [] zvals_exp = new double[]{ -3.6734577,  -5.0404946,  -6.1269397,  -6.2739848,   0.8618220,   4.5662083 ,  5.5148904,  -0.4265158 ,  3.1906387,  -3.3392867,   2.9428291,  35.8061272  };
    double [] pvals_exp = new double[]{ 2.392903e-04,  4.643302e-07,  8.958540e-10 , 3.519228e-10,  3.887855e-01 , 4.966252e-06,  3.489974e-08 , 6.697321e-01 , 1.419587e-03,  8.399383e-04,  3.252279e-03, 8.867127e-281};

    GLMParameters parms = new GLMParameters(Family.poisson);
    parms._train = _canCarTrain._key;
    parms._standardize = false;
    parms._lambda = new double[]{0};
    parms._alpha = new double[]{0};
    parms._response_column = "Claims";
    parms._compute_p_values = true;
    parms._objective_epsilon = 0;
    parms._missing_values_handling = DeepLearningModel.DeepLearningParameters.MissingValuesHandling.Skip;

    GLMModel model = null;
    Frame predict = null;
    try {
      model = new GLM(parms).trainModel().get();
      predict = model.score(parms._train.get());
      String[] names_expected = new String[]{"Intercept",  "Merit.1", "Merit.2", "Merit.3", "Class.2", "Class.3", "Class.4", "Class.5","Insured","Premium", "Cost", "logInsured" };
      String[] names_actual = model._output.coefficientNames();
      HashMap<String, Integer> coefMap = new HashMap<>();
      for (int i = 0; i < names_expected.length; ++i)
        coefMap.put(names_expected[i], i);
      double[] stder_actual = model._output.stdErr();
      double[] zvals_actual = model._output.zValues();
      double[] pvals_actual = model._output.pValues();
      for (int i = 0; i < sderr_exp.length; ++i) {
        int id = coefMap.get(names_actual[i]);
        assertEquals(sderr_exp[id], stder_actual[i], sderr_exp[id] * 1e-4);
        assertEquals(zvals_exp[id], zvals_actual[i], Math.abs(zvals_exp[id]) * 1e-4);
        assertEquals(pvals_exp[id], pvals_actual[i], Math.max(1e-15,pvals_exp[id] * 1e-3));
      }
      Vec.Reader r = predict.vec("StdErr").new Reader();
      for(int i = 0; i < 10; i++)
        System.out.println(fit_se[i] + " ?=? " + r.at(i));
      for(int i = 0; i < poisson_se_fit.length; ++i)
        assertEquals(poisson_se_fit[i],r.at(i),1e-4);
    } finally {
      if(model != null) model.delete();
      if(predict != null) predict.delete();
    }
  }
 

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

示例20: testCovtypeNoIntercept

点赞 2

import hex.deeplearning.DeepLearningModel; //导入依赖的package包/类
@Test
  public void testCovtypeNoIntercept(){
    GLMParameters params = new GLMParameters(Family.multinomial);
    GLMModel model = null;
    Frame preds = null;
    Vec weights = _covtype.anyVec().makeCon(1);
    Key k = Key.<Frame>make("cov_with_weights");
    Frame f = new Frame(k,_covtype.names(),_covtype.vecs());
    f.add("weights",weights);
    DKV.put(f);
    try {
      params._response_column = "C55";
      params._train = k;
      params._valid = _covtype._key;
      params._objective_epsilon = 1e-6;
      params._beta_epsilon = 1e-4;
      params._weights_column = "weights";
      params._missing_values_handling = DeepLearningModel.DeepLearningParameters.MissingValuesHandling.Skip;
      params._intercept = false;
      double[] alpha = new double[]{0,.5,.1};
      Solver s = Solver.L_BFGS;
      System.out.println("solver = " + s);
      params._solver = s;
      params._max_iterations = 5000;
      for (int i = 0; i < alpha.length; ++i) {
        params._alpha = new double[]{alpha[i]};
//        params._lambda[0] = lambda[i];
        model = new GLM(params).trainModel().get();
        System.out.println(model.coefficients());
//        Assert.assertEquals(0,model.coefficients().get("Intercept"),0);
        double [][] bs = model._output.getNormBetaMultinomial();
        for(double [] b:bs)
          Assert.assertEquals(0,b[b.length-1],0);
        System.out.println(model._output._model_summary);
        System.out.println(model._output._training_metrics);
        System.out.println(model._output._validation_metrics);
        preds = model.score(_covtype);
        ModelMetricsMultinomialGLM mmTrain = (ModelMetricsMultinomialGLM) hex.ModelMetricsMultinomial.getFromDKV(model, _covtype);
        assertTrue(model._output._training_metrics.equals(mmTrain));
        model.delete();
        model = null;
        preds.delete();
        preds = null;
      }
    } finally{
      weights.remove();
      DKV.remove(k);
      if(model != null)model.delete();
      if(preds != null)preds.delete();
    }
  }
 

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

示例21: testCovtypeBasic

点赞 2

import hex.deeplearning.DeepLearningModel; //导入依赖的package包/类
@Test
public void testCovtypeBasic(){
  GLMParameters params = new GLMParameters(Family.multinomial);
  GLMModel model = null;
  Frame preds = null;
  Vec weights = _covtype.anyVec().makeCon(1);
  Key k = Key.<Frame>make("cov_with_weights");
  Frame f = new Frame(k,_covtype.names(),_covtype.vecs());
  f.add("weights",weights);
  DKV.put(f);
  try {
    params._response_column = "C55";
    params._train = k;
    params._valid = _covtype._key;
    params._lambda = new double[]{4.881e-05};
    params._alpha = new double[]{1};
    params._objective_epsilon = 1e-6;
    params._beta_epsilon = 1e-4;
    params._weights_column = "weights";
    params._missing_values_handling = DeepLearningModel.DeepLearningParameters.MissingValuesHandling.Skip;
    double[] alpha = new double[]{1};
    double[] expected_deviance = new double[]{25499.76};
    double[] lambda = new double[]{2.544750e-05};
    for (Solver s : new Solver[]{Solver.IRLSM, Solver.COORDINATE_DESCENT, Solver.L_BFGS}) {
      System.out.println("solver = " + s);
      params._solver = s;
      params._max_iterations = params._solver == Solver.L_BFGS?300:10;
      for (int i = 0; i < alpha.length; ++i) {
        params._alpha[0] = alpha[i];
        params._lambda[0] = lambda[i];
        model = new GLM(params).trainModel().get();
        System.out.println(model._output._model_summary);
        System.out.println(model._output._training_metrics);
        System.out.println(model._output._validation_metrics);
        assertTrue(model._output._training_metrics.equals(model._output._validation_metrics));
        assertTrue(((ModelMetricsMultinomialGLM) model._output._training_metrics)._resDev <= expected_deviance[i] * 1.1);
        preds = model.score(_covtype);
        ModelMetricsMultinomialGLM mmTrain = (ModelMetricsMultinomialGLM) hex.ModelMetricsMultinomial.getFromDKV(model, _covtype);
        assertTrue(model._output._training_metrics.equals(mmTrain));
        model.delete();
        model = null;
        preds.delete();
        preds = null;
      }
    }
  } finally{
    weights.remove();
    DKV.remove(k);
    if(model != null)model.delete();
    if(preds != null)preds.delete();
  }
}
 

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

示例22: testCovtypeNAs

点赞 2

import hex.deeplearning.DeepLearningModel; //导入依赖的package包/类
@Test
  public void testCovtypeNAs(){
    GLMParameters params = new GLMParameters(Family.multinomial);
    GLMModel model = null;
    Frame preds = null;
    Frame covtype_subset = null, covtype_copy = null;
    try {
      double expected_deviance = 26000;
      covtype_copy = _covtype.deepCopy("covtype_copy");
      DKV.put(covtype_copy);
      Vec.Writer w = covtype_copy.vec(54).open();
      w.setNA(10);
      w.setNA(20);
      w.setNA(30);
      w.close();
      covtype_subset = new Frame(Key.<Frame>make("covtype_subset"),new String[]{"C51","C52","C53","C54","C55"},covtype_copy.vecs(new int[]{50,51,52,53,54}));
      DKV.put(covtype_subset);
//      params._nlambdas = 3;
      params._response_column = "C55";
      params._train = covtype_copy._key;
      params._valid = covtype_copy._key;
      params._alpha = new double[]{.99};
      params._objective_epsilon = 1e-6;
      params._beta_epsilon = 1e-4;
      params._max_active_predictors = 50;
      params._max_iterations = 500;
      params._solver = Solver.L_BFGS;
      params._missing_values_handling = DeepLearningModel.DeepLearningParameters.MissingValuesHandling.Skip;
//      params._lambda_search = true;
      model = new GLM(params).trainModel().get();
      assertEquals(covtype_copy.numRows()-3-1,model._nullDOF);
      System.out.println(model._output._training_metrics);
      System.out.println(model._output._validation_metrics);
      assertTrue(model._output._training_metrics.equals(model._output._validation_metrics));
      preds = model.score(covtype_copy);
      ModelMetricsMultinomialGLM mmTrain = (ModelMetricsMultinomialGLM) hex.ModelMetricsMultinomial.getFromDKV(model, covtype_copy);
      assertTrue(model._output._training_metrics.equals(mmTrain));
      assertTrue(((ModelMetricsMultinomialGLM) model._output._training_metrics)._resDev <= expected_deviance);
      System.out.println(model._output._model_summary);
      model.delete();
      model = null;
      preds.delete();
      preds = null;
      // now run the same on the subset
      params._train = covtype_subset._key;
      model = new GLM(params).trainModel().get();
      assertEquals(covtype_copy.numRows()-3-1,model._nullDOF);
      System.out.println(model._output._training_metrics);
      System.out.println(model._output._validation_metrics);
      assertTrue(model._output._training_metrics.equals(model._output._validation_metrics));
      preds = model.score(_covtype);
      System.out.println(model._output._model_summary);
      assertTrue(((ModelMetricsMultinomialGLM) model._output._training_metrics)._resDev <= 66000);
      model.delete();
      model = null;
      preds.delete();
      preds = null;

    } finally{
      if(covtype_subset != null) covtype_subset.delete();
      if(covtype_copy != null)covtype_copy.delete();
      if(model != null)model.delete();
      if(preds != null)preds.delete();
    }
  }
 

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

示例23: testXValPredictions

点赞 2

import hex.deeplearning.DeepLearningModel; //导入依赖的package包/类
@Test public void testXValPredictions() {
  final int nfolds = 3;
  Frame tfr = null;
  try {
    // Load data, hack frames
    tfr = parse_test_file("smalldata/iris/iris_wheader.csv");
    Frame foldId = new Frame(new String[]{"foldId"}, new Vec[]{AstKFold.kfoldColumn(tfr.vec("class").makeZero(), nfolds, 543216789)});
    tfr.add(foldId);
    DKV.put(tfr);

    // GBM
    GBMModel.GBMParameters parms = new GBMModel.GBMParameters();
    parms._train = tfr._key;
    parms._response_column = "class";
    parms._ntrees = 1;
    parms._max_depth = 1;
    parms._fold_column = "foldId";
    parms._distribution = DistributionFamily.multinomial;
    parms._keep_cross_validation_predictions=true;
    GBM job = new GBM(parms);
    GBMModel gbm = job.trainModel().get();
    checkModel(gbm, foldId.anyVec(),3);

    // DRF
    DRFModel.DRFParameters parmsDRF = new DRFModel.DRFParameters();
    parmsDRF._train = tfr._key;
    parmsDRF._response_column = "class";
    parmsDRF._ntrees = 1;
    parmsDRF._max_depth = 1;
    parmsDRF._fold_column = "foldId";
    parmsDRF._distribution = DistributionFamily.multinomial;
    parmsDRF._keep_cross_validation_predictions=true;
    DRF drfJob = new DRF(parmsDRF);
    DRFModel drf = drfJob.trainModel().get();
    checkModel(drf, foldId.anyVec(),3);

    // GLM
    GLMModel.GLMParameters parmsGLM = new GLMModel.GLMParameters();
    parmsGLM._train = tfr._key;
    parmsGLM._response_column = "sepal_len";
    parmsGLM._fold_column = "foldId";
    parmsGLM._keep_cross_validation_predictions=true;
    GLM glmJob = new GLM(parmsGLM);
    GLMModel glm = glmJob.trainModel().get();
    checkModel(glm, foldId.anyVec(),1);

    // DL
    DeepLearningModel.DeepLearningParameters parmsDL = new DeepLearningModel.DeepLearningParameters();
    parmsDL._train = tfr._key;
    parmsDL._response_column = "class";
    parmsDL._hidden = new int[]{1};
    parmsDL._epochs = 1;
    parmsDL._fold_column = "foldId";
    parmsDL._keep_cross_validation_predictions=true;
    DeepLearning dlJob = new DeepLearning(parmsDL);
    DeepLearningModel dl = dlJob.trainModel().get();
    checkModel(dl, foldId.anyVec(),3);

  } finally {
    if (tfr != null) tfr.remove();
  }
}
 

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

示例24: run

点赞 2

import hex.deeplearning.DeepLearningModel; //导入依赖的package包/类
@Test
  public void run() {
    long seed = 0xDECAF;

    Key file_train = NFSFileVec.make(find_test_file(PATH));
    Frame train = ParseDataset2.parse(Key.make(), new Key[]{file_train});

    DeepLearning p = new DeepLearning();
    p.source = train;
    p.autoencoder = true;
    p.response = train.lastVec();
    p.seed = seed;
    p.hidden = new int[]{100, 50, 20};
//    p.ignored_cols = new int[]{0,1,2,3,6,7,8,10}; //Optional: ignore all categoricals
//    p.ignored_cols = new int[]{4,5,9}; //Optional: ignore all numericals
    p.adaptive_rate = true;
    p.l1 = 1e-4;
    p.activation = DeepLearning.Activation.Tanh;
    p.train_samples_per_iteration = -1;
    p.loss = DeepLearning.Loss.MeanSquare;
    p.epochs = 2;
//    p.shuffle_training_data = true;
    p.force_load_balance = true;
    p.score_training_samples = 0;
    p.score_validation_samples = 0;
//    p.reproducible = true;
    p.invoke();

    // Verification of results

    StringBuilder sb = new StringBuilder();
    sb.append("Verifying results.\n");
    DeepLearningModel mymodel = UKV.get(p.dest());
    sb.append("Reported mean reconstruction error: " + mymodel.mse() + "\n");

    // Training data
    // Reconstruct data using the same helper functions and verify that self-reported MSE agrees
    final Frame l2 = mymodel.scoreAutoEncoder(train);
    final Vec l2vec = l2.anyVec();
    sb.append("Actual   mean reconstruction error: " + l2vec.mean() + "\n");

    // print stats and potential outliers
    double quantile = 1 - 5. / train.numRows();
    sb.append("The following training points are reconstructed with an error above the "
            + quantile * 100 + "-th percentile - potential \"outliers\" in testing data.\n");
    double thresh = mymodel.calcOutlierThreshold(l2vec, quantile);
    for (long i = 0; i < l2vec.length(); i++) {
      if (l2vec.at(i) > thresh) {
        sb.append(String.format("row %d : l2vec error = %5f\n", i, l2vec.at(i)));
      }
    }
    Log.info(sb.toString());

    Assert.assertEquals(mymodel.mse(), l2vec.mean(), 1e-8);

    // Create reconstruction
    Log.info("Creating full reconstruction.");
    final Frame recon_train = mymodel.score(train);

    // cleanup
    recon_train.delete();
    train.delete();
    p.delete();
    mymodel.delete();
    l2.delete();
  }
 

开发者ID:h2oai,
项目名称:h2o-2,
代码行数:67,
代码来源:DeepLearningAutoEncoderCategoricalTest.java

示例25: run

点赞 2

import hex.deeplearning.DeepLearningModel; //导入依赖的package包/类
@Test public void run() {
  Key file = NFSFileVec.make(find_test_file("smalldata/neural/two_spiral.data"));
  Frame frame = ParseDataset2.parse(Key.make(), new Key[]{file});

  Key dest = Key.make("spirals2");

  for (boolean sparse : new boolean[]{true,false}) {
    for (boolean col_major : new boolean[]{false}) {
      if (!sparse && col_major) continue;

      // build the model
      {
        DeepLearning p = new DeepLearning();
        p.seed = 0xbabe;
        p.epochs = 10000;
        p.hidden = new int[]{100};
        p.sparse = sparse;
        p.col_major = col_major;
        p.activation = DeepLearning.Activation.Tanh;
        p.max_w2 = Float.POSITIVE_INFINITY;
        p.l1 = 0;
        p.l2 = 0;
        p.initial_weight_distribution = DeepLearning.InitialWeightDistribution.Normal;
        p.initial_weight_scale = 2.5;
        p.loss = DeepLearning.Loss.CrossEntropy;
        p.source = frame;
        p.response = frame.lastVec();
        p.validation = null;
        p.score_interval = 2;
        p.ignored_cols = null;
        p.train_samples_per_iteration = 0; //sync once per period
        p.quiet_mode = true;
        p.fast_mode = true;
        p.ignore_const_cols = true;
        p.nesterov_accelerated_gradient = true;
        p.classification = true;
        p.diagnostics = true;
        p.expert_mode = true;
        p.score_training_samples = 1000;
        p.score_validation_samples = 10000;
        p.shuffle_training_data = false;
        p.force_load_balance = false;
        p.replicate_training_data = false;
        p.destination_key = dest;
        p.adaptive_rate = true;
        p.reproducible = true;
        p.rho = 0.99;
        p.epsilon = 5e-3;
        p.invoke();
      }

      // score and check result
      {
        DeepLearningModel mymodel = UKV.get(dest);
        double error = mymodel.error();
        if (error >= 0.025) {
          Assert.fail("Classification error is not less than 0.025, but " + error + ".");
        }
        mymodel.delete();
        mymodel.delete_best_model();
      }
    }
  }

  frame.delete();
}
 

开发者ID:h2oai,
项目名称:h2o-2,
代码行数:67,
代码来源:DeepLearningSpiralsTest.java

示例26: getDeepLearningModel

点赞 1

import hex.deeplearning.DeepLearningModel; //导入依赖的package包/类
/**
 * Returns the model
 *
 * @return model
 */
public DeepLearningModel getDeepLearningModel() {
    return this.dlModel;
}
 

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

示例27: setDeepLearningModel

点赞 1

import hex.deeplearning.DeepLearningModel; //导入依赖的package包/类
/**
 * Set the model
 *
 * @param model model
 */
public void setDeepLearningModel(DeepLearningModel model) {
    this.dlModel = model;
}
 

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


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