Search in sources :

Example 1 with ConfusionMatrix

use of water.api.ConfusionMatrix in project h2o-2 by h2oai.

the class GBMTest method testGBMTrainTest.

// Test-on-Train.  Slow test, needed to build a good model.
@Test
public void testGBMTrainTest() {
    File file1 = TestUtil.find_test_file("smalldata/gbm_test/ecology_model.csv");
    // Silently ignore if file not found
    if (file1 == null)
        return;
    Key fkey1 = NFSFileVec.make(file1);
    Key dest1 = Key.make("train.hex");
    File file2 = TestUtil.find_test_file("smalldata/gbm_test/ecology_eval.csv");
    Key fkey2 = NFSFileVec.make(file2);
    Key dest2 = Key.make("test.hex");
    // The Builder
    GBM gbm = new GBM();
    // The Model
    GBM.GBMModel gbmmodel = null;
    Frame ftest = null, fpreds = null;
    try {
        Frame fr = ParseDataset2.parse(dest1, new Key[] { fkey1 });
        // Remove unique ID; too predictive
        UKV.remove(fr.remove("Site")._key);
        // Train on the outcome
        gbm.response = fr.vecs()[fr.find("Angaus")];
        gbm.source = fr;
        gbm.ntrees = 5;
        gbm.max_depth = 10;
        gbm.learn_rate = 0.2f;
        gbm.min_rows = 10;
        gbm.nbins = 100;
        gbm.invoke();
        gbmmodel = UKV.get(gbm.dest());
        testHTML(gbmmodel);
        //HEX-1817
        Assert.assertTrue(gbmmodel.get_params().state == Job.JobState.DONE);
        // Test on the train data
        ftest = ParseDataset2.parse(dest2, new Key[] { fkey2 });
        fpreds = gbm.score(ftest);
        // Build a confusion matrix
        ConfusionMatrix CM = new ConfusionMatrix();
        CM.actual = ftest;
        CM.vactual = ftest.vecs()[ftest.find("Angaus")];
        CM.predict = fpreds;
        CM.vpredict = fpreds.vecs()[fpreds.find("predict")];
        // Start it, do it
        CM.invoke();
        StringBuilder sb = new StringBuilder();
        CM.toASCII(sb);
        System.out.println(sb);
    } finally {
        // Remove the original hex frame key
        gbm.source.delete();
        if (ftest != null)
            ftest.delete();
        if (fpreds != null)
            fpreds.delete();
        // Remove the model
        if (gbmmodel != null)
            gbmmodel.delete();
        UKV.remove(gbm.response._key);
        // Remove GBM Job
        gbm.remove();
    }
}
Also used : GBMModel(hex.gbm.GBM.GBMModel) ConfusionMatrix(water.api.ConfusionMatrix) File(java.io.File) Test(org.junit.Test)

Aggregations

GBMModel (hex.gbm.GBM.GBMModel)1 File (java.io.File)1 Test (org.junit.Test)1 ConfusionMatrix (water.api.ConfusionMatrix)1