Search in sources :

Example 1 with Model

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

the class GBMGridTest method testDuplicatesCarsGrid.

//@Ignore("PUBDEV-1643")
@Test
public void testDuplicatesCarsGrid() {
    Grid grid = null;
    Frame fr = null;
    Vec old = null;
    try {
        fr = parse_test_file("smalldata/junit/cars_20mpg.csv");
        // Remove unique id
        fr.remove("name").remove();
        old = fr.remove("economy");
        // response to last column
        fr.add("economy", old);
        DKV.put(fr);
        // Setup random hyperparameter search space
        HashMap<String, Object[]> hyperParms = new HashMap<String, Object[]>() {

            {
                put("_distribution", new DistributionFamily[] { DistributionFamily.gaussian });
                put("_ntrees", new Integer[] { 5, 5 });
                put("_max_depth", new Integer[] { 2, 2 });
                put("_learn_rate", new Double[] { .1, .1 });
            }
        };
        // Fire off a grid search
        GBMModel.GBMParameters params = new GBMModel.GBMParameters();
        params._train = fr._key;
        params._response_column = "economy";
        Job<Grid> gs = GridSearch.startGridSearch(null, params, hyperParms);
        grid = gs.get();
        // Check that duplicate model have not been constructed
        Model[] models = grid.getModels();
        assertTrue("Number of returned models has to be > 0", models.length > 0);
        // But all off them should be same
        Key<Model> modelKey = models[0]._key;
        for (Model m : models) {
            assertTrue("Number of constructed models has to be equal to 1", modelKey == m._key);
        }
    } finally {
        if (old != null) {
            old.remove();
        }
        if (fr != null) {
            fr.remove();
        }
        if (grid != null) {
            grid.remove();
        }
    }
}
Also used : Frame(water.fvec.Frame) HashMap(java.util.HashMap) Grid(hex.grid.Grid) Vec(water.fvec.Vec) Model(hex.Model) Test(org.junit.Test)

Example 2 with Model

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

the class ModelsV3 method fillFromImplWithSynopsis.

public ModelsV3 fillFromImplWithSynopsis(Models m) {
    this.model_id = new KeyV3.ModelKeyV3(m.model_id);
    if (null != m.models) {
        this.models = new ModelSchemaBaseV3[m.models.length];
        int i = 0;
        for (Model model : m.models) {
            this.models[i++] = new ModelSynopsisV3(model);
        }
    }
    return this;
}
Also used : Model(hex.Model)

Example 3 with Model

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

the class ModelsV3 method fillFromImpl.

@Override
public ModelsV3 fillFromImpl(Models m) {
    // TODO: this is failing in PojoUtils with an IllegalAccessException.  Why?  Different class loaders?
    // PojoUtils.copyProperties(this, m, PojoUtils.FieldNaming.CONSISTENT);
    // Shouldn't need to do this manually. . .
    this.model_id = new KeyV3.ModelKeyV3(m.model_id);
    this.find_compatible_frames = m.find_compatible_frames;
    if (null != m.models) {
        this.models = new ModelSchemaBaseV3[m.models.length];
        int i = 0;
        for (Model model : m.models) {
            this.models[i++] = (ModelSchemaV3) SchemaServer.schema(this.getSchemaVersion(), model).fillFromImpl(model);
        }
    }
    return this;
}
Also used : Model(hex.Model)

Example 4 with Model

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

the class ModelMetricsBaseV3 method fillFromImpl.

@Override
public S fillFromImpl(ModelMetrics modelMetrics) {
    // If we're copying in a Model we need a ModelSchemaV3 of the right class to fill into.
    Model m = modelMetrics.model();
    if (m != null) {
        this.model = new ModelKeyV3(m._key);
        this.model_category = m._output.getModelCategory();
        this.model_checksum = m.checksum();
    }
    // If we're copying in a Frame we need a Frame Schema of the right class to fill into.
    Frame f = modelMetrics.frame();
    if (null != f) {
        //true == f.getClass().getSuperclass().getGenericSuperclass() instanceof ParameterizedType
        this.frame = new FrameKeyV3(f._key);
        this.frame_checksum = f.checksum();
    }
    PojoUtils.copyProperties(this, modelMetrics, PojoUtils.FieldNaming.ORIGIN_HAS_UNDERSCORES, new String[] { "model", "model_category", "model_checksum", "frame", "frame_checksum" });
    RMSE = modelMetrics.rmse();
    return (S) this;
}
Also used : Frame(water.fvec.Frame) Model(hex.Model) ModelKeyV3(water.api.schemas3.KeyV3.ModelKeyV3) FrameKeyV3(water.api.schemas3.KeyV3.FrameKeyV3)

Example 5 with Model

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

the class AstRename method apply.

@Override
public ValNum apply(Env env, Env.StackHelp stk, AstRoot[] asts) {
    Key oldKey = Key.make(env.expand(asts[1].exec(env).getStr()));
    Key newKey = Key.make(env.expand(asts[2].exec(env).getStr()));
    Iced o = DKV.remove(oldKey).get();
    if (o instanceof Frame)
        DKV.put(newKey, new Frame(newKey, ((Frame) o)._names, ((Frame) o).vecs()));
    else if (o instanceof Model) {
        ((Model) o)._key = newKey;
        DKV.put(newKey, o);
    } else
        throw new IllegalArgumentException("Trying to rename Value of type " + o.getClass());
    return new ValNum(Double.NaN);
}
Also used : Frame(water.fvec.Frame) Model(hex.Model) Iced(water.Iced) ValNum(water.rapids.vals.ValNum) Key(water.Key)

Aggregations

Model (hex.Model)28 Frame (water.fvec.Frame)15 Grid (hex.grid.Grid)11 HashMap (java.util.HashMap)11 Test (org.junit.Test)11 MojoModel (hex.genmodel.MojoModel)8 Vec (water.fvec.Vec)6 URI (java.net.URI)4 ArrayList (java.util.ArrayList)4 Key (water.Key)4 Persist (water.persist.Persist)4 Random (java.util.Random)3 Set (java.util.Set)3 DataInfo (hex.DataInfo)2 ModelMojoWriter (hex.ModelMojoWriter)1 GLMModel (hex.glm.GLMModel)1 SharedTreeModel (hex.tree.SharedTreeModel)1 DRFModel (hex.tree.drf.DRFModel)1 GBMModel (hex.tree.gbm.GBMModel)1 HashSet (java.util.HashSet)1