Search in sources :

Example 56 with Frame

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();
    }
}
Also used : Frame(water.fvec.Frame) H2OModelBuilderIllegalArgumentException(water.exceptions.H2OModelBuilderIllegalArgumentException) Test(org.junit.Test)

Example 57 with Frame

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();
}
Also used : Frame(water.fvec.Frame) Test(org.junit.Test)

Example 58 with Frame

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();
    }
}
Also used : Frame(water.fvec.Frame) hex(hex) Test(org.junit.Test)

Example 59 with Frame

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();
        }
    }
}
Also used : Frame(water.fvec.Frame) Vec(water.fvec.Vec) FVecTest.makeByteVec(water.fvec.FVecTest.makeByteVec) Chunk(water.fvec.Chunk) Test(org.junit.Test)

Example 60 with Frame

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();
    }
}
Also used : Frame(water.fvec.Frame) Test(org.junit.Test)

Aggregations

Frame (water.fvec.Frame)782 Test (org.junit.Test)435 Vec (water.fvec.Vec)215 ValFrame (water.rapids.vals.ValFrame)132 NFSFileVec (water.fvec.NFSFileVec)66 Val (water.rapids.Val)65 SplitFrame (hex.SplitFrame)59 Key (water.Key)56 DeepLearningParameters (hex.deeplearning.DeepLearningModel.DeepLearningParameters)54 Chunk (water.fvec.Chunk)50 NewChunk (water.fvec.NewChunk)37 MRTask (water.MRTask)33 ShuffleSplitFrame (hex.splitframe.ShuffleSplitFrame)31 Ignore (org.junit.Ignore)28 Random (java.util.Random)26 File (java.io.File)25 BufferedString (water.parser.BufferedString)21 H2OIllegalArgumentException (water.exceptions.H2OIllegalArgumentException)19 HashMap (java.util.HashMap)17 hex (hex)16