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();
}
}
}
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;
}
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;
}
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;
}
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);
}
Aggregations