Search in sources :

Example 26 with DeepLearningParameters

use of hex.deeplearning.DeepLearningModel.DeepLearningParameters in project h2o-3 by h2oai.

the class DeepLearningTest method testDistributions.

@Test
public void testDistributions() {
    Frame tfr = null, vfr = null, fr2 = null;
    DeepLearningModel dl = null;
    for (DistributionFamily dist : new DistributionFamily[] { AUTO, gaussian, poisson, gamma, tweedie }) {
        Scope.enter();
        try {
            tfr = parse_test_file("smalldata/glm_test/cancar_logIn.csv");
            for (String s : new String[] { "Merit", "Class" }) {
                Scope.track(tfr.replace(tfr.find(s), tfr.vec(s).toCategoricalVec()));
            }
            DKV.put(tfr);
            DeepLearningParameters parms = new DeepLearningParameters();
            parms._train = tfr._key;
            parms._epochs = 1;
            parms._reproducible = true;
            parms._hidden = new int[] { 50, 50 };
            parms._response_column = "Cost";
            parms._seed = 0xdecaf;
            parms._distribution = dist;
            // Build a first model; all remaining models should be equal
            DeepLearning job = new DeepLearning(parms);
            dl = job.trainModel().get();
            ModelMetricsRegression mm = (ModelMetricsRegression) dl._output._training_metrics;
            if (dist == gaussian || dist == AUTO)
                Assert.assertEquals(mm._mean_residual_deviance, mm._MSE, 1e-6);
            else
                assertTrue(mm._mean_residual_deviance != mm._MSE);
            assertTrue(dl.testJavaScoring(tfr, fr2 = dl.score(tfr), 1e-5));
        } finally {
            if (tfr != null)
                tfr.remove();
            if (dl != null)
                dl.delete();
            if (fr2 != null)
                fr2.delete();
            Scope.exit();
        }
    }
}
Also used : Frame(water.fvec.Frame) DistributionFamily(hex.genmodel.utils.DistributionFamily) DeepLearningParameters(hex.deeplearning.DeepLearningModel.DeepLearningParameters) Test(org.junit.Test)

Example 27 with DeepLearningParameters

use of hex.deeplearning.DeepLearningModel.DeepLearningParameters in project h2o-3 by h2oai.

the class DeepLearningTest method testCategoricalEncodingEigenCV.

@Test
public void testCategoricalEncodingEigenCV() {
    Frame tfr = null;
    DeepLearningModel dl = null;
    try {
        String response = "survived";
        tfr = parse_test_file("./smalldata/junit/titanic_alt.csv");
        if (tfr.vec(response).isBinary()) {
            Vec v = tfr.remove(response);
            tfr.add(response, v.toCategoricalVec());
            v.remove();
        }
        DKV.put(tfr);
        DeepLearningParameters parms = new DeepLearningParameters();
        parms._train = tfr._key;
        parms._valid = tfr._key;
        parms._response_column = response;
        parms._reproducible = true;
        parms._hidden = new int[] { 20, 20 };
        parms._seed = 0xdecaf;
        parms._nfolds = 3;
        parms._categorical_encoding = Model.Parameters.CategoricalEncodingScheme.Eigen;
        parms._score_training_samples = 0;
        dl = new DeepLearning(parms).trainModel().get();
        Assert.assertEquals(0.9521718170580964, ((ModelMetricsBinomial) dl._output._training_metrics)._auc._auc, 1e-4);
        Assert.assertEquals(0.9521656365883807, ((ModelMetricsBinomial) dl._output._validation_metrics)._auc._auc, 1e-4);
        Assert.assertEquals(0.9115080346106303, ((ModelMetricsBinomial) dl._output._cross_validation_metrics)._auc._auc, 1e-4);
        Assert.assertEquals(0.913637, Double.parseDouble((String) (dl._output._cross_validation_metrics_summary).get(1, 0)), 1e-4);
    } finally {
        if (tfr != null)
            tfr.remove();
        if (dl != null)
            dl.deleteCrossValidationModels();
        if (dl != null)
            dl.delete();
    }
}
Also used : Frame(water.fvec.Frame) NFSFileVec(water.fvec.NFSFileVec) Vec(water.fvec.Vec) DeepLearningParameters(hex.deeplearning.DeepLearningModel.DeepLearningParameters) Test(org.junit.Test)

Example 28 with DeepLearningParameters

use of hex.deeplearning.DeepLearningModel.DeepLearningParameters in project h2o-3 by h2oai.

the class DeepLearningTest method testNoRowWeightsShuffled.

@Test
public void testNoRowWeightsShuffled() {
    Frame tfr = null, vfr = null, pred = null, fr2 = null;
    Scope.enter();
    try {
        tfr = parse_test_file("smalldata/junit/no_weights_shuffled.csv");
        DKV.put(tfr);
        DeepLearningParameters parms = new DeepLearningParameters();
        parms._train = tfr._key;
        parms._response_column = "response";
        parms._reproducible = true;
        parms._seed = 0xdecaf;
        parms._l1 = 0.1;
        parms._epochs = 1;
        parms._hidden = new int[] { 1 };
        parms._classification_stop = -1;
        // Build a first model; all remaining models should be equal
        DeepLearningModel dl = new DeepLearning(parms).trainModel().get();
        pred = dl.score(parms.train());
        hex.ModelMetricsBinomial mm = hex.ModelMetricsBinomial.getFromDKV(dl, parms.train());
        assertEquals(0.7222222222222222, mm.auc_obj()._auc, 1e-8);
        double mse = dl._output._training_metrics.mse();
        assertEquals(0.31643071339946, mse, 1e-8);
        assertTrue(dl.testJavaScoring(tfr, fr2 = dl.score(tfr), 1e-5));
        dl.delete();
    } finally {
        if (tfr != null)
            tfr.remove();
        if (vfr != null)
            vfr.remove();
        if (pred != null)
            pred.remove();
        if (fr2 != null)
            fr2.remove();
    }
    Scope.exit();
}
Also used : Frame(water.fvec.Frame) DeepLearningParameters(hex.deeplearning.DeepLearningModel.DeepLearningParameters) hex(hex) Test(org.junit.Test)

Example 29 with DeepLearningParameters

use of hex.deeplearning.DeepLearningModel.DeepLearningParameters in project h2o-3 by h2oai.

the class DeepLearningTest method testLaplace.

@Test
public void testLaplace() {
    Frame tfr = null;
    DeepLearningModel dl = null;
    try {
        tfr = parse_test_file("./smalldata/gbm_test/BostonHousing.csv");
        DeepLearningParameters parms = new DeepLearningParameters();
        parms._train = tfr._key;
        parms._response_column = tfr.lastVecName();
        parms._reproducible = true;
        parms._hidden = new int[] { 20, 20 };
        parms._seed = 0xdecaf;
        parms._distribution = laplace;
        dl = new DeepLearning(parms).trainModel().get();
        Assert.assertEquals(2.31398, /*MAE*/
        ((ModelMetricsRegression) dl._output._training_metrics)._mean_residual_deviance, 1e-5);
        Assert.assertEquals(14.889, ((ModelMetricsRegression) dl._output._training_metrics)._MSE, 1e-3);
    } finally {
        if (tfr != null)
            tfr.delete();
        if (dl != null)
            dl.deleteCrossValidationModels();
        if (dl != null)
            dl.delete();
    }
}
Also used : Frame(water.fvec.Frame) DeepLearningParameters(hex.deeplearning.DeepLearningModel.DeepLearningParameters) Test(org.junit.Test)

Example 30 with DeepLearningParameters

use of hex.deeplearning.DeepLearningModel.DeepLearningParameters in project h2o-3 by h2oai.

the class DeepLearningTest method testWhatever.

@Ignore
@Test
public void testWhatever() {
    DeepLearningParameters dl;
    Frame first1kSVM = null;
    Frame second1kSVM = null;
    Frame third1kSVM = null;
    Frame first1kCSV = null;
    Frame second1kCSV = null;
    Frame third1kCSV = null;
    DeepLearningModel model = null;
    dl = new DeepLearningParameters();
    Scope.enter();
    try {
        //      first1kSVM = parse_test_file("/users/arno/first1k.svm");
        //      Scope.track(first1kSVM.replace(0, first1kSVM.vec(0).toCategoricalVec())._key);
        //      DKV.put(first1kSVM);
        //
        //      second1kSVM = parse_test_file("/users/arno/second1k.svm");
        //      Scope.track(second1kSVM.replace(0, second1kSVM.vec(0).toCategoricalVec())._key);
        //      DKV.put(second1kSVM);
        //
        //      third1kSVM = parse_test_file("/users/arno/third1k.svm");
        //      Scope.track(third1kSVM.replace(third1kSVM.find("C1"), third1kSVM.vec("C1")).toCategoricalVec()._key);
        //      DKV.put(third1kSVM);
        first1kCSV = parse_test_file("/users/arno/first1k.csv");
        //      first1kCSV.remove(first1kCSV.find("C1")).remove(); //remove id
        //remove response, but keep it around outside the frame
        Vec response = first1kCSV.remove(first1kCSV.find("C2"));
        //turn response into a categorical
        Vec responseFactor = response.toCategoricalVec();
        response.remove();
        //      first1kCSV.prepend("C2", first1kCSV.anyVec().makeCon(0)); //add a dummy column (will be the first predictor)
        //add back response as first column
        first1kCSV.prepend("C2", responseFactor);
        DKV.put(first1kCSV);
        //      second1kCSV = parse_test_file("/users/arno/second1k.csv");
        //      second1kCSV.remove(second1kCSV.find("C1")).remove(); //remove id
        //      response = second1kCSV.remove(second1kCSV.find("C2")); //remove response, but keep it around outside the frame
        //      responseFactor = response.toCategoricalVec(); //turn response into a categorical
        //      response.remove();
        //      second1kCSV.prepend("C2", second1kCSV.anyVec().makeCon(0)); //add a dummy column (will be the first predictor)
        //      second1kCSV.prepend("C1", responseFactor); //add back response as first column
        //      DKV.put(second1kCSV);
        //
        //      third1kCSV = parse_test_file("/users/arno/third1k.csv");
        //      third1kCSV.remove(third1kCSV.find("C1")).remove(); //remove id
        //      response = third1kCSV.remove(third1kCSV.find("C2")); //remove response, but keep it around outside the frame
        //      responseFactor = response.toCategoricalVec(); //turn response into a categorical
        //      response.remove();
        //      third1kCSV.prepend("C2", third1kCSV.anyVec().makeCon(0)); //add a dummy column (will be the first predictor)
        //      third1kCSV.prepend("C1", responseFactor); //add back response as first column
        //      DKV.put(third1kCSV);
        //print non-zeros for each frame
        //      Log.info("SVMLight First 1k non-trivial rows");
        //      new PrintEntries().doAll(trainSVM);
        //      Log.info("DenseCSV First 1k non-trivial rows");
        //      new PrintEntries().doAll(trainCSV);
        //      Log.info("SVMLight Second 1k non-trivial rows");
        //      new PrintEntries().doAll(trainSVM);
        //      Log.info("DenseCSV Second 1k non-trivial rows");
        //      new PrintEntries().doAll(testCSV);
        // Configure DL
        dl._train = first1kCSV._key;
        //      dl._valid = second1kSVM._key;
        dl._ignored_columns = new String[] { "C1" };
        dl._response_column = "C2";
        //default
        dl._epochs = 10;
        //default
        dl._reproducible = true;
        dl._seed = 1234;
        //default
        dl._ignore_const_cols = false;
        //non-default, much faster here for sparse data
        dl._sparse = true;
        dl._hidden = new int[] { 10, 10 };
        // Invoke DL and block till the end
        DeepLearning job = new DeepLearning(dl);
        // Get the model
        model = job.trainModel().get();
        Log.info(model._output);
        //        Log.info("Holdout CSV");
        //        model.score(third1kCSV).delete();
        //
        //        Log.info("Holdout SVM");
        //        model.score(third1kSVM).delete();
        //
        //        Log.info("POJO SVM Train Check");
        Frame pred;
        //        assertTrue(model.testJavaScoring(first1kSVM, pred = model.score(first1kSVM), 1e-5));
        //        pred.remove();
        //
        //        Log.info("POJO SVM Validation Check");
        //        DKV.remove(model._key); model._key = Key.make(); DKV.put(model);
        //        assertTrue(model.testJavaScoring(second1kSVM,  pred = model.score(second1kSVM), 1e-5));
        //        pred.remove();
        //
        //        Log.info("POJO SVM Test Check");
        //        DKV.remove(model._key); model._key = Key.make(); DKV.put(model);
        //        assertTrue(model.testJavaScoring(third1kSVM,  pred = model.score(third1kSVM), 1e-5));
        //        pred.remove();
        Log.info("POJO CSV Train Check");
        DKV.remove(model._key);
        model._key = Key.make();
        DKV.put(model);
        assertTrue(model.testJavaScoring(first1kCSV, pred = model.score(first1kCSV), 1e-5));
        pred.remove();
        //        Log.info("POJO CSV Validation Check");
        //        DKV.remove(model._key); model._key = Key.make(); DKV.put(model);
        //        assertTrue(model.testJavaScoring(second1kCSV,  pred = model.score(second1kCSV), 1e-5));
        //        pred.remove();
        //
        //        Log.info("POJO CSV Test Check");
        //        DKV.remove(model._key); model._key = Key.make(); DKV.put(model);
        //        assertTrue(model.testJavaScoring(third1kCSV, pred = model.score(third1kSVM), 1e-5));
        //        pred.remove();
        //
        //        Log.info("POJO SVM vs H2O CSV Test Check");
        //        DKV.remove(model._key); model._key = Key.make(); DKV.put(model);
        //        assertTrue(model.testJavaScoring(third1kSVM, pred = model.score(third1kCSV), 1e-5));
        //        pred.remove();
        //
        //        Log.info("POJO CSV vs H2O SVM Test Check");
        //        DKV.remove(model._key); model._key = Key.make(); DKV.put(model);
        //        assertTrue(model.testJavaScoring(third1kSVM, pred = model.score(third1kCSV), 1e-5));
        //        pred.remove();
        //HEX-1817
        assertTrue(job.isStopped());
    } finally {
        if (first1kSVM != null)
            first1kSVM.remove();
        if (second1kSVM != null)
            second1kSVM.remove();
        if (third1kSVM != null)
            third1kSVM.remove();
        if (first1kCSV != null)
            first1kCSV.remove();
        if (second1kCSV != null)
            second1kCSV.remove();
        if (third1kCSV != null)
            third1kCSV.remove();
        if (model != null)
            model.delete();
        Scope.exit();
    }
}
Also used : Frame(water.fvec.Frame) NFSFileVec(water.fvec.NFSFileVec) Vec(water.fvec.Vec) DeepLearningParameters(hex.deeplearning.DeepLearningModel.DeepLearningParameters) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

DeepLearningParameters (hex.deeplearning.DeepLearningModel.DeepLearningParameters)58 Frame (water.fvec.Frame)54 Test (org.junit.Test)52 NFSFileVec (water.fvec.NFSFileVec)26 Vec (water.fvec.Vec)22 hex (hex)5 Ignore (org.junit.Ignore)5 DistributionFamily (hex.genmodel.utils.DistributionFamily)4 Random (java.util.Random)4 H2OIllegalArgumentException (water.exceptions.H2OIllegalArgumentException)3 DataInfo (hex.DataInfo)2 File (java.io.File)2 Key (water.Key)2 H2OModelBuilderIllegalArgumentException (water.exceptions.H2OModelBuilderIllegalArgumentException)2 PrettyPrint (water.util.PrettyPrint)2 ConfusionMatrix (hex.ConfusionMatrix)1 Distribution (hex.Distribution)1 FrameSplitter (hex.FrameSplitter)1 FrameTask (hex.FrameTask)1 ModelMetricsBinomial (hex.ModelMetricsBinomial)1