use of water.api.schemas3.KeyV3.FrameKeyV3 in project h2o-3 by h2oai.
the class ModelMetricsBaseV3 method fillFromImpl.
@Override
public S fillFromImpl(ModelMetrics modelMetrics) {
// If we're copying in a Model we need a ModelSchemaV3 of the right class to fill into.
Model m = modelMetrics.model();
if (m != null) {
this.model = new ModelKeyV3(m._key);
this.model_category = m._output.getModelCategory();
this.model_checksum = m.checksum();
}
// If we're copying in a Frame we need a Frame Schema of the right class to fill into.
Frame f = modelMetrics.frame();
if (null != f) {
//true == f.getClass().getSuperclass().getGenericSuperclass() instanceof ParameterizedType
this.frame = new FrameKeyV3(f._key);
this.frame_checksum = f.checksum();
}
PojoUtils.copyProperties(this, modelMetrics, PojoUtils.FieldNaming.ORIGIN_HAS_UNDERSCORES, new String[] { "model", "model_category", "model_checksum", "frame", "frame_checksum" });
RMSE = modelMetrics.rmse();
return (S) this;
}
use of water.api.schemas3.KeyV3.FrameKeyV3 in project h2o-3 by h2oai.
the class AssemblyHandler method fit.
public AssemblyV99 fit(int version, AssemblyV99 ass) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
if (ass == null)
return null;
if (ass.steps == null)
return ass;
// process assembly:
// of the form [name__class__ast__inplace__names, name__class__ast__inplace__names, ...]
// s[0] : stepName
// s[1] : transform class
// s[2] : ast (can be noop)
// s[3] : inplace
// s[4] : names
ArrayList<Transform> steps = new ArrayList<>();
for (String step : ass.steps) {
String[] s = step.split("__");
Class transformClass = Class.forName("water.rapids.transforms." + s[1]);
Class[] constructorTypes = new Class[] { String.class, /*name*/
String.class, /*ast*/
boolean.class, /*inplace*/
String[].class };
Object[] constructorArgs = new Object[] { s[0], s[2], Boolean.valueOf(s[3]), s[4].equals("|") ? null : s[4].split("\\|") };
steps.add((Transform) transformClass.getConstructor(constructorTypes).newInstance(constructorArgs));
}
Assembly assembly = new Assembly(Key.make("assembly_" + Key.make().toString()), steps.toArray(new Transform[steps.size()]));
ass.result = new KeyV3.FrameKeyV3(assembly.fit((Frame) DKV.getGet(ass.frame.key()))._key);
ass.assembly = new KeyV3.AssemblyKeyV3(assembly._key);
DKV.put(assembly);
return ass;
}
use of water.api.schemas3.KeyV3.FrameKeyV3 in project h2o-3 by h2oai.
the class MakeGLMModelHandler method getDataInfoFrame.
// instead of adding a new endpoint, just put this stupid test functionality here
/** Get the expanded (interactions + offsets) dataset. Careful printing! Test only
*/
public DataInfoFrameV3 getDataInfoFrame(int version, DataInfoFrameV3 args) {
Frame fr = DKV.getGet(args.frame.key());
if (null == fr)
throw new IllegalArgumentException("no frame found");
args.result = new KeyV3.FrameKeyV3(oneHot(fr, args.interactions, args.use_all, args.standardize, args.interactions_only, true)._key);
return args;
}
use of water.api.schemas3.KeyV3.FrameKeyV3 in project h2o-3 by h2oai.
the class MakeGLMModelHandler method computeGram.
public GramV3 computeGram(int v, GramV3 input) {
if (DKV.get(input.X.key()) == null)
throw new IllegalArgumentException("Frame " + input.X.key() + " does not exist.");
Frame fr = input.X.key().get();
Frame frcpy = new Frame(fr._names.clone(), fr.vecs().clone());
String wname = null;
Vec weight = null;
if (input.W != null && !input.W.column_name.isEmpty()) {
wname = input.W.column_name;
if (fr.find(wname) == -1)
throw new IllegalArgumentException("Did not find weight vector " + wname);
weight = frcpy.remove(wname);
}
DataInfo dinfo = new DataInfo(frcpy, null, 0, input.use_all_factor_levels, input.standardize ? TransformType.STANDARDIZE : TransformType.NONE, TransformType.NONE, input.skip_missing, false, !input.skip_missing, /* weight */
false, /* offset */
false, /* fold */
false, /* intercept */
true);
DKV.put(dinfo);
if (weight != null)
dinfo.setWeights(wname, weight);
Gram.GramTask gt = new Gram.GramTask(null, dinfo, false, true).doAll(dinfo._adaptedFrame);
double[][] gram = gt._gram.getXX();
dinfo.remove();
String[] names = water.util.ArrayUtils.append(dinfo.coefNames(), "Intercept");
Vec[] vecs = new Vec[gram.length];
Key[] keys = new VectorGroup().addVecs(vecs.length);
for (int i = 0; i < vecs.length; ++i) vecs[i] = Vec.makeVec(gram[i], keys[i]);
input.destination_frame = new KeyV3.FrameKeyV3();
String keyname = input.X.key().toString();
if (keyname.endsWith(".hex"))
keyname = keyname.substring(0, keyname.lastIndexOf("."));
keyname = keyname + "_gram";
if (weight != null)
keyname = keyname + "_" + wname;
Key k = Key.make(keyname);
if (DKV.get(k) != null) {
int cnt = 0;
while (cnt < 1000 && DKV.get(k = Key.make(keyname + "_" + cnt)) != null) cnt++;
if (cnt == 1000)
throw new IllegalArgumentException("unable to make unique key");
}
input.destination_frame.fillFromImpl(k);
DKV.put(new Frame(k, names, vecs));
return input;
}
use of water.api.schemas3.KeyV3.FrameKeyV3 in project h2o-3 by h2oai.
the class Word2VecHandler method transform.
public Word2VecTransformV3 transform(int version, Word2VecTransformV3 args) {
Word2VecModel model = DKV.getGet(args.model.key());
if (model == null)
throw new IllegalArgumentException("missing source model " + args.model);
Frame words = DKV.getGet(args.words_frame.key());
if (words == null)
throw new IllegalArgumentException("missing words frame " + args.words_frame);
if (words.numCols() != 1) {
throw new IllegalArgumentException("words frame is expected to have a single string column, got" + words.numCols());
}
if (args.aggregate_method == null)
args.aggregate_method = Word2VecModel.AggregateMethod.NONE;
Frame vectors = model.transform(words.vec(0), args.aggregate_method);
args.vectors_frame = new KeyV3.FrameKeyV3(vectors._key);
return args;
}
Aggregations