use of hex.deeplearning.DeepLearningModel.DeepLearningParameters in project h2o-3 by h2oai.
the class DeepLearningTest method testBinomial.
@Test
public void testBinomial() {
Frame train = null;
Frame preds = null;
Frame small = null, large = null;
DeepLearningModel model = null;
Scope.enter();
try {
train = parse_test_file("./smalldata/junit/titanic_alt.csv");
Vec v = train.remove("survived");
train.add("survived", v.toCategoricalVec());
v.remove();
DKV.put(train);
DeepLearningParameters parms = new DeepLearningParameters();
parms._train = train._key;
parms._response_column = "survived";
parms._reproducible = true;
parms._hidden = new int[] { 20, 20 };
parms._seed = 0xdecaf;
model = new DeepLearning(parms).trainModel().get();
FrameSplitter fs = new FrameSplitter(train, new double[] { 0.002 }, new Key[] { Key.make("small"), Key.make("large") }, null);
fs.compute2();
small = fs.getResult()[0];
large = fs.getResult()[1];
preds = model.score(small);
//actual
Vec labels = small.vec("survived");
//actual
String[] fullDomain = train.vec("survived").domain();
ModelMetricsBinomial mm = ModelMetricsBinomial.make(preds.vec(2), labels, fullDomain);
Log.info(mm.toString());
mm = ModelMetricsBinomial.make(preds.vec(2), labels, new String[] { "0", "1" });
Log.info(mm.toString());
mm = ModelMetricsBinomial.make(preds.vec(2), labels);
Log.info(mm.toString());
try {
mm = ModelMetricsBinomial.make(preds.vec(2), labels, new String[] { "a", "b" });
Log.info(mm.toString());
Assert.assertFalse(true);
} catch (IllegalArgumentException ex) {
ex.printStackTrace();
}
} catch (Throwable t) {
t.printStackTrace();
throw t;
} finally {
if (model != null)
model.delete();
if (preds != null)
preds.remove();
if (train != null)
train.remove();
if (small != null)
small.delete();
if (large != null)
large.delete();
Scope.exit();
}
}
use of hex.deeplearning.DeepLearningModel.DeepLearningParameters in project h2o-3 by h2oai.
the class DeepLearningTest method testPretrainedAE.
@Test
public void testPretrainedAE() {
Frame tfr = null;
DeepLearningModel dl1 = null;
DeepLearningModel dl2 = null;
DeepLearningModel ae = null;
try {
tfr = parse_test_file("./smalldata/gbm_test/BostonHousing.csv");
Vec r = tfr.remove("chas");
tfr.add("chas", r.toCategoricalVec());
DKV.put(tfr);
r.remove();
// train unsupervised AE
Key<DeepLearningModel> key = Key.make("ae_model");
{
DeepLearningParameters parms = new DeepLearningParameters();
parms._train = tfr._key;
parms._ignored_columns = new String[] { "chas" };
parms._activation = DeepLearningParameters.Activation.TanhWithDropout;
parms._reproducible = true;
parms._hidden = new int[] { 20, 20 };
parms._input_dropout_ratio = 0.1;
parms._hidden_dropout_ratios = new double[] { 0.2, 0.1 };
parms._autoencoder = true;
parms._seed = 0xdecaf;
ae = new DeepLearning(parms, key).trainModel().get();
// test POJO
Frame res = ae.score(tfr);
assertTrue(ae.testJavaScoring(tfr, res, 1e-5));
res.remove();
}
// train supervised DL model
{
DeepLearningParameters parms = new DeepLearningParameters();
parms._train = tfr._key;
parms._response_column = "chas";
parms._activation = DeepLearningParameters.Activation.TanhWithDropout;
parms._reproducible = true;
parms._hidden = new int[] { 20, 20 };
parms._input_dropout_ratio = 0.1;
parms._hidden_dropout_ratios = new double[] { 0.2, 0.1 };
parms._seed = 0xdecad;
parms._pretrained_autoencoder = key;
parms._rate_decay = 1.0;
parms._adaptive_rate = false;
parms._rate_annealing = 1e-3;
parms._loss = DeepLearningParameters.Loss.CrossEntropy;
dl1 = new DeepLearning(parms).trainModel().get();
// test POJO
Frame res = dl1.score(tfr);
assertTrue(dl1.testJavaScoring(tfr, res, 1e-5));
res.remove();
}
// train DL model from scratch
{
DeepLearningParameters parms = new DeepLearningParameters();
parms._train = tfr._key;
parms._response_column = "chas";
parms._activation = DeepLearningParameters.Activation.TanhWithDropout;
parms._reproducible = true;
parms._hidden = new int[] { 20, 20 };
parms._input_dropout_ratio = 0.1;
parms._hidden_dropout_ratios = new double[] { 0.2, 0.1 };
parms._seed = 0xdecad;
parms._rate_decay = 1.0;
parms._adaptive_rate = false;
parms._rate_annealing = 1e-3;
dl2 = new DeepLearning(parms).trainModel().get();
// test POJO
Frame res = dl2.score(tfr);
assertTrue(dl2.testJavaScoring(tfr, res, 1e-5));
res.remove();
}
Log.info("pretrained : MSE=" + dl1._output._training_metrics.mse());
Log.info("from scratch: MSE=" + dl2._output._training_metrics.mse());
// Assert.assertTrue(dl1._output._training_metrics.mse() < dl2._output._training_metrics.mse());
} finally {
if (tfr != null)
tfr.delete();
if (ae != null)
ae.delete();
if (dl1 != null)
dl1.delete();
if (dl2 != null)
dl2.delete();
}
}
use of hex.deeplearning.DeepLearningModel.DeepLearningParameters in project h2o-3 by h2oai.
the class DeepLearningTest method testMiniBatch50.
@Test
public void testMiniBatch50() {
Frame tfr = null;
DeepLearningModel dl = null;
try {
tfr = parse_test_file("./smalldata/gbm_test/BostonHousing.csv");
DeepLearningParameters parms = new DeepLearningParameters();
parms._train = tfr._key;
parms._response_column = tfr.lastVecName();
parms._reproducible = true;
parms._hidden = new int[] { 20, 20 };
parms._seed = 0xdecaf;
parms._mini_batch_size = 50;
dl = new DeepLearning(parms).trainModel().get();
Assert.assertEquals(12.938076268040659, dl._output._training_metrics._MSE, 1e-6);
} 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 testMultinomial.
@Test
public void testMultinomial() {
Frame train = null;
Frame preds = null;
DeepLearningModel model = null;
Scope.enter();
try {
train = parse_test_file("./smalldata/junit/titanic_alt.csv");
Vec v = train.remove("pclass");
train.add("pclass", v.toCategoricalVec());
v.remove();
DKV.put(train);
DeepLearningParameters p = new DeepLearningParameters();
p._train = train._key;
// last column is the response
p._response_column = "pclass";
p._activation = DeepLearningParameters.Activation.RectifierWithDropout;
p._hidden = new int[] { 50, 50 };
p._epochs = 1;
p._adaptive_rate = false;
p._rate = 0.005;
p._sparse = true;
model = new DeepLearning(p).trainModel().get();
preds = model.score(train);
//remove label, keep only probs
preds.remove(0);
//actual
Vec labels = train.vec("pclass");
//actual
String[] fullDomain = train.vec("pclass").domain();
ModelMetricsMultinomial mm = ModelMetricsMultinomial.make(preds, labels, fullDomain);
Log.info(mm.toString());
} finally {
if (model != null)
model.delete();
if (preds != null)
preds.remove();
if (train != null)
train.remove();
Scope.exit();
}
}
use of hex.deeplearning.DeepLearningModel.DeepLearningParameters in project h2o-3 by h2oai.
the class DeepLearningTest method testEarlyStopping.
@Test
public void testEarlyStopping() {
Frame tfr = null;
DeepLearningModel dl = null;
try {
tfr = parse_test_file("./smalldata/junit/two_spiral.csv");
for (String s : new String[] { "Class" }) {
Vec resp = tfr.vec(s).toCategoricalVec();
tfr.remove(s).remove();
tfr.add(s, resp);
DKV.put(tfr);
}
DeepLearningParameters parms = new DeepLearningParameters();
parms._train = tfr._key;
parms._epochs = 100;
parms._response_column = "Class";
parms._reproducible = true;
parms._classification_stop = 0.7;
parms._score_duty_cycle = 1;
parms._score_interval = 0;
parms._hidden = new int[] { 100, 100 };
parms._seed = 0xdecaf;
// Build a first model; all remaining models should be equal
dl = new DeepLearning(parms).trainModel().get();
assertTrue(dl.stopped_early);
assertTrue(dl.epoch_counter < 100);
} finally {
if (tfr != null)
tfr.delete();
if (dl != null)
dl.delete();
}
}
Aggregations