Search in sources :

Example 1 with DRFModel

use of hex.drf.DRF.DRFModel in project h2o-2 by h2oai.

the class DRFCheckpointTest method testCheckPointReconstruction.

private void testCheckPointReconstruction(String dataset, int response, boolean classification, int ntreesInPriorModel, int ntreesInANewModel) {
    Frame f = parseFrame(dataset);
    DRFModel model = null;
    DRFModel modelFromCheckpoint = null;
    DRFModel modelFinal = null;
    try {
        Vec respVec = f.vec(response);
        // Build a model
        DRFWithHooks drf = new DRFWithHooks();
        drf.source = f;
        drf.response = respVec;
        drf.classification = classification;
        drf.ntrees = ntreesInPriorModel;
        drf.collectPoint = WhereToCollect.AFTER_BUILD;
        drf.seed = 42;
        drf.invoke();
        model = UKV.get(drf.dest());
        DRFWithHooks drfFromCheckpoint = new DRFWithHooks();
        drfFromCheckpoint.source = f;
        drfFromCheckpoint.response = respVec;
        drfFromCheckpoint.classification = classification;
        drfFromCheckpoint.ntrees = ntreesInANewModel;
        drfFromCheckpoint.collectPoint = WhereToCollect.AFTER_RECONSTRUCTION;
        drfFromCheckpoint.checkpoint = drf.dest();
        drfFromCheckpoint.seed = 42;
        drfFromCheckpoint.invoke();
        modelFromCheckpoint = UKV.get(drf.dest());
        //System.err.println(Arrays.toString(modelFromCheckpoint.errs));
        Assert.assertArrayEquals("Tree data produced by drf run and reconstructed from a model do not match!", drf.treesCols, drfFromCheckpoint.treesCols);
        DRF drfFinal = new DRF();
        drfFinal.source = f;
        drfFinal.response = respVec;
        drfFinal.classification = classification;
        drfFinal.ntrees = ntreesInANewModel + ntreesInPriorModel;
        drfFinal.score_each_iteration = true;
        drfFinal.seed = 42;
        drfFinal.invoke();
        modelFinal = UKV.get(drfFinal.dest());
        //System.err.println(Arrays.toString(modelFinal.errs));
        // Compare resulting model with the model produced from checkpoint
        assertTreeModelEquals(modelFinal, modelFromCheckpoint);
    } finally {
        if (f != null)
            f.delete();
        if (model != null)
            model.delete();
        if (modelFromCheckpoint != null)
            modelFromCheckpoint.delete();
        if (modelFinal != null)
            modelFinal.delete();
    }
}
Also used : Frame(water.fvec.Frame) DRFModel(hex.drf.DRF.DRFModel) Vec(water.fvec.Vec)

Example 2 with DRFModel

use of hex.drf.DRF.DRFModel in project h2o-2 by h2oai.

the class DRFTest method basicDRF.

public void basicDRF(String fnametrain, String hexnametrain, String fnametest, String hexnametest, PrepData prep, int ntree, long[][] expCM, String[] expRespDom, int max_depth, int nbins, int optflags) throws Throwable {
    DRF drf = new DRF();
    Key destTrain = Key.make(hexnametrain);
    Key destTest = hexnametest != null ? Key.make(hexnametest) : null;
    Frame frTest = null, pred = null;
    DRFModel model = null;
    try {
        Frame frTrain = drf.source = parseFrame(destTrain, fnametrain);
        unifyFrame(drf, frTrain, prep);
        // Configure DRF
        drf.classification = true;
        drf.ntrees = ntree;
        drf.max_depth = max_depth;
        // = nodesize
        drf.min_rows = 1;
        drf.nbins = nbins;
        drf.mtries = -1;
        // Simulated sampling with replacement
        drf.sample_rate = 0.66667f;
        drf.seed = (1L << 32) | 2;
        drf.destination_key = Key.make("DRF_model_4_" + hexnametrain);
        // Invoke DRF and block till the end
        drf.invoke();
        // Get the model
        model = UKV.get(drf.dest());
        //HEX-1817
        Assert.assertTrue(model.get_params().state == Job.JobState.DONE);
        testHTML(model);
        // And compare CMs
        assertCM(expCM, model.cms[model.cms.length - 1]._arr);
        Assert.assertEquals("Number of trees differs!", ntree, model.errs.length - 1);
        String[] cmDom = model._domains[model._domains.length - 1];
        Assert.assertArrayEquals("CM domain differs!", expRespDom, cmDom);
        frTest = fnametest != null ? parseFrame(destTest, fnametest) : null;
        pred = drf.score(frTest != null ? frTest : drf.source);
    } finally {
        drf.source.delete();
        UKV.remove(drf.response._key);
        drf.remove();
        if (frTest != null)
            frTest.delete();
        // Remove the model
        if (model != null)
            model.delete();
        if (pred != null)
            pred.delete();
    }
}
Also used : Frame(water.fvec.Frame) DRFModel(hex.drf.DRF.DRFModel)

Example 3 with DRFModel

use of hex.drf.DRF.DRFModel in project h2o-2 by h2oai.

the class ModelSerializationTest method testDRFModelBinomial.

@Test
public void testDRFModelBinomial() throws IOException {
    DRFModel model = null, loadedModel = null;
    try {
        model = prepareDRFModel("smalldata/logreg/prostate.csv", ari(0), 1, true, 5);
        loadedModel = saveAndLoad(model);
        // And compare
        assertTreeModelEquals(model, loadedModel);
        assertModelBinaryEquals(model, loadedModel);
    } finally {
        if (model != null)
            model.delete();
        if (loadedModel != null)
            loadedModel.delete();
    }
}
Also used : DRFModel(hex.drf.DRF.DRFModel) Test(org.junit.Test)

Example 4 with DRFModel

use of hex.drf.DRF.DRFModel in project h2o-2 by h2oai.

the class DRFProgressPage method toHTML.

@Override
public boolean toHTML(StringBuilder sb) {
    Job jjob = Job.findJob(job_key);
    if (jjob == null)
        return true;
    DRFModel m = UKV.get(jjob.dest());
    if (m != null)
        m.generateHTML("DRF Model", sb);
    else
        DocGen.HTML.paragraph(sb, "Pending...");
    return true;
}
Also used : DRFModel(hex.drf.DRF.DRFModel) Job(water.Job)

Example 5 with DRFModel

use of hex.drf.DRF.DRFModel in project h2o-2 by h2oai.

the class DHistTest method testDBinom.

@Test
public void testDBinom() {
    DRF drf = new DRF();
    Key destTrain = Key.make("data.hex");
    DRFModel model = null;
    try {
        // Configure DRF
        drf.source = parseFrame(destTrain, "../smalldata/histogram_test/alphabet_cattest.csv");
        drf.response = drf.source.vecs()[1];
        drf.classification = true;
        drf.ntrees = 100;
        // = interaction.depth
        drf.max_depth = 5;
        // = nodesize
        drf.min_rows = 10;
        drf.nbins = 100;
        drf.destination_key = Key.make("DRF_model_dhist.hex");
        // Invoke DRF and block till the end
        drf.invoke();
        // Get the model
        model = UKV.get(drf.dest());
    } finally {
        drf.source.delete();
        drf.remove();
        // Remove the model
        if (model != null)
            model.delete();
    }
}
Also used : DRFModel(hex.drf.DRF.DRFModel) DRF(hex.drf.DRF) Test(org.junit.Test)

Aggregations

DRFModel (hex.drf.DRF.DRFModel)9 Frame (water.fvec.Frame)5 Test (org.junit.Test)3 Vec (water.fvec.Vec)3 DRF (hex.drf.DRF)1 Job (water.Job)1 RebalanceDataSet (water.fvec.RebalanceDataSet)1