Search in sources :

Example 1 with CreateFrame

use of hex.CreateFrame in project h2o-3 by h2oai.

the class AggregatorTest method testAggregatorOneHot.

@Test
public void testAggregatorOneHot() {
    Scope.enter();
    CreateFrame cf = new CreateFrame();
    cf.rows = 1000;
    cf.cols = 10;
    cf.categorical_fraction = 0.6;
    cf.integer_fraction = 0.0;
    cf.binary_fraction = 0.0;
    cf.real_range = 100;
    cf.integer_range = 100;
    cf.missing_fraction = 0.1;
    cf.factors = 5;
    cf.seed = 1234;
    Frame frame = cf.execImpl().get();
    AggregatorModel.AggregatorParameters parms = new AggregatorModel.AggregatorParameters();
    parms._train = frame._key;
    parms._target_num_exemplars = 278;
    parms._transform = DataInfo.TransformType.NORMALIZE;
    parms._categorical_encoding = Model.Parameters.CategoricalEncodingScheme.OneHotExplicit;
    long start = System.currentTimeMillis();
    // 0.905
    AggregatorModel agg = new Aggregator(parms).trainModel().get();
    System.out.println("AggregatorModel finished in: " + (System.currentTimeMillis() - start) / 1000. + " seconds");
    agg.checkConsistency();
    Frame output = agg._output._output_frame.get();
    System.out.println(output.toTwoDimTable(0, 10));
    checkNumExemplars(agg);
    output.remove();
    frame.remove();
    agg.remove();
    Scope.exit();
}
Also used : CreateFrame(hex.CreateFrame) Frame(water.fvec.Frame) Aggregator(hex.aggregator.Aggregator) CreateFrame(hex.CreateFrame) AggregatorModel(hex.aggregator.AggregatorModel) Test(org.junit.Test)

Example 2 with CreateFrame

use of hex.CreateFrame in project h2o-3 by h2oai.

the class AggregatorTest method testAggregatorBinary.

@Test
public void testAggregatorBinary() {
    CreateFrame cf = new CreateFrame();
    cf.rows = 1000;
    cf.cols = 10;
    cf.categorical_fraction = 0.6;
    cf.integer_fraction = 0.0;
    cf.binary_fraction = 0.0;
    cf.real_range = 100;
    cf.integer_range = 100;
    cf.missing_fraction = 0.1;
    cf.factors = 5;
    cf.seed = 1234;
    Frame frame = cf.execImpl().get();
    AggregatorModel.AggregatorParameters parms = new AggregatorModel.AggregatorParameters();
    parms._train = frame._key;
    parms._transform = DataInfo.TransformType.NORMALIZE;
    parms._categorical_encoding = Model.Parameters.CategoricalEncodingScheme.Binary;
    long start = System.currentTimeMillis();
    // 0.905
    AggregatorModel agg = new Aggregator(parms).trainModel().get();
    System.out.println("AggregatorModel finished in: " + (System.currentTimeMillis() - start) / 1000. + " seconds");
    agg.checkConsistency();
    Frame output = agg._output._output_frame.get();
    System.out.println(output.toTwoDimTable(0, 10));
    Log.info("Number of exemplars: " + agg._exemplars.length);
    Assert.assertTrue(agg._exemplars.length == 1000);
    output.remove();
    frame.remove();
    agg.remove();
}
Also used : CreateFrame(hex.CreateFrame) Frame(water.fvec.Frame) Aggregator(hex.aggregator.Aggregator) CreateFrame(hex.CreateFrame) AggregatorModel(hex.aggregator.AggregatorModel) Test(org.junit.Test)

Example 3 with CreateFrame

use of hex.CreateFrame in project h2o-3 by h2oai.

the class AggregatorTest method testAggregator.

public void testAggregator(int max) {
    CreateFrame cf = new CreateFrame();
    cf.rows = 100000;
    cf.cols = 2;
    cf.categorical_fraction = 0.1;
    cf.integer_fraction = 0.3;
    cf.real_range = 100;
    cf.integer_range = 100;
    cf.seed = 1234;
    Frame frame = cf.execImpl().get();
    AggregatorModel.AggregatorParameters parms = new AggregatorModel.AggregatorParameters();
    parms._train = frame._key;
    parms._target_num_exemplars = max;
    long start = System.currentTimeMillis();
    AggregatorModel agg = new Aggregator(parms).trainModel().get();
    System.out.println("AggregatorModel finished in: " + (System.currentTimeMillis() - start) / 1000. + " seconds");
    agg.checkConsistency();
    Frame output = agg._output._output_frame.get();
    System.out.println(output.toTwoDimTable(0, 10));
    frame.delete();
    checkNumExemplars(agg);
    output.remove();
    agg.remove();
}
Also used : CreateFrame(hex.CreateFrame) Frame(water.fvec.Frame) Aggregator(hex.aggregator.Aggregator) CreateFrame(hex.CreateFrame) AggregatorModel(hex.aggregator.AggregatorModel)

Example 4 with CreateFrame

use of hex.CreateFrame in project h2o-3 by h2oai.

the class FrameUtilsTest method testCategoricalColumnsBinaryEncoding.

@Test
public void testCategoricalColumnsBinaryEncoding() {
    int numNoncatColumns = 10;
    int[] catSizes = { 2, 3, 4, 5, 7, 8, 9, 15, 16, 30, 31, 127, 255, 256 };
    int[] expBinarySizes = { 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 7, 8, 9 };
    String[] catNames = { "duo", "Trinity", "Quart", "Star rating", "Dwarves", "Octopus legs", "Planets", "Game of Fifteen", "Halfbyte", "Days30", "Days31", "Periodic Table", "AlmostByte", "Byte" };
    Assert.assertEquals(catSizes.length, expBinarySizes.length);
    Assert.assertEquals(catSizes.length, catNames.length);
    int totalExpectedColumns = numNoncatColumns;
    for (int s : expBinarySizes) totalExpectedColumns += s;
    Key<Frame> frameKey = Key.make();
    CreateFrame cf = new CreateFrame(frameKey);
    cf.rows = 100;
    cf.cols = numNoncatColumns;
    cf.categorical_fraction = 0.0;
    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 = 100;
            ccf.cols = 1;
            ccf.categorical_fraction = 1;
            ccf.integer_fraction = 0;
            ccf.binary_fraction = 0;
            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]);
        }
        FrameUtils.CategoricalBinaryEncoder cbed = new FrameUtils.CategoricalBinaryEncoder(mainFrame, null);
        transformedFrame = cbed.exec().get();
        assert transformedFrame != null : "Unable to transform a frame";
        Assert.assertEquals("Wrong number of columns after converting to binary 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 = 0, colOffset = numNoncatColumns; i < catSizes.length; colOffset += expBinarySizes[i++]) {
            for (int j = 0; j < expBinarySizes[i]; ++j) {
                int jj = colOffset + j;
                Assert.assertTrue("A categorical column should be transformed into several binary ones (col " + jj + ")", transformedFrame.vec(jj).isBinary());
                Assert.assertThat("Transformed categorical column should carry the name of the original column", transformedFrame.name(jj), CoreMatchers.startsWith(mainFrame.name(numNoncatColumns + i) + ":"));
            }
        }
    } 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) CreateFrame(hex.CreateFrame) CreateFrame(hex.CreateFrame) Test(org.junit.Test)

Example 5 with CreateFrame

use of hex.CreateFrame in project h2o-3 by h2oai.

the class InteractionWrappedVecTest method makeFrame.

Frame makeFrame(long rows) {
    CreateFrame cf = new CreateFrame();
    cf.rows = rows;
    cf.cols = 10;
    cf.categorical_fraction = 0.7;
    cf.integer_fraction = 0.1;
    cf.missing_fraction = 0.1;
    cf.binary_fraction = 0.1;
    cf.factors = 5;
    cf.response_factors = 2;
    cf.positive_response = false;
    cf.has_response = false;
    cf.seed = 1234;
    return cf.execImpl().get();
}
Also used : CreateFrame(hex.CreateFrame)

Aggregations

CreateFrame (hex.CreateFrame)10 Test (org.junit.Test)6 Frame (water.fvec.Frame)5 Aggregator (hex.aggregator.Aggregator)4 AggregatorModel (hex.aggregator.AggregatorModel)4 BeforeClass (org.junit.BeforeClass)1 Ignore (org.junit.Ignore)1 JobV3 (water.api.schemas3.JobV3)1 KeyV3 (water.api.schemas3.KeyV3)1 TwoDimTableV3 (water.api.schemas3.TwoDimTableV3)1