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();
}
}
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();
}
}
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);
}
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);
}
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);
}
Aggregations