use of hex.deeplearning.DeepLearningModel.DeepLearningParameters in project h2o-3 by h2oai.
the class DeepLearningTest method elasticAveragingTrivial.
@Test
public void elasticAveragingTrivial() {
DeepLearningParameters dl;
Frame frTrain;
int N = 2;
DeepLearningModel[] models = new DeepLearningModel[N];
dl = new DeepLearningParameters();
Scope.enter();
try {
for (int i = 0; i < N; ++i) {
frTrain = parse_test_file("./smalldata/covtype/covtype.20k.data");
Vec resp = frTrain.lastVec().toCategoricalVec();
frTrain.remove(frTrain.vecs().length - 1).remove();
frTrain.add("Response", resp);
DKV.put(frTrain);
dl._train = frTrain._key;
dl._response_column = ((Frame) DKV.getGet(dl._train)).lastVecName();
dl._export_weights_and_biases = true;
dl._hidden = new int[] { 17, 11 };
dl._quiet_mode = false;
// make it reproducible
dl._seed = 1234;
dl._reproducible = true;
// only do one M/R iteration, and there's no elastic average yet - so the two paths below should be identical
dl._epochs = 1;
dl._train_samples_per_iteration = -1;
if (i == 0) {
// no elastic averaging
dl._elastic_averaging = false;
//ignored
dl._elastic_averaging_moving_rate = 0.5;
//ignored
dl._elastic_averaging_regularization = 0.9;
} else {
// no-op elastic averaging
//go different path, but don't really do anything because of epochs=1 and train_samples_per_iteration=-1
dl._elastic_averaging = true;
//doesn't matter, it's not used since we only do one M/R iteration and there's no time average
dl._elastic_averaging_moving_rate = 0.5;
//doesn't matter, since elastic average isn't yet available in first iteration
dl._elastic_averaging_regularization = 0.1;
}
// Invoke DL and block till the end
DeepLearning job = new DeepLearning(dl);
// Get the model
models[i] = job.trainModel().get();
frTrain.remove();
}
for (int i = 0; i < N; ++i) {
Log.info(models[i]._output._training_metrics.cm().table().toString());
Assert.assertEquals(models[i]._output._training_metrics._MSE, models[0]._output._training_metrics._MSE, 1e-6);
}
} finally {
for (int i = 0; i < N; ++i) if (models[i] != null)
models[i].delete();
Scope.exit();
}
}
use of hex.deeplearning.DeepLearningModel.DeepLearningParameters in project h2o-3 by h2oai.
the class DeepLearningTest method testCategoricalEncodingAUTO.
@Test
public void testCategoricalEncodingAUTO() {
Frame tfr = null;
DeepLearningModel dl = null;
try {
tfr = parse_test_file("./smalldata/junit/titanic_alt.csv");
Vec v = tfr.remove("survived");
tfr.add("survived", v.toCategoricalVec());
v.remove();
DKV.put(tfr);
DeepLearningParameters parms = new DeepLearningParameters();
parms._train = tfr._key;
parms._valid = tfr._key;
parms._response_column = "survived";
parms._reproducible = true;
parms._hidden = new int[] { 20, 20 };
parms._seed = 0xdecaf;
parms._nfolds = 3;
parms._distribution = bernoulli;
parms._categorical_encoding = Model.Parameters.CategoricalEncodingScheme.AUTO;
dl = new DeepLearning(parms).trainModel().get();
Assert.assertEquals(0.97329, ((ModelMetricsBinomial) dl._output._training_metrics)._auc._auc, 1e-3);
Assert.assertEquals(0.97329, ((ModelMetricsBinomial) dl._output._validation_metrics)._auc._auc, 1e-3);
Assert.assertEquals(0.93152165, ((ModelMetricsBinomial) dl._output._cross_validation_metrics)._auc._auc, 1e-5);
} finally {
if (tfr != null)
tfr.delete();
if (dl != null)
dl.deleteCrossValidationModels();
if (dl != null)
dl.delete();
}
}
use of hex.deeplearning.DeepLearningModel.DeepLearningParameters in project h2o-3 by h2oai.
the class DeepLearningTest method testConvergenceDeviance.
@Test
public void testConvergenceDeviance() {
Frame tfr = null;
DeepLearningModel dl = null;
DeepLearningModel dl2 = null;
try {
tfr = parse_test_file("./smalldata/logreg/prostate.csv");
DeepLearningParameters parms = new DeepLearningParameters();
parms._train = tfr._key;
parms._epochs = 1000000;
parms._response_column = "AGE";
parms._reproducible = true;
parms._hidden = new int[] { 2, 2 };
parms._seed = 0xdecaf;
parms._variable_importances = true;
parms._score_duty_cycle = 1.0;
parms._score_interval = 0;
//don't stop based on absolute classification error
parms._classification_stop = -1;
//don't stop based on absolute classification error
parms._stopping_rounds = 2;
//don't stop based on absolute classification error
parms._stopping_metric = ScoreKeeper.StoppingMetric.deviance;
parms._stopping_tolerance = 0.0;
dl = new DeepLearning(parms).trainModel().get();
Assert.assertTrue(dl.epoch_counter < parms._epochs);
} finally {
if (tfr != null)
tfr.delete();
if (dl != null)
dl.delete();
if (dl2 != null)
dl2.delete();
}
}
Aggregations