use of water.fvec.Vec in project h2o-3 by h2oai.
the class DeepLearningTest method testConvergenceAUC.
@Test
public void testConvergenceAUC() {
Frame tfr = null;
DeepLearningModel dl = null;
DeepLearningModel dl2 = null;
try {
tfr = parse_test_file("./smalldata/logreg/prostate.csv");
for (String s : new String[] { "CAPSULE" }) {
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 = 1000000;
parms._response_column = "CAPSULE";
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.AUC;
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();
}
}
use of water.fvec.Vec in project h2o-3 by h2oai.
the class DeepWaterAbstractIntegrationTest method categorical.
@Test
public void categorical() {
Frame tr = null;
DeepWaterModel m = null;
try {
DeepWaterParameters p = new DeepWaterParameters();
p._backend = getBackend();
p._train = (tr = parse_test_file("smalldata/gbm_test/alphabet_cattest.csv"))._key;
p._response_column = "y";
for (String col : new String[] { "y" }) {
Vec v = tr.remove(col);
tr.add(col, v.toCategoricalVec());
v.remove();
}
DKV.put(tr);
DeepWater j = new DeepWater(p);
m = j.trainModel().get();
Assert.assertTrue((m._output._training_metrics).auc_obj()._auc > 0.90);
} finally {
if (tr != null)
tr.remove();
if (m != null)
m.remove();
}
}
use of water.fvec.Vec in project h2o-3 by h2oai.
the class FindHandler method find.
// called through reflection by RequestServer
@SuppressWarnings("unused")
public FindV3 find(int version, FindV3 find) {
Frame frame = find.key._fr;
// Peel out an optional column; restrict to this column
if (find.column != null) {
Vec vec = frame.vec(find.column);
if (vec == null)
throw new H2OColumnNotFoundArgumentException("column", frame, find.column);
find.key = new FrameV3(new Frame(new String[] { find.column }, new Vec[] { vec }));
}
// Convert the search string into a column-specific flavor
Vec[] vecs = frame.vecs();
double[] ds = new double[vecs.length];
for (int i = 0; i < vecs.length; i++) {
if (vecs[i].isCategorical()) {
int idx = ArrayUtils.find(vecs[i].domain(), find.match);
if (idx == -1 && vecs.length == 1)
throw new H2OCategoricalLevelNotFoundArgumentException("match", find.match, frame._key.toString(), frame.name(i));
ds[i] = idx;
} else if (vecs[i].isUUID()) {
throw H2O.unimpl();
} else if (vecs[i].isString()) {
throw H2O.unimpl();
} else if (vecs[i].isTime()) {
throw H2O.unimpl();
} else {
try {
ds[i] = find.match == null ? Double.NaN : Double.parseDouble(find.match);
} catch (NumberFormatException e) {
if (vecs.length == 1) {
// There's only one Vec and it's a numeric Vec and our search string isn't a number
IcedHashMapGeneric.IcedHashMapStringObject values = new IcedHashMapGeneric.IcedHashMapStringObject();
String msg = "Frame: " + frame._key.toString() + " as only one column, it is numeric, and the find pattern is not numeric: " + find.match;
values.put("frame_name", frame._key.toString());
values.put("column_name", frame.name(i));
values.put("pattern", find.match);
throw new H2OIllegalArgumentException(msg, msg, values);
}
// Do not match
ds[i] = Double.longBitsToDouble(0xcafebabe);
}
}
}
Find f = new Find(find.row, ds).doAll(frame);
find.prev = f._prev;
find.next = f._next == Long.MAX_VALUE ? -1 : f._next;
return find;
}
use of water.fvec.Vec in project h2o-3 by h2oai.
the class FramesHandler method column.
// TODO: return VecV4
/** Return a single column from the frame. */
// called through reflection by RequestServer
@SuppressWarnings("unused")
public FramesV3 column(int version, FramesV3 s) {
// TODO: should return a Vec schema
Frame frame = getFromDKV("key", s.frame_id.key());
Vec vec = frame.vec(s.column);
if (null == vec)
throw new H2OColumnNotFoundArgumentException("column", s.frame_id.toString(), s.column);
Vec[] vecs = { vec };
String[] names = { s.column };
Frame new_frame = new Frame(names, vecs);
s.frames = new FrameV3[1];
s.frames[0] = new FrameV3().fillFromImpl(new_frame);
((FrameV3) s.frames[0]).clearBinsField();
return s;
}
use of water.fvec.Vec in project h2o-3 by h2oai.
the class FramesHandler method summary.
// called through reflection by RequestServer
@SuppressWarnings("unused")
public // TODO: return list of FrameSummaryV3 that has histograms et al.
FramesV3 summary(int version, FramesV3 s) {
// safe
Frame frame = getFromDKV("key", s.frame_id.key());
if (null != frame) {
Futures fs = new Futures();
int i = 0;
for (Vec v : frame.vecs()) {
if (null == DKV.get(v._key))
Log.warn("For Frame: " + frame._key + ", Vec number: " + i + " (" + frame.name(i) + ") is missing; not returning it.");
else
v.startRollupStats(fs, Vec.DO_HISTOGRAMS);
i++;
}
fs.blockForPending();
}
return doFetch(version, s);
}
Aggregations