Search in sources :

Example 6 with TwoDimTable

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

the class PartialDependenceTest method prostateBinary.

@Test
public void prostateBinary() {
    Frame fr = null;
    GBMModel model = null;
    PartialDependence partialDependence = null;
    try {
        // Frame
        fr = parse_test_file("smalldata/prostate/prostate.csv");
        for (String s : new String[] { "RACE", "GLEASON", "DPROS", "DCAPS", "CAPSULE" }) {
            Vec v = fr.remove(s);
            fr.add(s, v.toCategoricalVec());
            v.remove();
        }
        DKV.put(fr);
        // Model
        GBMModel.GBMParameters parms = new GBMModel.GBMParameters();
        parms._train = fr._key;
        parms._ignored_columns = new String[] { "ID" };
        parms._response_column = "CAPSULE";
        model = new GBM(parms).trainModel().get();
        // PartialDependence
        partialDependence = new PartialDependence(Key.<PartialDependence>make());
        //      partialDependence._cols = model._output._names;
        partialDependence._nbins = 10;
        partialDependence._model_id = (Key) model._key;
        partialDependence._frame_id = fr._key;
        partialDependence.execImpl().get();
        for (TwoDimTable t : partialDependence._partial_dependence_data) Log.info(t);
    } finally {
        if (fr != null)
            fr.remove();
        if (model != null)
            model.remove();
        if (partialDependence != null)
            partialDependence.remove();
    }
}
Also used : PartialDependence(hex.PartialDependence) Frame(water.fvec.Frame) GBMModel(hex.tree.gbm.GBMModel) GBM(hex.tree.gbm.GBM) TwoDimTable(water.util.TwoDimTable) Vec(water.fvec.Vec) Test(org.junit.Test)

Example 7 with TwoDimTable

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

the class PartialDependenceTest method prostateRegression.

@Test
public void prostateRegression() {
    Frame fr = null;
    GBMModel model = null;
    PartialDependence partialDependence = null;
    try {
        // Frame
        fr = parse_test_file("smalldata/prostate/prostate.csv");
        for (String s : new String[] { "RACE", "GLEASON", "DPROS", "DCAPS", "CAPSULE" }) {
            Vec v = fr.remove(s);
            fr.add(s, v.toCategoricalVec());
            v.remove();
        }
        DKV.put(fr);
        // Model
        GBMModel.GBMParameters parms = new GBMModel.GBMParameters();
        parms._train = fr._key;
        parms._ignored_columns = new String[] { "ID" };
        parms._response_column = "AGE";
        model = new GBM(parms).trainModel().get();
        // PartialDependence
        partialDependence = new PartialDependence(Key.<PartialDependence>make());
        partialDependence._nbins = 10;
        partialDependence._model_id = (Key) model._key;
        partialDependence._frame_id = fr._key;
        partialDependence.execImpl().get();
        for (TwoDimTable t : partialDependence._partial_dependence_data) Log.info(t);
    } finally {
        if (fr != null)
            fr.remove();
        if (model != null)
            model.remove();
        if (partialDependence != null)
            partialDependence.remove();
    }
}
Also used : PartialDependence(hex.PartialDependence) Frame(water.fvec.Frame) GBMModel(hex.tree.gbm.GBMModel) GBM(hex.tree.gbm.GBM) TwoDimTable(water.util.TwoDimTable) Vec(water.fvec.Vec) Test(org.junit.Test)

Example 8 with TwoDimTable

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

the class TwoDimTableTest method run4.

@Test
public void run4() {
    TwoDimTable table = new TwoDimTable("All numbers", "yada", new String[] { "R1", "R2", "R3", "R4" }, new String[] { "Num1", "Num2", "Num3" }, new String[] { "double", "double", "double" }, new String[] { "%f", "%f", "%f" }, "", new String[4][], new double[][] { new double[] { 1.123, 3.42, 3200034.00001 }, new double[] { 123.34, emptyDouble, 1.0 }, new double[] { emptyDouble, emptyDouble, 3234.00001 }, new double[] { 3.33420923423423, 83.32, 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 9 with TwoDimTable

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

the class TwoDimTableTest method run5.

@Test
public void run5() {
    TwoDimTable table = new TwoDimTable("All strings", null, new String[] { "R1", "R2", "R3", "R4" }, new String[] { "S1", "S2", "S3", "S4" }, new String[] { "string", "string", "string", "string" }, new String[] { "%s", "%s", "%s", "%s" }, "", new String[][] { new String[] { "a", "b", "c", "d" }, new String[] { "a", "b", "c", "d" }, new String[] { "a", null, "c", "d" }, new String[] { "a", "b", "c", null } }, new double[4][]);
    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 10 with TwoDimTable

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

the class TwoDimTableTest method run8.

@Test
public void run8() {
    TwoDimTable table = new TwoDimTable("Mixed", "description", new String[1000], new String[] { "C0", "C1", "C2", "C3" }, new String[] { "double", "float", "int", "long" }, new String[] { "%f", "%f", "%d", "%d" }, "");
    for (int i = 0; i < 1000; ++i) {
        table.set(i, 0, Double.NEGATIVE_INFINITY);
        table.set(i, 1, Double.POSITIVE_INFINITY);
        table.set(i, 2, i);
        table.set(i, 3, -234234);
    }
    String ts = table.toString(1, false);
    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)

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