Search in sources :

Example 6 with GLRMParameters

use of hex.glrm.GLRMModel.GLRMParameters in project h2o-3 by h2oai.

the class GLRMTest method testMojo.

@Test
public void testMojo() throws InterruptedException, ExecutionException {
    GLRM glrm;
    GLRMModel model = null;
    Frame train = null;
    try {
        Scope.enter();
        train = parse_test_file(Key.<Frame>make("birds"), "./smalldata/pca_test/AustraliaCoast.csv");
        GLRMParameters parms = new GLRMParameters();
        parms._train = train._key;
        parms._k = 4;
        parms._loss = GlrmLoss.Quadratic;
        parms._init = GlrmInitialization.Random;
        parms._max_iterations = 2000;
        parms._regularization_x = GlrmRegularizer.Quadratic;
        parms._gamma_x = 0;
        parms._gamma_y = 0;
        glrm = new GLRM(parms);
        model = glrm.trainModel().get();
        assert model != null;
        checkLossbyCol(parms, model);
        boolean res = model.testJavaScoring(train, model._output._representation_key.get(), 1e-6, 1);
    // Disable for now
    // Assert.assertTrue(res);
    } finally {
        if (train != null)
            train.delete();
        if (model != null)
            model.delete();
    }
}
Also used : Frame(water.fvec.Frame) GLRMParameters(hex.glrm.GLRMModel.GLRMParameters) Test(org.junit.Test)

Example 7 with GLRMParameters

use of hex.glrm.GLRMModel.GLRMParameters in project h2o-3 by h2oai.

the class GLRMTest method testSetColumnLoss.

@Test
public void testSetColumnLoss() throws InterruptedException, ExecutionException {
    GLRM job = null;
    GLRMModel model = null;
    Frame train = null;
    try {
        train = parse_test_file(Key.make("benign.hex"), "smalldata/logreg/benign.csv");
        GLRMParameters parms = new GLRMParameters();
        parms._train = train._key;
        parms._k = 12;
        parms._loss = GlrmLoss.Quadratic;
        parms._loss_by_col = new GlrmLoss[] { GlrmLoss.Absolute, GlrmLoss.Huber };
        parms._loss_by_col_idx = new int[] { 2, /* AGMT */
        5 };
        parms._transform = DataInfo.TransformType.STANDARDIZE;
        parms._init = GlrmInitialization.PlusPlus;
        parms._min_step_size = 1e-5;
        parms._recover_svd = false;
        parms._max_iterations = 2000;
        job = new GLRM(parms);
        model = job.trainModel().get();
        Log.info("Iteration " + model._output._iterations + ": Objective value = " + model._output._objective);
        checkLossbyCol(parms, model);
        model.score(train).delete();
        ModelMetricsGLRM mm = (ModelMetricsGLRM) ModelMetrics.getFromDKV(model, train);
        Log.info("Numeric Sum of Squared Error = " + mm._numerr + "\tCategorical Misclassification Error = " + mm._caterr);
    } finally {
        if (train != null)
            train.delete();
        if (model != null)
            model.delete();
    }
}
Also used : Frame(water.fvec.Frame) GLRMParameters(hex.glrm.GLRMModel.GLRMParameters) Test(org.junit.Test)

Example 8 with GLRMParameters

use of hex.glrm.GLRMModel.GLRMParameters in project h2o-3 by h2oai.

the class GLRMCategoricalTest method testSetColumnLossCats.

@Test
public void testSetColumnLossCats() throws InterruptedException, ExecutionException {
    GLRMModel model = null;
    Frame train = null;
    // Categoricals: CAPSULE, RACE, DPROS, DCAPS
    final int[] cats = new int[] { 1, 3, 4, 5 };
    Scope.enter();
    try {
        train = parse_test_file(Key.make("prostate.hex"), "smalldata/logreg/prostate.csv");
        for (int i = 0; i < cats.length; i++) Scope.track(train.replace(cats[i], train.vec(cats[i]).toCategoricalVec()));
        train.remove("ID").remove();
        DKV.put(train._key, train);
        GLRMParameters parms = new GLRMParameters();
        parms._train = train._key;
        parms._k = 12;
        parms._loss = GlrmLoss.Quadratic;
        parms._multi_loss = GlrmLoss.Categorical;
        parms._loss_by_col = new GlrmLoss[] { GlrmLoss.Ordinal, GlrmLoss.Poisson, GlrmLoss.Absolute };
        parms._loss_by_col_idx = new int[] { 3, /* DPROS */
        1, /* AGE */
        6 };
        parms._init = GlrmInitialization.PlusPlus;
        parms._min_step_size = 1e-5;
        parms._recover_svd = false;
        parms._max_iterations = 2000;
        model = new GLRM(parms).trainModel().get();
        Log.info("Iteration " + model._output._iterations + ": Objective value = " + model._output._objective);
        GLRMTest.checkLossbyCol(parms, model);
        model.score(train).delete();
        ModelMetricsGLRM mm = (ModelMetricsGLRM) ModelMetrics.getFromDKV(model, train);
        Log.info("Numeric Sum of Squared Error = " + mm._numerr + "\tCategorical Misclassification Error = " + mm._caterr);
    } finally {
        if (train != null)
            train.delete();
        if (model != null)
            model.delete();
        Scope.exit();
    }
}
Also used : Frame(water.fvec.Frame) GLRMParameters(hex.glrm.GLRMModel.GLRMParameters) Test(org.junit.Test)

Example 9 with GLRMParameters

use of hex.glrm.GLRMModel.GLRMParameters in project h2o-3 by h2oai.

the class GLRMCategoricalTest method testLosses.

@Test
public void testLosses() throws InterruptedException, ExecutionException {
    long seed = 0xDECAF;
    Random rng = new Random(seed);
    Frame train = null;
    // Categoricals: CAPSULE, RACE, DPROS, DCAPS
    final int[] cats = new int[] { 1, 3, 4, 5 };
    final GlrmRegularizer[] regs = new GlrmRegularizer[] { GlrmRegularizer.Quadratic, GlrmRegularizer.L1, GlrmRegularizer.NonNegative, GlrmRegularizer.OneSparse, GlrmRegularizer.UnitOneSparse, GlrmRegularizer.Simplex };
    Scope.enter();
    try {
        train = parse_test_file(Key.make("prostate.hex"), "smalldata/logreg/prostate.csv");
        for (int i = 0; i < cats.length; i++) Scope.track(train.replace(cats[i], train.vec(cats[i]).toCategoricalVec()));
        train.remove("ID").remove();
        DKV.put(train._key, train);
        for (GlrmLoss loss : new GlrmLoss[] { GlrmLoss.Quadratic, GlrmLoss.Absolute, GlrmLoss.Huber, GlrmLoss.Poisson }) {
            for (GlrmLoss multiloss : new GlrmLoss[] { GlrmLoss.Categorical, GlrmLoss.Ordinal }) {
                GLRMModel model = null;
                try {
                    Scope.enter();
                    long myseed = rng.nextLong();
                    Log.info("GLRM using seed = " + myseed);
                    GLRMParameters parms = new GLRMParameters();
                    parms._train = train._key;
                    parms._transform = DataInfo.TransformType.NONE;
                    parms._k = 5;
                    parms._loss = loss;
                    parms._multi_loss = multiloss;
                    parms._init = GlrmInitialization.SVD;
                    parms._regularization_x = regs[rng.nextInt(regs.length)];
                    parms._regularization_y = regs[rng.nextInt(regs.length)];
                    parms._gamma_x = Math.abs(rng.nextDouble());
                    parms._gamma_y = Math.abs(rng.nextDouble());
                    parms._recover_svd = false;
                    parms._seed = myseed;
                    parms._verbose = false;
                    parms._max_iterations = 500;
                    model = new GLRM(parms).trainModel().get();
                    Log.info("Iteration " + model._output._iterations + ": Objective value = " + model._output._objective);
                    model.score(train).delete();
                    ModelMetricsGLRM mm = (ModelMetricsGLRM) ModelMetrics.getFromDKV(model, train);
                    Log.info("Numeric Sum of Squared Error = " + mm._numerr + "\tCategorical Misclassification Error = " + mm._caterr);
                } finally {
                    if (model != null)
                        model.delete();
                    Scope.exit();
                }
            }
        }
    } finally {
        if (train != null)
            train.delete();
        Scope.exit();
    }
}
Also used : Frame(water.fvec.Frame) GlrmLoss(hex.genmodel.algos.glrm.GlrmLoss) Random(java.util.Random) GLRMParameters(hex.glrm.GLRMModel.GLRMParameters) GlrmRegularizer(hex.genmodel.algos.glrm.GlrmRegularizer) Test(org.junit.Test)

Example 10 with GLRMParameters

use of hex.glrm.GLRMModel.GLRMParameters in project h2o-3 by h2oai.

the class GLRMCategoricalTest method testCategoricalProstate.

@Test
public void testCategoricalProstate() throws InterruptedException, ExecutionException {
    GLRMModel model = null;
    Frame train = null;
    // Categoricals: CAPSULE, RACE, DPROS, DCAPS
    final int[] cats = new int[] { 1, 3, 4, 5 };
    try {
        Scope.enter();
        train = parse_test_file(Key.make("prostate.hex"), "smalldata/logreg/prostate.csv");
        for (int i = 0; i < cats.length; i++) Scope.track(train.replace(cats[i], train.vec(cats[i]).toCategoricalVec()));
        train.remove("ID").remove();
        DKV.put(train._key, train);
        GLRMParameters parms = new GLRMParameters();
        parms._train = train._key;
        parms._k = 8;
        parms._gamma_x = parms._gamma_y = 0.1;
        parms._regularization_x = GlrmRegularizer.Quadratic;
        parms._regularization_y = GlrmRegularizer.Quadratic;
        parms._init = GlrmInitialization.PlusPlus;
        parms._transform = DataInfo.TransformType.STANDARDIZE;
        parms._recover_svd = false;
        parms._max_iterations = 200;
        model = new GLRM(parms).trainModel().get();
        Log.info("Iteration " + model._output._iterations + ": Objective value = " + model._output._objective);
        model.score(train).delete();
        ModelMetricsGLRM mm = (ModelMetricsGLRM) ModelMetrics.getFromDKV(model, train);
        Log.info("Numeric Sum of Squared Error = " + mm._numerr + "\tCategorical Misclassification Error = " + mm._caterr);
    } finally {
        if (train != null)
            train.delete();
        if (model != null)
            model.delete();
        Scope.exit();
    }
}
Also used : Frame(water.fvec.Frame) GLRMParameters(hex.glrm.GLRMModel.GLRMParameters) Test(org.junit.Test)

Aggregations

GLRMParameters (hex.glrm.GLRMModel.GLRMParameters)14 Test (org.junit.Test)14 Frame (water.fvec.Frame)14 DataInfo (hex.DataInfo)1 GlrmLoss (hex.genmodel.algos.glrm.GlrmLoss)1 GlrmRegularizer (hex.genmodel.algos.glrm.GlrmRegularizer)1 PCA (hex.pca.PCA)1 PCAModel (hex.pca.PCAModel)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 Random (java.util.Random)1 TreeMap (java.util.TreeMap)1 ExecutionException (java.util.concurrent.ExecutionException)1 Ignore (org.junit.Ignore)1 UploadFileVec (water.fvec.UploadFileVec)1 Vec (water.fvec.Vec)1 Val (water.rapids.Val)1 FrameUtils (water.util.FrameUtils)1