Search in sources :

Example 21 with TwoDimTable

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

the class SVD method createModelSummaryTable.

private TwoDimTable createModelSummaryTable(SVDModel.SVDOutput output) {
    if (null == output._d)
        return null;
    String[] colTypes = new String[_parms._nv];
    String[] colFormats = new String[_parms._nv];
    String[] colHeaders = new String[_parms._nv];
    Arrays.fill(colTypes, "double");
    Arrays.fill(colFormats, "%5f");
    for (int i = 0; i < colHeaders.length; i++) colHeaders[i] = "sval" + String.valueOf(i + 1);
    return new TwoDimTable("Singular values", null, new String[1], colHeaders, colTypes, colFormats, "", new String[1][], new double[][] { output._d });
}
Also used : TwoDimTable(water.util.TwoDimTable) PrettyPrint(water.util.PrettyPrint)

Example 22 with TwoDimTable

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

the class TwoDimTableTest method run1.

@Test
public void run1() {
    TwoDimTable table = new TwoDimTable("My foo bar table", "Corner value", 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[] { "%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 23 with TwoDimTable

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

the class TwoDimTableTest method run7.

@Test
public void run7() {
    TwoDimTable table = new TwoDimTable("Mixed", "description", new String[] { "R0", "R1", "R2", "R3" }, new String[] { "C0", "C1", "C2", "C3" }, new String[] { "double", "float", "int", "long" }, new String[] { "%f", "%f", "%d", "%d" }, "");
    table.set(0, 0, Double.NEGATIVE_INFINITY);
    table.set(1, 0, Double.POSITIVE_INFINITY);
    table.set(2, 0, Double.NaN);
    table.set(3, 0, Math.PI);
    table.set(0, 1, Float.NEGATIVE_INFINITY);
    table.set(1, 1, Float.POSITIVE_INFINITY);
    table.set(2, 1, Float.NaN);
    table.set(3, 1, Float.MIN_VALUE);
    table.set(0, 2, Integer.MAX_VALUE);
    table.set(1, 2, Integer.MIN_VALUE);
    table.set(2, 2, Double.NaN);
    table.set(3, 2, 0);
    table.set(0, 3, Long.MAX_VALUE);
    table.set(1, 3, Long.MIN_VALUE);
    table.set(2, 3, Double.NaN);
    table.set(3, 3, null);
    String ts = table.toString();
    assertTrue(ts.length() > 0);
    Log.info(ts);
    assertTrue(table.get(0, 0).equals(Double.NEGATIVE_INFINITY));
    assertTrue(table.get(1, 0).equals(Double.POSITIVE_INFINITY));
    assertTrue(table.get(2, 0).equals(Double.NaN));
    assertTrue(table.get(3, 0).equals(Math.PI));
    assertTrue(table.get(0, 1).equals(Float.NEGATIVE_INFINITY));
    assertTrue(table.get(1, 1).equals(Float.POSITIVE_INFINITY));
    assertTrue(table.get(2, 1).equals(Float.NaN));
    assertTrue(table.get(3, 1).equals(Float.MIN_VALUE));
    assertTrue(table.get(0, 2).equals(Integer.MAX_VALUE));
    assertTrue(table.get(1, 2).equals(Integer.MIN_VALUE));
    assertTrue(table.get(2, 2).equals(Double.NaN));
    assertTrue(table.get(3, 2).equals(0));
    assertTrue(table.get(0, 3).equals(Long.MAX_VALUE));
    assertTrue(table.get(1, 3).equals(Long.MIN_VALUE));
    assertTrue(table.get(2, 3).equals(Double.NaN));
    assertTrue(table.get(3, 3) == null);
    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 24 with TwoDimTable

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

the class TwoDimTableTest method run10.

@Test
public void run10() {
    Frame fr = null;
    try {
        int OFFSET = 5;
        String data = "1\n3\n4\nNA\n";
        Key k1 = ParserTest.makeByteVec(data);
        Key r1 = Key.make();
        fr = ParseDataset.parse(r1, k1);
        assertTrue(fr.numRows() == 4);
        System.out.println(fr);
        TwoDimTable table = fr.toTwoDimTable(0, 4);
        assertTrue(table.getColTypes()[0] == "long");
        //min
        assertTrue((long) table.get(0, 0) == 1);
        //mean
        assertTrue((double) table.get(1, 0) > 2.66);
        //mean
        assertTrue((double) table.get(1, 0) < 2.67);
        //sd
        assertTrue((double) table.get(2, 0) > 1.52);
        //sd
        assertTrue((double) table.get(2, 0) < 1.53);
        //max
        assertTrue((long) table.get(3, 0) == 4);
        //missing
        assertTrue((long) table.get(4, 0) == 1);
        assertTrue((long) table.get(0 + OFFSET, 0) == 1);
        assertTrue((long) table.get(1 + OFFSET, 0) == 3);
        assertTrue((long) table.get(2 + OFFSET, 0) == 4);
        assertTrue(Double.isNaN((double) table.get(3 + OFFSET, 0)));
    } finally {
        if (fr != null)
            fr.delete();
    }
}
Also used : Frame(water.fvec.Frame) TwoDimTable(water.util.TwoDimTable) Test(org.junit.Test) ParserTest(water.parser.ParserTest)

Example 25 with TwoDimTable

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

the class ModelMetricsClustering method createCentroidStatsTable.

/**
   * Populate TwoDimTable from members _size and _withinss
   * @return TwoDimTable
   */
public TwoDimTable createCentroidStatsTable() {
    if (_size == null || _withinss == null)
        return null;
    List<String> colHeaders = new ArrayList<>();
    List<String> colTypes = new ArrayList<>();
    List<String> colFormat = new ArrayList<>();
    colHeaders.add("Centroid");
    colTypes.add("long");
    colFormat.add("%d");
    colHeaders.add("Size");
    colTypes.add("double");
    colFormat.add("%.5f");
    colHeaders.add("Within Cluster Sum of Squares");
    colTypes.add("double");
    colFormat.add("%.5f");
    final int K = _size.length;
    assert (_withinss.length == K);
    TwoDimTable table = new TwoDimTable("Centroid Statistics", null, new String[K], colHeaders.toArray(new String[0]), colTypes.toArray(new String[0]), colFormat.toArray(new String[0]), "");
    for (int k = 0; k < K; ++k) {
        int col = 0;
        table.set(k, col++, k + 1);
        table.set(k, col++, _size[k]);
        table.set(k, col, _withinss[k]);
    }
    return table;
}
Also used : TwoDimTable(water.util.TwoDimTable) ArrayList(java.util.ArrayList)

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