use of hex.tree.gbm.GBMModel in project h2o-3 by h2oai.
the class ModelSerializationTest method testGBMModelBinomial.
@Test
public void testGBMModelBinomial() throws IOException {
GBMModel model, loadedModel = null;
try {
model = prepareGBMModel("smalldata/logreg/prostate.csv", ar("ID"), "CAPSULE", true, 5);
CompressedTree[][] trees = getTrees(model);
loadedModel = saveAndLoad(model);
// And compare
assertModelBinaryEquals(model, loadedModel);
CompressedTree[][] loadedTrees = getTrees(loadedModel);
assertTreeEquals("Trees have to be binary same", trees, loadedTrees);
} finally {
if (loadedModel != null)
loadedModel.delete();
}
}
use of hex.tree.gbm.GBMModel in project h2o-3 by h2oai.
the class ModelSerializationTest method prepareGBMModel.
private GBMModel prepareGBMModel(String dataset, String[] ignoredColumns, String response, boolean classification, int ntrees) {
Frame f = parse_test_file(dataset);
try {
if (classification && !f.vec(response).isCategorical()) {
f.replace(f.find(response), f.vec(response).toCategoricalVec()).remove();
DKV.put(f._key, f);
}
GBMModel.GBMParameters gbmParams = new GBMModel.GBMParameters();
gbmParams._train = f._key;
gbmParams._ignored_columns = ignoredColumns;
gbmParams._response_column = response;
gbmParams._ntrees = ntrees;
gbmParams._score_each_iteration = true;
return new GBM(gbmParams).trainModel().get();
} finally {
if (f != null)
f.delete();
}
}
use of hex.tree.gbm.GBMModel in project h2o-3 by h2oai.
the class SSLEncryptionTest method testGBMRegressionGaussian.
private static void testGBMRegressionGaussian() {
GBMModel gbm = null;
Frame fr = null, fr2 = null;
try {
Date start = new Date();
fr = parse_test_file("./smalldata/gbm_test/Mfgdata_gaussian_GBM_testing.csv");
GBMModel.GBMParameters parms = new GBMModel.GBMParameters();
parms._train = fr._key;
parms._distribution = gaussian;
// Row in col 0, dependent in col 1, predictor in col 2
parms._response_column = fr._names[1];
parms._ntrees = 1;
parms._max_depth = 1;
parms._min_rows = 1;
parms._nbins = 20;
// Drop ColV2 0 (row), keep 1 (response), keep col 2 (only predictor), drop remaining cols
String[] xcols = parms._ignored_columns = new String[fr.numCols() - 2];
xcols[0] = fr._names[0];
System.arraycopy(fr._names, 3, xcols, 1, fr.numCols() - 3);
parms._learn_rate = 1.0f;
parms._score_each_iteration = true;
GBM job = new GBM(parms);
gbm = job.trainModel().get();
Log.info(">>> GBM parsing and training took: " + (new Date().getTime() - start.getTime()) + " ms.");
//HEX-1817
Assert.assertTrue(job.isStopped());
// Done building model; produce a score column with predictions
Date scoringStart = new Date();
fr2 = gbm.score(fr);
Log.info(">>> GBM scoring took: " + (new Date().getTime() - scoringStart.getTime()) + " ms.");
} finally {
if (fr != null)
fr.remove();
if (fr2 != null)
fr2.remove();
if (gbm != null)
gbm.remove();
}
}
use of hex.tree.gbm.GBMModel 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 hex.tree.gbm.GBMModel 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();
}
}
Aggregations