Search in sources :

Example 41 with Key

use of water.Key in project h2o-3 by h2oai.

the class DataInfoTestAdapt method testInteractionTrainTestSplitAdaptAirlines.

@Test
public void testInteractionTrainTestSplitAdaptAirlines() {
    DataInfo dinfo = null, scoreInfo = null;
    Frame frA = null, fr = null, expanded = null;
    Frame[] frSplits = null, expandSplits = null;
    String[] interactions = new String[] { "CRSDepTime", "Origin" };
    String[] keepColumns = new String[] { "Year", "Month", "DayofMonth", "DayOfWeek", "CRSDepTime", "CRSArrTime", "UniqueCarrier", "CRSElapsedTime", "Origin", "Dest", "Distance", "IsDepDelayed" };
    boolean useAll = false;
    // golden frame is standardized before splitting, while frame we want to check would be standardized post-split (not exactly what we want!)
    boolean standardize = false;
    boolean skipMissing = false;
    try {
        frA = parse_test_file(Key.make("a.hex"), "smalldata/airlines/allyears2k_headers.zip");
        fr = frA.subframe(keepColumns);
        // here's the "golden" frame
        expanded = GLMModel.GLMOutput.expand(fr, interactions, useAll, standardize, skipMissing);
        // now split fr and expanded
        long seed;
        frSplits = ShuffleSplitFrame.shuffleSplitFrame(fr, new Key[] { Key.make(), Key.make() }, new double[] { 0.8, 0.2 }, seed = new Random().nextLong());
        expandSplits = ShuffleSplitFrame.shuffleSplitFrame(expanded, new Key[] { Key.make(), Key.make() }, new double[] { 0.8, 0.2 }, seed);
        // check1: verify splits. expand frSplits with DataInfo and check against expandSplits
        checkSplits(frSplits, expandSplits, interactions, useAll, standardize, skipMissing);
        // now take the test frame from frSplits, and adapt it to a DataInfo built on the train frame
        dinfo = makeInfo(frSplits[0], interactions, useAll, standardize, skipMissing);
        GLMModel.GLMParameters parms = new GLMModel.GLMParameters();
        parms._response_column = "IsDepDelayed";
        Model.adaptTestForTrain(frSplits[1], null, null, dinfo._adaptedFrame.names(), dinfo._adaptedFrame.domains(), parms, true, false, interactions, null, null, false);
        scoreInfo = dinfo.scoringInfo(dinfo._adaptedFrame._names, frSplits[1]);
        checkFrame(scoreInfo, expandSplits[1], skipMissing);
    } finally {
        cleanup(fr, frA, expanded);
        cleanup(frSplits);
        cleanup(expandSplits);
        cleanup(dinfo, scoreInfo);
    }
}
Also used : ShuffleSplitFrame(hex.splitframe.ShuffleSplitFrame) Frame(water.fvec.Frame) GLMModel(hex.glm.GLMModel) Random(java.util.Random) Key(water.Key) Test(org.junit.Test)

Example 42 with Key

use of water.Key in project h2o-3 by h2oai.

the class ParseHandler method parseSVMLight.

// called through reflection by RequestServer
@SuppressWarnings("unused")
public JobV3 parseSVMLight(int version, ParseSVMLightV3 parse) {
    Key[] fkeys = new Key[parse.source_frames.length];
    for (int i = 0; i < fkeys.length; ++i) fkeys[i] = parse.source_frames[i].key();
    Key<Frame> destKey = parse.destination_frame == null ? null : parse.destination_frame.key();
    if (destKey == null)
        destKey = Key.make(ParseSetup.createHexName(parse.source_frames[0].toString()));
    ParseSetup setup = ParseSetup.guessSetup(fkeys, ParseSetup.makeSVMLightSetup());
    return new JobV3().fillFromImpl(ParseDataset.forkParseSVMLight(destKey, fkeys, setup));
}
Also used : Frame(water.fvec.Frame) ParseSetup(water.parser.ParseSetup) JobV3(water.api.schemas3.JobV3) Key(water.Key)

Example 43 with Key

use of water.Key in project h2o-2 by h2oai.

the class ImportS3 method processListing.

public void processListing(ObjectListing listing, JsonArray succ, JsonArray fail) {
    for (S3ObjectSummary obj : listing.getObjectSummaries()) {
        try {
            Key k = PersistS3.loadKey(obj);
            JsonObject o = new JsonObject();
            o.addProperty(KEY, k.toString());
            o.addProperty(FILE, obj.getKey());
            o.addProperty(VALUE_SIZE, obj.getSize());
            succ.add(o);
        } catch (IOException e) {
            JsonObject o = new JsonObject();
            o.addProperty(FILE, obj.getKey());
            o.addProperty(ERROR, e.getMessage());
            fail.add(o);
        }
    }
}
Also used : S3ObjectSummary(com.amazonaws.services.s3.model.S3ObjectSummary) IOException(java.io.IOException) Key(water.Key)

Example 44 with Key

use of water.Key in project h2o-2 by h2oai.

the class MatrixMultiply method serve.

@Override
protected Response serve() {
    Key jk = Key.make(after + "_job");
    Futures fs = new Futures();
    if (skip_first_col && x.numCols() == (y.numRows() + 1)) {
        // hack to remove columns added during smvlight conversion
        x.remove(0).remove(fs);
        y.remove(0).remove(fs);
    }
    new DMatrix.MatrixMulJob(jk, after, x, y).fork();
    return Response.redirect(this, "/2/Inspector", "src_key", after);
}
Also used : Futures(water.Futures) Key(water.Key) DMatrix(hex.la.DMatrix)

Example 45 with Key

use of water.Key in project h2o-2 by h2oai.

the class ASTFunc method map.

@Override
double[] map(Env env, double[] in, double[] out) {
    final int sp = env._sp;
    Key key = Vec.VectorGroup.VG_LEN1.addVecs(1)[0];
    AppendableVec av = new AppendableVec(key);
    NewChunk nc = new NewChunk(av, 0);
    for (double v : in) nc.addNum(v);
    nc.close(0, null);
    Frame fr = new Frame(new String[] { "row" }, new Vec[] { av.close(null) });
    env.push(this);
    env.push(fr);
    this.apply(env, 2, null);
    if (env.isDbl()) {
        if (out == null || out.length < 1)
            out = new double[1];
        out[0] = env.popDbl();
    } else if (env.isAry()) {
        fr = env.peekAry();
        if (fr.vecs().length > 1)
            H2O.unimpl();
        Vec vec = fr.anyVec();
        if (vec.length() > 1 << 8)
            H2O.unimpl();
        if (out == null || out.length < vec.length())
            out = new double[(int) vec.length()];
        for (long i = 0; i < vec.length(); i++) out[(int) i] = vec.at(i);
        env.pop();
    } else {
        H2O.unimpl();
    }
    assert sp == env._sp;
    return out;
}
Also used : Frame(water.fvec.Frame) Vec(water.fvec.Vec) AppendableVec(water.fvec.AppendableVec) AppendableVec(water.fvec.AppendableVec) Key(water.Key) NewChunk(water.fvec.NewChunk)

Aggregations

Key (water.Key)94 Frame (water.fvec.Frame)56 Test (org.junit.Test)42 Vec (water.fvec.Vec)21 File (java.io.File)18 NFSFileVec (water.fvec.NFSFileVec)17 Futures (water.Futures)10 Random (java.util.Random)7 H2OIllegalArgumentException (water.exceptions.H2OIllegalArgumentException)6 ValFrame (water.rapids.vals.ValFrame)6 DateTimeZone (org.joda.time.DateTimeZone)5 Model (hex.Model)4 SplitFrame (hex.SplitFrame)4 DeepLearning (hex.deeplearning.DeepLearning)4 DeepLearningModel (hex.deeplearning.DeepLearningModel)4 AppendableVec (water.fvec.AppendableVec)4 NewChunk (water.fvec.NewChunk)4 Grid (hex.grid.Grid)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3