use of water.fvec.Frame in project h2o-3 by h2oai.
the class GBMTest method testNfoldsCVAndValidation.
@Test
public void testNfoldsCVAndValidation() {
Frame tfr = null, vfr = null;
GBMModel gbm = null;
Scope.enter();
try {
tfr = parse_test_file("smalldata/junit/weights.csv");
vfr = parse_test_file("smalldata/junit/weights.csv");
DKV.put(tfr);
GBMModel.GBMParameters parms = new GBMModel.GBMParameters();
parms._train = tfr._key;
parms._valid = vfr._key;
parms._response_column = "response";
parms._seed = 12345;
parms._min_rows = 1;
parms._max_depth = 2;
parms._nfolds = 3;
parms._ntrees = 3;
parms._learn_rate = 1e-3f;
try {
Log.info("Trying N-fold cross-validation AND Validation dataset provided.");
gbm = new GBM(parms).trainModel().get();
} catch (H2OModelBuilderIllegalArgumentException e) {
Assert.fail("Should not toss H2OModelBuilderIllegalArgumentException.");
}
} finally {
if (tfr != null)
tfr.remove();
if (vfr != null)
vfr.remove();
if (gbm != null) {
gbm.deleteCrossValidationModels();
gbm.delete();
}
Scope.exit();
}
}
use of water.fvec.Frame in project h2o-3 by h2oai.
the class GBMTest method testOnevsRest.
// PUBDEV-2822
@Test
public void testOnevsRest() {
String xy = "-9,5\n1,0\n2,0\n3,0\n4,0\n-9,3";
Key tr = Key.make("train");
Frame df = ParseDataset.parse(tr, makeByteVec(Key.make("xy"), xy));
GBMModel.GBMParameters parms = new GBMModel.GBMParameters();
parms._train = tr;
parms._response_column = "C2";
parms._min_rows = 1;
parms._learn_rate = 1;
parms._ntrees = 1;
GBM job = new GBM(parms);
GBMModel gbm = job.trainModel().get();
Frame preds = gbm.score(df);
Log.info(df);
Log.info(preds);
Assert.assertTrue(gbm.testJavaScoring(df, preds, 1e-15));
Assert.assertTrue(Math.abs(preds.vec(0).at(0) - 4) < 1e-6);
Assert.assertTrue(Math.abs(preds.vec(0).at(1) - 0) < 1e-6);
Assert.assertTrue(Math.abs(preds.vec(0).at(2) - 0) < 1e-6);
Assert.assertTrue(Math.abs(preds.vec(0).at(3) - 0) < 1e-6);
Assert.assertTrue(Math.abs(preds.vec(0).at(4) - 0) < 1e-6);
Assert.assertTrue(Math.abs(preds.vec(0).at(5) - 4) < 1e-6);
preds.remove();
gbm.remove();
df.remove();
}
use of water.fvec.Frame in project h2o-3 by h2oai.
the class GBMTest method testNoRowWeightsShuffled.
@Test
public void testNoRowWeightsShuffled() {
Frame tfr = null, vfr = null;
GBMModel gbm = null;
Scope.enter();
try {
tfr = parse_test_file("smalldata/junit/no_weights_shuffled.csv");
DKV.put(tfr);
GBMModel.GBMParameters parms = new GBMModel.GBMParameters();
parms._train = tfr._key;
parms._response_column = "response";
parms._seed = 0xdecaf;
parms._min_rows = 1;
parms._max_depth = 2;
parms._ntrees = 3;
parms._learn_rate = 1e-3f;
// Build a first model; all remaining models should be equal
gbm = new GBM(parms).trainModel().get();
ModelMetricsBinomial mm = (ModelMetricsBinomial) gbm._output._training_metrics;
assertEquals(_AUC, mm.auc_obj()._auc, 1e-8);
assertEquals(_MSE, mm.mse(), 1e-8);
assertEquals(_LogLoss, mm.logloss(), 1e-6);
Frame pred = gbm.score(parms.train());
hex.ModelMetricsBinomial mm2 = hex.ModelMetricsBinomial.getFromDKV(gbm, parms.train());
assertEquals(_AUC, mm2.auc_obj()._auc, 1e-8);
assertEquals(_MSE, mm2.mse(), 1e-8);
assertEquals(_LogLoss, mm2.logloss(), 1e-6);
pred.remove();
} finally {
if (tfr != null)
tfr.remove();
if (vfr != null)
vfr.remove();
if (gbm != null)
gbm.delete();
Scope.exit();
}
}
use of water.fvec.Frame in project h2o-3 by h2oai.
the class GBMTest method testNfoldsColumnNumbersFrom0.
@Test
public void testNfoldsColumnNumbersFrom0() {
Frame tfr = null;
Vec old = null;
GBMModel gbm1 = null;
try {
tfr = parse_test_file("smalldata/junit/cars_20mpg.csv");
// Remove unique id
tfr.remove("name").remove();
new MRTask() {
@Override
public void map(Chunk c) {
for (int i = 0; i < c.len(); ++i) {
if (c.at8(i) == 3)
c.set(i, 0);
if (c.at8(i) == 4)
c.set(i, 1);
if (c.at8(i) == 5)
c.set(i, 2);
if (c.at8(i) == 6)
c.set(i, 3);
if (c.at8(i) == 8)
c.set(i, 4);
}
}
}.doAll(tfr.vec("cylinders"));
DKV.put(tfr);
GBMModel.GBMParameters parms = new GBMModel.GBMParameters();
parms._train = tfr._key;
parms._response_column = "economy_20mpg";
parms._fold_column = "cylinders";
parms._ntrees = 10;
GBM job1 = new GBM(parms);
gbm1 = job1.trainModel().get();
Assert.assertTrue(gbm1._output._cross_validation_models.length == 5);
} finally {
if (tfr != null)
tfr.remove();
if (old != null)
old.remove();
if (gbm1 != null) {
gbm1.deleteCrossValidationModels();
gbm1.delete();
}
}
}
use of water.fvec.Frame in project h2o-3 by h2oai.
the class GBMTest method missingAndUnseenValues.
@Test
public void missingAndUnseenValues() {
GBMModel gbm = null;
GBMModel.GBMParameters parms = new GBMModel.GBMParameters();
Frame train = null, test = null, train_preds = null, test_preds = null;
Scope.enter();
try {
{
CreateFrame cf = new CreateFrame();
cf.rows = 100;
cf.cols = 10;
cf.integer_range = 1000;
cf.categorical_fraction = 1.0;
cf.integer_fraction = 0.0;
cf.binary_fraction = 0.0;
cf.time_fraction = 0.0;
cf.string_fraction = 0.0;
cf.binary_ones_fraction = 0.0;
cf.missing_fraction = 0.2;
cf.factors = 3;
cf.response_factors = 2;
cf.positive_response = false;
cf.has_response = true;
cf.seed = 1235;
cf.seed_for_column_types = 1234;
train = cf.execImpl().get();
}
{
CreateFrame cf = new CreateFrame();
cf.rows = 100;
cf.cols = 10;
cf.integer_range = 1000;
cf.categorical_fraction = 1.0;
cf.integer_fraction = 0.0;
cf.binary_fraction = 0.0;
cf.time_fraction = 0.0;
cf.string_fraction = 0.0;
cf.binary_ones_fraction = 0.0;
cf.missing_fraction = 0.2;
cf.factors = 3;
cf.response_factors = 2;
cf.positive_response = false;
cf.has_response = true;
//different test set
cf.seed = 4321;
cf.seed_for_column_types = 1234;
test = cf.execImpl().get();
}
parms._train = train._key;
// Train on the outcome
parms._response_column = "response";
parms._distribution = DistributionFamily.multinomial;
parms._max_depth = 20;
parms._min_rows = 1;
parms._ntrees = 5;
parms._seed = 1;
GBM job = new GBM(parms);
gbm = job.trainModel().get();
train_preds = gbm.score(train);
test_preds = gbm.score(test);
// Build a POJO, validate same results
Assert.assertTrue(gbm.testJavaScoring(train, train_preds, 1e-15));
Key old = gbm._key;
gbm._key = Key.make(gbm._key + "ha");
Assert.assertTrue(gbm.testJavaScoring(test, test_preds, 1e-15));
DKV.remove(old);
} finally {
if (gbm != null)
gbm.delete();
if (train != null)
train.remove();
if (test != null)
test.remove();
if (train_preds != null)
train_preds.remove();
if (test_preds != null)
test_preds.remove();
Scope.exit();
}
}
Aggregations