Search in sources :

Example 16 with TwoDimTable

use of water.util.TwoDimTable in project h2o-3 by h2oai.

the class TwoDimTableTest method run0.

@Test
public void run0() {
    TwoDimTable table = new TwoDimTable("My foo bar table", null, new String[4], new String[] { "DoubleValue", "S2", "My Terrible Percent Value" }, new String[] { "double", "string", "double" }, new String[] { "%5.8e", "%s", "%5.8g %%" }, "", new String[][] { new String[] { null, "One", null }, new String[] { null, null, null }, new String[] { null, "Three", null }, new String[] { null, "FooBar", null } }, new double[][] { new double[] { 1.123, emptyDouble, 3200034.00001 }, new double[] { 123.34, emptyDouble, 1.0 }, new double[] { emptyDouble, emptyDouble, 3234.00001 }, new double[] { 3.33420923423423, emptyDouble, 3.40234234 } });
    String ts = table.toString();
    assertTrue(ts.length() > 0);
    Log.info(ts);
    String json = new TwoDimTableV3().fillFromImpl(table).toJsonString();
    Log.info(json);
}
Also used : TwoDimTable(water.util.TwoDimTable) TwoDimTableV3(water.api.schemas3.TwoDimTableV3) Test(org.junit.Test) ParserTest(water.parser.ParserTest)

Example 17 with TwoDimTable

use of water.util.TwoDimTable in project h2o-3 by h2oai.

the class ScoringInfo method createScoringHistoryTable.

/**
   * Create a TwoDimTable to display the scoring history from an array of scoringInfo.
   * @param scoringInfos array of ScoringInfo to render
   * @param hasValidation do we have validation metrics?
   * @param hasCrossValidation do we have cross-validation metrics?
   * @param modelCategory the category for the model or models
   * @param isAutoencoder is the model or are the models autoencoders?
   * @return
   */
public static TwoDimTable createScoringHistoryTable(ScoringInfo[] scoringInfos, boolean hasValidation, boolean hasCrossValidation, ModelCategory modelCategory, boolean isAutoencoder) {
    boolean hasEpochs = (scoringInfos instanceof HasEpochs[]);
    boolean hasSamples = (scoringInfos instanceof HasSamples[]);
    boolean hasIterations = (scoringInfos instanceof HasIterations[]);
    boolean isClassifier = (modelCategory == ModelCategory.Binomial || modelCategory == ModelCategory.Multinomial);
    List<String> colHeaders = new ArrayList<>();
    List<String> colTypes = new ArrayList<>();
    List<String> colFormat = new ArrayList<>();
    colHeaders.add("Timestamp");
    colTypes.add("string");
    colFormat.add("%s");
    colHeaders.add("Duration");
    colTypes.add("string");
    colFormat.add("%s");
    if (hasSamples) {
        colHeaders.add("Training Speed");
        colTypes.add("string");
        colFormat.add("%s");
    }
    if (hasEpochs) {
        colHeaders.add("Epochs");
        colTypes.add("double");
        colFormat.add("%.5f");
    }
    if (hasIterations) {
        colHeaders.add("Iterations");
        colTypes.add("int");
        colFormat.add("%d");
    }
    if (hasSamples) {
        colHeaders.add("Samples");
        colTypes.add("double");
        colFormat.add("%f");
    }
    colHeaders.add("Training RMSE");
    colTypes.add("double");
    colFormat.add("%.5f");
    if (modelCategory == ModelCategory.Regression) {
        colHeaders.add("Training Deviance");
        colTypes.add("double");
        colFormat.add("%.5f");
    }
    if (modelCategory == ModelCategory.Regression) {
        colHeaders.add("Training MAE");
        colTypes.add("double");
        colFormat.add("%.5f");
    }
    if (isClassifier) {
        colHeaders.add("Training LogLoss");
        colTypes.add("double");
        colFormat.add("%.5f");
    }
    if (modelCategory == ModelCategory.Binomial) {
        colHeaders.add("Training AUC");
        colTypes.add("double");
        colFormat.add("%.5f");
    }
    if (modelCategory == ModelCategory.Binomial) {
        colHeaders.add("Training Lift");
        colTypes.add("double");
        colFormat.add("%.5f");
    }
    if (isClassifier) {
        colHeaders.add("Training Classification Error");
        colTypes.add("double");
        colFormat.add("%.5f");
    }
    if (modelCategory == ModelCategory.AutoEncoder) {
        colHeaders.add("Training MSE");
        colTypes.add("double");
        colFormat.add("%.5f");
    }
    if (hasValidation) {
        colHeaders.add("Validation RMSE");
        colTypes.add("double");
        colFormat.add("%.5f");
        if (modelCategory == ModelCategory.Regression) {
            colHeaders.add("Validation Deviance");
            colTypes.add("double");
            colFormat.add("%.5f");
            colHeaders.add("Validation MAE");
            colTypes.add("double");
            colFormat.add("%.5f");
        }
        if (isClassifier) {
            colHeaders.add("Validation LogLoss");
            colTypes.add("double");
            colFormat.add("%.5f");
        }
        if (modelCategory == ModelCategory.Binomial) {
            colHeaders.add("Validation AUC");
            colTypes.add("double");
            colFormat.add("%.5f");
        }
        if (modelCategory == ModelCategory.Binomial) {
            colHeaders.add("Validation Lift");
            colTypes.add("double");
            colFormat.add("%.5f");
        }
        if (isClassifier) {
            colHeaders.add("Validation Classification Error");
            colTypes.add("double");
            colFormat.add("%.5f");
        }
        if (modelCategory == ModelCategory.AutoEncoder) {
            colHeaders.add("Validation MSE");
            colTypes.add("double");
            colFormat.add("%.5f");
        }
    }
    // (hasValidation)
    if (hasCrossValidation) {
        colHeaders.add("Cross-Validation RMSE");
        colTypes.add("double");
        colFormat.add("%.5f");
        if (modelCategory == ModelCategory.Regression) {
            colHeaders.add("Cross-Validation Deviance");
            colTypes.add("double");
            colFormat.add("%.5f");
            colHeaders.add("Cross-Validation MAE");
            colTypes.add("double");
            colFormat.add("%.5f");
        }
        if (isClassifier) {
            colHeaders.add("Cross-Validation LogLoss");
            colTypes.add("double");
            colFormat.add("%.5f");
        }
        if (modelCategory == ModelCategory.Binomial) {
            colHeaders.add("Cross-Validation AUC");
            colTypes.add("double");
            colFormat.add("%.5f");
        }
        if (modelCategory == ModelCategory.Binomial) {
            colHeaders.add("Cross-Validation Lift");
            colTypes.add("double");
            colFormat.add("%.5f");
        }
        if (isClassifier) {
            colHeaders.add("Cross-Validation Classification Error");
            colTypes.add("double");
            colFormat.add("%.5f");
        }
        if (modelCategory == ModelCategory.AutoEncoder) {
            colHeaders.add("Cross-Validation MSE");
            colTypes.add("double");
            colFormat.add("%.5f");
        }
    }
    // (hasCrossValidation)
    final int rows = scoringInfos == null ? 0 : scoringInfos.length;
    String[] s = new String[0];
    TwoDimTable table = new TwoDimTable("Scoring History", null, new String[rows], colHeaders.toArray(s), colTypes.toArray(s), colFormat.toArray(s), "");
    int row = 0;
    if (null == scoringInfos)
        return table;
    for (ScoringInfo si : scoringInfos) {
        int col = 0;
        assert (row < table.getRowDim());
        assert (col < table.getColDim());
        DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
        table.set(row, col++, fmt.print(si.time_stamp_ms));
        table.set(row, col++, PrettyPrint.msecs(si.total_training_time_ms, true));
        if (hasSamples) {
            //      Log.info("1st speed: (samples: " + si.training_samples + ", total_run_time: " + si.total_training_time_ms + ", total_scoring_time: " + si.total_scoring_time_ms + ", total_setup_time: " + si.total_setup_time_ms + ")");
            float speed = (float) (((HasSamples) si).training_samples() / ((1. + si.total_training_time_ms - si.total_scoring_time_ms - si.total_setup_time_ms) / 1e3));
            assert (speed >= 0) : "Speed should not be negative! " + speed + " = (float)(" + ((HasSamples) si).training_samples() + "/((" + si.total_training_time_ms + "-" + si.total_scoring_time_ms + "-" + si.total_setup_time_ms + ")/1e3)";
            table.set(row, col++, si.total_training_time_ms == 0 ? null : (speed > 10 ? String.format("%d", (int) speed) : String.format("%g", speed)) + " obs/sec");
        }
        if (hasEpochs)
            table.set(row, col++, ((HasEpochs) si).epoch_counter());
        if (hasIterations)
            table.set(row, col++, ((HasIterations) si).iterations());
        if (hasSamples)
            table.set(row, col++, ((HasSamples) si).training_samples());
        table.set(row, col++, si.scored_train != null ? si.scored_train._rmse : Double.NaN);
        if (modelCategory == ModelCategory.Regression) {
            table.set(row, col++, si.scored_train != null ? si.scored_train._mean_residual_deviance : Double.NaN);
        }
        if (modelCategory == ModelCategory.Regression) {
            table.set(row, col++, si.scored_train != null ? si.scored_train._mae : Double.NaN);
        }
        if (isClassifier) {
            table.set(row, col++, si.scored_train != null ? si.scored_train._logloss : Double.NaN);
        }
        if (modelCategory == ModelCategory.Binomial) {
            table.set(row, col++, si.training_AUC != null ? si.training_AUC._auc : Double.NaN);
            table.set(row, col++, si.scored_train != null ? si.scored_train._lift : Double.NaN);
        }
        if (isClassifier) {
            table.set(row, col++, si.scored_train != null ? si.scored_train._classError : Double.NaN);
        }
        if (isAutoencoder) {
            table.set(row, col++, si.scored_train != null ? si.scored_train._mse : Double.NaN);
        }
        if (hasValidation) {
            table.set(row, col++, si.scored_valid != null ? si.scored_valid._rmse : Double.NaN);
            if (modelCategory == ModelCategory.Regression) {
                table.set(row, col++, si.scored_valid != null ? si.scored_valid._mean_residual_deviance : Double.NaN);
            }
            if (modelCategory == ModelCategory.Regression) {
                table.set(row, col++, si.scored_valid != null ? si.scored_valid._mae : Double.NaN);
            }
            if (isClassifier) {
                table.set(row, col++, si.scored_valid != null ? si.scored_valid._logloss : Double.NaN);
            }
            if (modelCategory == ModelCategory.Binomial) {
                table.set(row, col++, si.validation_AUC != null ? si.validation_AUC._auc : Double.NaN);
                table.set(row, col++, si.scored_valid != null ? si.scored_valid._lift : Double.NaN);
            }
            if (isClassifier) {
                table.set(row, col, si.scored_valid != null ? si.scored_valid._classError : Double.NaN);
            }
            if (isAutoencoder) {
                table.set(row, col++, si.scored_valid != null ? si.scored_valid._mse : Double.NaN);
            }
        }
        // hasValidation
        if (hasCrossValidation) {
            table.set(row, col++, si.scored_xval != null ? si.scored_xval._rmse : Double.NaN);
            if (modelCategory == ModelCategory.Regression) {
                table.set(row, col++, si.scored_xval != null ? si.scored_xval._mean_residual_deviance : Double.NaN);
            }
            if (modelCategory == ModelCategory.Regression) {
                table.set(row, col++, si.scored_xval != null ? si.scored_xval._mae : Double.NaN);
            }
            if (isClassifier) {
                table.set(row, col++, si.scored_xval != null ? si.scored_xval._logloss : Double.NaN);
            }
            if (modelCategory == ModelCategory.Binomial) {
                table.set(row, col++, si.validation_AUC != null ? si.validation_AUC._auc : Double.NaN);
                table.set(row, col++, si.scored_xval != null ? si.scored_xval._lift : Double.NaN);
            }
            if (isClassifier) {
                table.set(row, col, si.scored_xval != null ? si.scored_xval._classError : Double.NaN);
            }
            if (isAutoencoder) {
                table.set(row, col++, si.scored_xval != null ? si.scored_xval._mse : Double.NaN);
            }
        }
        // hasCrossValidation
        row++;
    }
    return table;
}
Also used : ArrayList(java.util.ArrayList) PrettyPrint(water.util.PrettyPrint) TwoDimTable(water.util.TwoDimTable) DateTimeFormatter(org.joda.time.format.DateTimeFormatter)

Example 18 with TwoDimTable

use of water.util.TwoDimTable in project h2o-3 by h2oai.

the class GridSchemaV99 method fillFromImpl.

@Override
public GridSchemaV99 fillFromImpl(Grid grid) {
    Key<Model>[] gridModelKeys = grid.getModelKeys();
    // Return only keys which are referencing to existing objects in DKV
    // However, here is still implicit race, since we are sending
    // keys to client, but referenced models can be deleted in meantime
    // Hence, client has to be responsible for handling this situation
    // - call getModel and check for null model
    // pre-allocate
    List<Key<Model>> modelKeys = new ArrayList<>(gridModelKeys.length);
    for (Key k : gridModelKeys) {
        if (k != null && DKV.get(k) != null) {
            modelKeys.add(k);
        }
    }
    // Default sort order -- TODO: Outsource
    if (sort_by == null && modelKeys.size() > 0 && modelKeys.get(0) != null) {
        Model m = DKV.getGet(modelKeys.get(0));
        if (m != null && m.isSupervised()) {
            if (m._output.nclasses() > 1) {
                sort_by = "logloss";
                decreasing = false;
            } else {
                sort_by = "residual_deviance";
                decreasing = false;
            }
        }
    }
    // If not, show all possible metrics
    if (modelKeys.size() > 0 && sort_by != null) {
        Set<String> possibleMetrics = ModelMetrics.getAllowedMetrics(modelKeys.get(0));
        if (!possibleMetrics.contains(sort_by.toLowerCase())) {
            throw new H2OIllegalArgumentException("Invalid argument for sort_by specified. Must be one of: " + Arrays.toString(possibleMetrics.toArray(new String[0])));
        }
    }
    // Are we sorting by model metrics?
    if (null != sort_by && !sort_by.isEmpty()) {
        // sort the model keys
        modelKeys = ModelMetrics.sortModelsByMetric(sort_by, decreasing, modelKeys);
        // fill the metrics arrays
        training_metrics = new ModelMetricsBaseV3[modelKeys.size()];
        validation_metrics = new ModelMetricsBaseV3[modelKeys.size()];
        cross_validation_metrics = new ModelMetricsBaseV3[modelKeys.size()];
        cross_validation_metrics_summary = new TwoDimTableV3[modelKeys.size()];
        for (int i = 0; i < modelKeys.size(); i++) {
            Model m = DKV.getGet(modelKeys.get(i));
            if (m != null) {
                Model.Output o = m._output;
                if (null != o._training_metrics)
                    training_metrics[i] = (ModelMetricsBaseV3) SchemaServer.schema(3, o._training_metrics).fillFromImpl(o._training_metrics);
                if (null != o._validation_metrics)
                    validation_metrics[i] = (ModelMetricsBaseV3) SchemaServer.schema(3, o._validation_metrics).fillFromImpl(o._validation_metrics);
                if (null != o._cross_validation_metrics)
                    cross_validation_metrics[i] = (ModelMetricsBaseV3) SchemaServer.schema(3, o._cross_validation_metrics).fillFromImpl(o._cross_validation_metrics);
                if (o._cross_validation_metrics_summary != null)
                    cross_validation_metrics_summary[i] = new TwoDimTableV3(o._cross_validation_metrics_summary);
            }
        }
    }
    KeyV3.ModelKeyV3[] modelIds = new KeyV3.ModelKeyV3[modelKeys.size()];
    Key<Model>[] keys = new Key[modelKeys.size()];
    for (int i = 0; i < modelIds.length; i++) {
        modelIds[i] = new KeyV3.ModelKeyV3(modelKeys.get(i));
        keys[i] = modelIds[i].key();
    }
    grid_id = new KeyV3.GridKeyV3(grid._key);
    model_ids = modelIds;
    hyper_names = grid.getHyperNames();
    failed_params = toModelParametersSchema(grid.getFailedParameters());
    failure_details = grid.getFailureDetails();
    failure_stack_traces = grid.getFailureStackTraces();
    failed_raw_params = grid.getFailedRawParameters();
    TwoDimTable t = grid.createSummaryTable(keys, sort_by, decreasing);
    if (t != null)
        summary_table = new TwoDimTableV3().fillFromImpl(t);
    TwoDimTable h = grid.createScoringHistoryTable();
    if (h != null)
        scoring_history = new TwoDimTableV3().fillFromImpl(h);
    return this;
}
Also used : ArrayList(java.util.ArrayList) H2OIllegalArgumentException(water.exceptions.H2OIllegalArgumentException) TwoDimTable(water.util.TwoDimTable) Model(hex.Model) Key(water.Key)

Example 19 with TwoDimTable

use of water.util.TwoDimTable in project h2o-3 by h2oai.

the class TwoDimTableTest method run3.

@Test
public void run3() {
    TwoDimTable table = new TwoDimTable("My foo bar table", "desc", new String[] { "First row", "R2", "Row #3", "Last row is here:" }, new String[] { "DoubleValue", "S2", "My Terrible Percent Value" }, new String[] { "double", "string", "double" }, new String[] { "%f", "%s", "%f" }, "", new String[][] { new String[] { null, "One", null }, new String[] { null, null, null }, new String[] { null, "Three", null }, new String[] { null, "FooBar", null } }, new double[][] { new double[] { 1.123, emptyDouble, 3200034.00001 }, new double[] { 123.34, emptyDouble, 1.0 }, new double[] { emptyDouble, emptyDouble, 3234.00001 }, new double[] { 3.33420923423423, emptyDouble, 3.40234234 } });
    String ts = table.toString();
    assertTrue(ts.length() > 0);
    Log.info(ts);
    String json = new TwoDimTableV3().fillFromImpl(table).toJsonString();
    Log.info(json);
}
Also used : TwoDimTable(water.util.TwoDimTable) TwoDimTableV3(water.api.schemas3.TwoDimTableV3) Test(org.junit.Test) ParserTest(water.parser.ParserTest)

Example 20 with TwoDimTable

use of water.util.TwoDimTable in project h2o-3 by h2oai.

the class DeepWaterModelInfo method createSummaryTable.

/**
   * Create a summary table
   * @return TwoDimTable with the summary of the model
   */
TwoDimTable createSummaryTable() {
    TwoDimTable table = new TwoDimTable("Status of Deep Learning Model", (get_params()._network == null ? ("MLP: " + Arrays.toString(get_params()._hidden)) : get_params()._network.toString()) + ", " + PrettyPrint.bytes(size()) + ", " + (!get_params()._autoencoder ? ("predicting " + get_params()._response_column + ", ") : "") + (get_params()._autoencoder ? "auto-encoder" : _classification ? (_classes + "-class classification") : "regression") + ", " + String.format("%,d", get_processed_global()) + " training samples, " + "mini-batch size " + String.format("%,d", get_params()._mini_batch_size), //rows
    new String[1], new String[] { "Input Neurons", "Rate", "Momentum" }, new String[] { "int", "double", "double" }, new String[] { "%d", "%5f", "%5f" }, "");
    table.set(0, 0, _dataInfo != null ? _dataInfo.fullN() : _width * _height * _channels);
    table.set(0, 1, get_params().learningRate(get_processed_global()));
    table.set(0, 2, get_params().momentum(get_processed_global()));
    summaryTable = table;
    return summaryTable;
}
Also used : TwoDimTable(water.util.TwoDimTable)

Aggregations

TwoDimTable (water.util.TwoDimTable)30 Test (org.junit.Test)15 ParserTest (water.parser.ParserTest)10 TwoDimTableV3 (water.api.schemas3.TwoDimTableV3)8 Frame (water.fvec.Frame)8 ArrayList (java.util.ArrayList)5 PrettyPrint (water.util.PrettyPrint)5 PartialDependence (hex.PartialDependence)4 GBM (hex.tree.gbm.GBM)4 GBMModel (hex.tree.gbm.GBMModel)4 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)4 Vec (water.fvec.Vec)3 NFSFileVec (water.fvec.NFSFileVec)2 AUC2 (hex.AUC2)1 Model (hex.Model)1 DeepLearningParameters (hex.deeplearning.DeepLearningModel.DeepLearningParameters)1 ShuffleSplitFrame (hex.splitframe.ShuffleSplitFrame)1 Key (water.Key)1 H2OIllegalArgumentException (water.exceptions.H2OIllegalArgumentException)1