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);
}
}
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));
}
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);
}
}
}
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);
}
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;
}
Aggregations