Search in sources :

Example 11 with DeepLearningParameters

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

the class DeepLearningTest method testRowWeights.

@Test
public void testRowWeights() {
    Frame tfr = null, pred = null;
    Scope.enter();
    try {
        tfr = parse_test_file("smalldata/junit/weights.csv");
        DKV.put(tfr);
        DeepLearningParameters parms = new DeepLearningParameters();
        parms._train = tfr._key;
        parms._response_column = "response";
        parms._weights_column = "weight";
        parms._reproducible = true;
        parms._seed = 0xdecaf;
        parms._classification_stop = -1;
        parms._l1 = 0.1;
        parms._hidden = new int[] { 1 };
        parms._epochs = 10;
        // 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.7592592592592592, mm.auc_obj()._auc, 1e-8);
        double mse = dl._output._training_metrics.mse();
        assertEquals(0.3116490253190556, mse, 1e-8);
        //      Assert.assertTrue(dl.testJavaScoring(tfr,fr2=dl.score(tfr),1e-5)); //PUBDEV-1900
        dl.delete();
    } finally {
        if (tfr != null)
            tfr.remove();
        if (pred != null)
            pred.remove();
    }
    Scope.exit();
}
Also used : Frame(water.fvec.Frame) DeepLearningParameters(hex.deeplearning.DeepLearningModel.DeepLearningParameters) hex(hex) Test(org.junit.Test)

Example 12 with DeepLearningParameters

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

the class DeepLearningTest method testMultinomialMNIST.

@Ignore
@Test
public void testMultinomialMNIST() {
    Frame train = null;
    Frame preds = null;
    Frame small = null, large = null;
    DeepLearningModel model = null;
    Scope.enter();
    try {
        File file = FileUtils.locateFile("bigdata/laptop/mnist/train.csv.gz");
        if (file != null) {
            NFSFileVec trainfv = NFSFileVec.make(file);
            train = ParseDataset.parse(Key.make(), trainfv._key);
            int ci = train.find("C785");
            Scope.track(train.replace(ci, train.vecs()[ci].toCategoricalVec()));
            DKV.put(train);
            DeepLearningParameters p = new DeepLearningParameters();
            p._train = train._key;
            // last column is the response
            p._response_column = "C785";
            p._activation = DeepLearningParameters.Activation.RectifierWithDropout;
            p._hidden = new int[] { 50, 50 };
            p._epochs = 1;
            p._adaptive_rate = false;
            p._rate = 0.005;
            p._sparse = true;
            model = new DeepLearning(p).trainModel().get();
            FrameSplitter fs = new FrameSplitter(train, new double[] { 0.0001 }, new Key[] { Key.make("small"), Key.make("large") }, null);
            fs.compute2();
            small = fs.getResult()[0];
            large = fs.getResult()[1];
            preds = model.score(small);
            //remove label, keep only probs
            preds.remove(0);
            //actual
            Vec labels = small.vec("C785");
            //actual
            String[] fullDomain = train.vec("C785").domain();
            ModelMetricsMultinomial mm = ModelMetricsMultinomial.make(preds, labels, fullDomain);
            Log.info(mm.toString());
        }
    } catch (Throwable t) {
        t.printStackTrace();
        throw t;
    } finally {
        if (model != null)
            model.delete();
        if (preds != null)
            preds.remove();
        if (train != null)
            train.remove();
        if (small != null)
            small.delete();
        if (large != null)
            large.delete();
        Scope.exit();
    }
}
Also used : Frame(water.fvec.Frame) NFSFileVec(water.fvec.NFSFileVec) DeepLearningParameters(hex.deeplearning.DeepLearningModel.DeepLearningParameters) NFSFileVec(water.fvec.NFSFileVec) Vec(water.fvec.Vec) File(java.io.File) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 13 with DeepLearningParameters

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

the class DeepLearningTest method testNumericalExplosion.

@Test
public void testNumericalExplosion() {
    for (boolean ae : new boolean[] { true, false }) {
        Frame tfr = null;
        DeepLearningModel dl = null;
        Frame pred = null;
        try {
            tfr = parse_test_file("./smalldata/junit/two_spiral.csv");
            for (String s : new String[] { "Class" }) {
                Vec resp = tfr.vec(s).toCategoricalVec();
                tfr.remove(s).remove();
                tfr.add(s, resp);
                DKV.put(tfr);
            }
            DeepLearningParameters parms = new DeepLearningParameters();
            parms._train = tfr._key;
            parms._epochs = 100;
            parms._response_column = "Class";
            parms._autoencoder = ae;
            parms._reproducible = true;
            parms._train_samples_per_iteration = 10;
            parms._hidden = new int[] { 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 };
            parms._initial_weight_distribution = DeepLearningParameters.InitialWeightDistribution.Uniform;
            parms._initial_weight_scale = 1e20;
            parms._seed = 0xdecaf;
            parms._max_w2 = 1e20f;
            // Build a first model; all remaining models should be equal
            DeepLearning job = new DeepLearning(parms);
            try {
                dl = job.trainModel().get();
                Assert.fail("Should toss exception instead of reaching here");
            } catch (RuntimeException de) {
            // catch anything - might be a NPE during cleanup
            //          assertTrue(de.getMessage().contains("Trying to predict with an unstable model."));
            }
            dl = DKV.getGet(job.dest());
            try {
                pred = dl.score(tfr);
                Assert.fail("Should toss exception instead of reaching here");
            } catch (RuntimeException ex) {
            // OK
            }
            assertTrue(dl.model_info().isUnstable());
            assertTrue(dl._output._job.isCrashed());
        } finally {
            if (tfr != null)
                tfr.delete();
            if (dl != null)
                dl.delete();
            if (pred != null)
                pred.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 14 with DeepLearningParameters

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

the class DeepLearningTest method testEigenEncodingLogic.

// NOTE: This test has nothing to do with Deep Learning, except that it uses the Deep Learning infrastructure to get access to the EigenVec computation logic
@Test
public void testEigenEncodingLogic() {
    int numNoncatColumns = 1;
    int[] catSizes = { 16 };
    String[] catNames = { "sixteen" };
    Assert.assertEquals(catSizes.length, catNames.length);
    int totalExpectedColumns = numNoncatColumns + catSizes.length;
    //to test reproducibility
    double[] expectedMean = { 0.0453 };
    Key<Frame> frameKey = Key.make();
    CreateFrame cf = new CreateFrame(frameKey);
    cf.rows = 100000;
    cf.cols = numNoncatColumns;
    cf.categorical_fraction = 0.0;
    cf.seed = 1234;
    cf.integer_fraction = 0.3;
    cf.binary_fraction = 0.1;
    cf.time_fraction = 0.2;
    cf.string_fraction = 0.1;
    Frame mainFrame = cf.execImpl().get();
    assert mainFrame != null : "Unable to create a frame";
    Frame[] auxFrames = new Frame[catSizes.length];
    Frame transformedFrame = null;
    try {
        for (int i = 0; i < catSizes.length; ++i) {
            CreateFrame ccf = new CreateFrame();
            ccf.rows = 100000;
            ccf.cols = 1;
            ccf.categorical_fraction = 1;
            ccf.integer_fraction = 0;
            ccf.binary_fraction = 0;
            ccf.seed = 1234;
            ccf.time_fraction = 0;
            ccf.string_fraction = 0;
            ccf.factors = catSizes[i];
            auxFrames[i] = ccf.execImpl().get();
            auxFrames[i]._names[0] = catNames[i];
            mainFrame.add(auxFrames[i]);
        }
        Log.info(mainFrame, 0, 100);
        FrameUtils.CategoricalEigenEncoder cbed = new FrameUtils.CategoricalEigenEncoder(new DeepLearning(new DeepLearningParameters()).getToEigenVec(), mainFrame, null);
        transformedFrame = cbed.exec().get();
        assert transformedFrame != null : "Unable to transform a frame";
        Assert.assertEquals("Wrong number of columns after converting to eigen encoding", totalExpectedColumns, transformedFrame.numCols());
        for (int i = 0; i < numNoncatColumns; ++i) {
            Assert.assertEquals(mainFrame.name(i), transformedFrame.name(i));
            Assert.assertEquals(mainFrame.types()[i], transformedFrame.types()[i]);
        }
        for (int i = numNoncatColumns; i < transformedFrame.numCols(); i++) {
            Assert.assertTrue("A categorical column should be transformed into one numeric one (col " + i + ")", transformedFrame.vec(i).isNumeric());
            Assert.assertEquals("Transformed categorical column should carry the name of the original column", transformedFrame.name(i), mainFrame.name(i) + ".Eigen");
            Assert.assertEquals("Transformed categorical column should have the correct mean value", expectedMean[i - numNoncatColumns], transformedFrame.vec(i).mean(), 5e-4);
        }
    } catch (Throwable e) {
        e.printStackTrace();
        throw e;
    } finally {
        mainFrame.delete();
        if (transformedFrame != null)
            transformedFrame.delete();
        for (Frame f : auxFrames) if (f != null)
            f.delete();
    }
}
Also used : Frame(water.fvec.Frame) DeepLearningParameters(hex.deeplearning.DeepLearningModel.DeepLearningParameters) Test(org.junit.Test)

Example 15 with DeepLearningParameters

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

the class DeepLearningTest method testConvergenceLogloss.

@Test
public void testConvergenceLogloss() {
    Frame tfr = null;
    DeepLearningModel dl = null;
    DeepLearningModel dl2 = null;
    try {
        tfr = parse_test_file("./smalldata/iris/iris.csv");
        DeepLearningParameters parms = new DeepLearningParameters();
        parms._train = tfr._key;
        parms._epochs = 1000000;
        parms._response_column = "C5";
        parms._reproducible = true;
        parms._hidden = new int[] { 2, 2 };
        parms._seed = 0xdecaf;
        parms._variable_importances = true;
        parms._score_duty_cycle = 0.1;
        parms._score_interval = 0;
        //don't stop based on absolute classification error
        parms._classification_stop = -1;
        //don't stop based on absolute classification error
        parms._stopping_rounds = 5;
        //don't stop based on absolute classification error
        parms._stopping_metric = ScoreKeeper.StoppingMetric.logloss;
        parms._stopping_tolerance = 0.03;
        dl = new DeepLearning(parms).trainModel().get();
        Assert.assertTrue(dl.epoch_counter < parms._epochs);
    } finally {
        if (tfr != null)
            tfr.delete();
        if (dl != null)
            dl.delete();
        if (dl2 != null)
            dl2.delete();
    }
}
Also used : Frame(water.fvec.Frame) DeepLearningParameters(hex.deeplearning.DeepLearningModel.DeepLearningParameters) 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