Search in sources :

Example 66 with Frame

use of water.fvec.Frame in project h2o-3 by h2oai.

the class GBMTest method testUnseenNACategorical.

// PUBDEV-2822
@Test
public void testUnseenNACategorical() {
    String xy = "B,-5\nA,0\nB,0\nA,0\nD,0\nA,3";
    Key tr = Key.make("train");
    Frame df = ParseDataset.parse(tr, makeByteVec(Key.make("xy"), xy));
    String test = ",5\n,0\nB,0\n,0\nE,0\n,3";
    Key te = Key.make("test");
    Frame df2 = ParseDataset.parse(te, makeByteVec(Key.make("te"), test));
    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();
    //AdaptTestTrain leaks when it does inplace Vec adaptation, need a Scope to catch that stuff
    Scope.enter();
    Frame preds = gbm.score(df);
    Frame preds2 = gbm.score(df2);
    Log.info(df);
    Log.info(preds);
    Log.info(df2);
    Log.info(preds2);
    Assert.assertTrue(gbm.testJavaScoring(df, preds, 1e-15));
    Assert.assertTrue(gbm.testJavaScoring(df2, preds2, 1e-15));
    Assert.assertTrue(Math.abs(preds.vec(0).at(0) - -2.5) < 1e-6);
    Assert.assertTrue(Math.abs(preds.vec(0).at(1) - 1) < 1e-6);
    Assert.assertTrue(Math.abs(preds.vec(0).at(2) - -2.5) < 1e-6);
    Assert.assertTrue(Math.abs(preds.vec(0).at(3) - 1) < 1e-6);
    Assert.assertTrue(Math.abs(preds.vec(0).at(4) - 0) < 1e-6);
    Assert.assertTrue(Math.abs(preds.vec(0).at(5) - 1) < 1e-6);
    preds.remove();
    preds2.remove();
    gbm.remove();
    df.remove();
    df2.remove();
    Scope.exit();
}
Also used : Frame(water.fvec.Frame) Test(org.junit.Test)

Example 67 with Frame

use of water.fvec.Frame in project h2o-3 by h2oai.

the class GBMTest method sampleRatePerClass.

@Test
public void sampleRatePerClass() {
    Frame tfr = null;
    Key[] ksplits = null;
    GBMModel gbm = null;
    try {
        Scope.enter();
        tfr = parse_test_file("smalldata/covtype/covtype.20k.data");
        int resp = 54;
        Scope.track(tfr.replace(resp, tfr.vecs()[resp].toCategoricalVec()));
        DKV.put(tfr);
        SplitFrame sf = new SplitFrame(tfr, new double[] { 0.5, 0.5 }, new Key[] { Key.make("train.hex"), Key.make("valid.hex") });
        // Invoke the job
        sf.exec().get();
        ksplits = sf._destination_frames;
        GBMModel.GBMParameters parms = new GBMModel.GBMParameters();
        parms._train = ksplits[0];
        parms._valid = ksplits[1];
        parms._response_column = tfr.names()[resp];
        parms._learn_rate = 0.05f;
        parms._min_split_improvement = 1e-5;
        parms._ntrees = 10;
        parms._score_tree_interval = parms._ntrees;
        parms._max_depth = 5;
        parms._sample_rate_per_class = new double[] { 0.1f, 0.1f, 0.2f, 0.4f, 1f, 0.3f, 0.2f };
        GBM job = new GBM(parms);
        gbm = job.trainModel().get();
        if (gbm != null)
            gbm.delete();
    } finally {
        if (gbm != null)
            gbm.delete();
        if (tfr != null)
            tfr.delete();
        if (ksplits[0] != null)
            ksplits[0].remove();
        if (ksplits[1] != null)
            ksplits[1].remove();
        Scope.exit();
    }
}
Also used : Frame(water.fvec.Frame) Test(org.junit.Test)

Example 68 with Frame

use of water.fvec.Frame in project h2o-3 by h2oai.

the class GBMTest method testCatEncodingCV.

@Test
public void testCatEncodingCV() {
    for (Model.Parameters.CategoricalEncodingScheme c : Model.Parameters.CategoricalEncodingScheme.values()) {
        if (c == Model.Parameters.CategoricalEncodingScheme.OneHotInternal)
            continue;
        Frame tfr = null;
        GBMModel gbm = null;
        try {
            tfr = parse_test_file("./smalldata/junit/weather.csv");
            GBMModel.GBMParameters parms = new GBMModel.GBMParameters();
            parms._train = tfr._key;
            parms._response_column = tfr.lastVecName();
            parms._ntrees = 5;
            parms._categorical_encoding = c;
            parms._nfolds = 3;
            gbm = new GBM(parms).trainModel().get();
        } finally {
            if (tfr != null)
                tfr.delete();
            if (gbm != null)
                gbm.deleteCrossValidationModels();
            if (gbm != null)
                gbm.delete();
        }
    }
}
Also used : Frame(water.fvec.Frame) Test(org.junit.Test)

Example 69 with Frame

use of water.fvec.Frame in project h2o-3 by h2oai.

the class GBMTest method testNoRowWeights.

@Test
public void testNoRowWeights() {
    Frame tfr = null, vfr = null;
    GBMModel gbm = null;
    Scope.enter();
    try {
        tfr = parse_test_file("smalldata/junit/no_weights.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._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 70 with Frame

use of water.fvec.Frame in project h2o-3 by h2oai.

the class GBMTest method testLaplace.

@Test
public void testLaplace() {
    Frame tfr = null;
    GBMModel gbm = null;
    try {
        tfr = parse_test_file("./smalldata/gbm_test/BostonHousing.csv");
        GBMModel.GBMParameters parms = new GBMModel.GBMParameters();
        parms._train = tfr._key;
        parms._response_column = tfr.lastVecName();
        parms._seed = 0xdecaf;
        parms._distribution = laplace;
        gbm = new GBM(parms).trainModel().get();
        Assert.assertEquals(8.05716257, ((ModelMetricsRegression) gbm._output._training_metrics)._MSE, 1e-5);
        Assert.assertEquals(1.42298, /*MAE*/
        ((ModelMetricsRegression) gbm._output._training_metrics)._mean_residual_deviance, 1e-5);
    } finally {
        if (tfr != null)
            tfr.delete();
        if (gbm != null)
            gbm.deleteCrossValidationModels();
        if (gbm != null)
            gbm.delete();
    }
}
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