use of hex.ModelBuilder in project h2o-3 by h2oai.
the class DeepWater method cv_computeAndSetOptimalParameters.
@Override
public void cv_computeAndSetOptimalParameters(ModelBuilder<DeepWaterModel, DeepWaterParameters, DeepWaterModelOutput>[] cvModelBuilders) {
_parms._overwrite_with_best_model = false;
// No exciting changes to stopping conditions
if (_parms._stopping_rounds == 0 && _parms._max_runtime_secs == 0)
return;
// Extract stopping conditions from each CV model, and compute the best stopping answer
_parms._stopping_rounds = 0;
_parms._max_runtime_secs = 0;
double sum = 0;
for (ModelBuilder cvmb : cvModelBuilders) sum += ((DeepWaterModel) DKV.getGet(cvmb.dest())).last_scored().epoch_counter;
_parms._epochs = sum / cvModelBuilders.length;
if (!_parms._quiet_mode) {
warn("_epochs", "Setting optimal _epochs to " + _parms._epochs + " for cross-validation main model based on early stopping of cross-validation models.");
warn("_stopping_rounds", "Disabling convergence-based early stopping for cross-validation main model.");
warn("_max_runtime_secs", "Disabling maximum allowed runtime for cross-validation main model.");
}
}
use of hex.ModelBuilder in project h2o-3 by h2oai.
the class ModelBuildersHandler method fetch.
/** Return a single modelbuilder. */
// called through reflection by RequestServer
@SuppressWarnings("unused")
public ModelBuildersV3 fetch(int version, ModelBuildersV3 m) {
m.model_builders = new ModelBuilderSchema.IcedHashMapStringModelBuilderSchema();
ModelBuilder builder = ModelBuilder.make(m.algo, null, null);
m.model_builders.put(m.algo.toLowerCase(), (ModelBuilderSchema) SchemaServer.schema(version, builder).fillFromImpl(builder));
return m;
}
use of hex.ModelBuilder in project h2o-3 by h2oai.
the class ModelBuildersHandler method list.
/** Return all the modelbuilders. */
// called through reflection by RequestServer
@SuppressWarnings("unused")
public ModelBuildersV3 list(int version, ModelBuildersV3 m) {
m.model_builders = new ModelBuilderSchema.IcedHashMapStringModelBuilderSchema();
for (String algo : ModelBuilder.algos()) {
ModelBuilder builder = ModelBuilder.make(algo, null, null);
m.model_builders.put(algo.toLowerCase(), (ModelBuilderSchema) SchemaServer.schema(version, builder).fillFromImpl(builder));
}
return m;
}
use of hex.ModelBuilder in project h2o-3 by h2oai.
the class GridSearchHandler method handle.
// Invoke the handler with parameters. Can throw any exception the called handler can throw.
// TODO: why does this do its own params filling?
// TODO: why does this do its own sub-dispatch?
@Override
S handle(int version, water.api.Route route, Properties parms, String postBody) throws Exception {
// Only here for train or validate-parms
if (!route._handler_method.getName().equals("train"))
throw water.H2O.unimpl();
// Peek out the desired algo from the URL
String[] ss = route._url.split("/");
// {}/{99}/{Grid}/{gbm}/
String algoURLName = ss[3];
// gbm -> GBM; deeplearning -> DeepLearning
String algoName = ModelBuilder.algoName(algoURLName);
String schemaDir = ModelBuilder.schemaDirectory(algoURLName);
// Get the latest version of this algo: /99/Grid/gbm ==> GBMV3
// String algoSchemaName = SchemaServer.schemaClass(version, algoName).getSimpleName(); // GBMV3
// int algoVersion = Integer.valueOf(algoSchemaName.substring(algoSchemaName.lastIndexOf("V")+1)); // '3'
// Ok, i'm replacing one hack with another hack here, because SchemaServer.schema*() calls are getting eliminated.
// There probably shouldn't be any reference to algoVersion here at all... TODO: unhack all of this
int algoVersion = 3;
if (algoName.equals("SVD") || algoName.equals("Aggregator") || algoName.equals("StackedEnsemble"))
algoVersion = 99;
// TODO: this is a horrible hack which is going to cause maintenance problems:
String paramSchemaName = schemaDir + algoName + "V" + algoVersion + "$" + ModelBuilder.paramName(algoURLName) + "V" + algoVersion;
// Build the Grid Search schema, and fill it from the parameters
S gss = (S) new GridSearchSchema();
gss.init_meta();
gss.parameters = (P) TypeMap.newFreezable(paramSchemaName);
gss.parameters.init_meta();
gss.hyper_parameters = new IcedHashMap<>();
// Get default parameters, then overlay the passed-in values
// Default parameter settings
ModelBuilder builder = ModelBuilder.make(algoURLName, null, null);
// Defaults for this builder into schema
gss.parameters.fillFromImpl(builder._parms);
// Override defaults from user parms
gss.fillFromParms(parms);
// Verify list of hyper parameters
// Right now only names, no types
// note: still use _validation_frame and and _training_frame at this point.
// Do not change those names yet.
validateHyperParams((P) gss.parameters, gss.hyper_parameters);
// Get actual parameters
MP params = (MP) gss.parameters.createAndFillImpl();
Map<String, Object[]> sortedMap = new TreeMap<>(gss.hyper_parameters);
// training_fame are no longer valid names.
if (sortedMap.containsKey("validation_frame")) {
sortedMap.put("valid", sortedMap.get("validation_frame"));
sortedMap.remove("validation_frame");
}
// Get/create a grid for given frame
// FIXME: Grid ID is not pass to grid search builder!
Key<Grid> destKey = gss.grid_id != null ? gss.grid_id.key() : null;
// Create target grid search object (keep it private for now)
// Start grid search and return the schema back with job key
Job<Grid> gsJob = GridSearch.startGridSearch(destKey, params, sortedMap, new DefaultModelParametersBuilderFactory<MP, P>(), (HyperSpaceSearchCriteria) gss.search_criteria.createAndFillImpl());
// Fill schema with job parameters
// FIXME: right now we have to remove grid parameters which we sent back
gss.hyper_parameters = null;
// TODO: looks like it's currently always 0
gss.total_models = gsJob._result.get().getModelCount();
gss.job = new JobV3(gsJob);
return gss;
}
use of hex.ModelBuilder in project h2o-3 by h2oai.
the class ModelBuildersHandler method modelsInfo.
// called through reflection by RequestServer
@SuppressWarnings("unused")
public ModelsInfoV4 modelsInfo(int version, ListRequestV4 m) {
String[] algos = ModelBuilder.algos();
ModelInfoV4[] infos = new ModelInfoV4[algos.length];
ModelsInfoV4 res = new ModelsInfoV4();
for (int i = 0; i < algos.length; i++) {
ModelBuilder builder = ModelBuilder.make(algos[i], null, null);
infos[i] = new ModelInfoV4();
infos[i].algo = algos[i];
infos[i].maturity = builder.builderVisibility() == ModelBuilder.BuilderVisibility.Stable ? "stable" : builder.builderVisibility() == ModelBuilder.BuilderVisibility.Beta ? "beta" : "alpha";
infos[i].have_mojo = builder.haveMojo();
infos[i].have_pojo = builder.havePojo();
infos[i].mojo_version = infos[i].have_mojo ? detectMojoVersion(builder) : null;
}
res.models = infos;
return res;
}
Aggregations