Search in sources :

Example 86 with Vec

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();
    }
}
Also used : Frame(water.fvec.Frame) NFSFileVec(water.fvec.NFSFileVec) Vec(water.fvec.Vec) DeepLearningParameters(hex.deeplearning.DeepLearningModel.DeepLearningParameters) Test(org.junit.Test)

Example 87 with Vec

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();
    }
}
Also used : Frame(water.fvec.Frame) ShuffleSplitFrame(hex.splitframe.ShuffleSplitFrame) NFSFileVec(water.fvec.NFSFileVec) Vec(water.fvec.Vec)

Example 88 with Vec

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;
}
Also used : IcedHashMapGeneric(water.util.IcedHashMapGeneric) Frame(water.fvec.Frame) H2OCategoricalLevelNotFoundArgumentException(water.exceptions.H2OCategoricalLevelNotFoundArgumentException) H2OIllegalArgumentException(water.exceptions.H2OIllegalArgumentException) FrameV3(water.api.schemas3.FrameV3) Vec(water.fvec.Vec) H2OColumnNotFoundArgumentException(water.exceptions.H2OColumnNotFoundArgumentException)

Example 89 with Vec

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;
}
Also used : Frame(water.fvec.Frame) Vec(water.fvec.Vec)

Example 90 with Vec

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);
}
Also used : Frame(water.fvec.Frame) Vec(water.fvec.Vec)

Aggregations

Vec (water.fvec.Vec)280 Frame (water.fvec.Frame)213 Test (org.junit.Test)82 NFSFileVec (water.fvec.NFSFileVec)48 ValFrame (water.rapids.vals.ValFrame)47 Chunk (water.fvec.Chunk)30 Random (java.util.Random)25 NewChunk (water.fvec.NewChunk)23 DeepLearningParameters (hex.deeplearning.DeepLearningModel.DeepLearningParameters)22 Key (water.Key)21 MRTask (water.MRTask)17 Val (water.rapids.Val)14 File (java.io.File)11 ArrayList (java.util.ArrayList)11 Futures (water.Futures)11 H2OIllegalArgumentException (water.exceptions.H2OIllegalArgumentException)11 ValNum (water.rapids.vals.ValNum)11 ShuffleSplitFrame (hex.splitframe.ShuffleSplitFrame)10 BufferedString (water.parser.BufferedString)10 AppendableVec (water.fvec.AppendableVec)9