use of water.Key in project h2o-2 by h2oai.
the class Frames method parse.
/**
* Parse a dataset into a Frame.
*/
public static Frame parse(File file) {
Key fkey = NFSFileVec.make(file);
Key dest = Key.make(file.getName());
Frame frame = ParseDataset2.parse(dest, new Key[] { fkey });
return frame;
}
use of water.Key in project h2o-2 by h2oai.
the class Frames method execImpl.
@Override
protected void execImpl() {
// From file
parse(new File(VM.h2oFolder(), "smalldata/iris/iris.csv"));
// Programmatically
Frame frame = create(//
new String[] { "A", "B" }, new double[][] { //
new double[] { 1.0, 2.0 }, new double[] { 3.0, 4.0 } });
// Store frame in H2O's K/V store
Key key = Key.make("MyFrame");
UKV.put(key, frame);
}
use of water.Key in project h2o-2 by h2oai.
the class MapReduceKMeans method execImpl.
@Override
protected void execImpl() {
// Load and parse a file. Data is distributed to other nodes in a round-robin way
Key file = NFSFileVec.make(new File("../lib/resources/datasets/gaussian.csv"));
Frame frame = ParseDataset2.parse(Key.make("test"), new Key[] { file });
// Optionally create a frame with less columns, e.g. skip first
frame = new Frame(Utils.remove(frame._names, 0), Utils.remove(frame.vecs(), 0));
// Create k clusters as arrays of doubles
int k = 7;
double[][] clusters = new double[k][frame.vecs().length];
// Initialize first cluster to random row
Random rand = new Random();
for (int cluster = 0; cluster < clusters.length; cluster++) {
long row = Math.max(0, (long) (rand.nextDouble() * frame.vecs().length) - 1);
for (int i = 0; i < frame.vecs().length; i++) {
Vec v = frame.vecs()[i];
clusters[cluster][i] = v.at(row);
}
}
// Iterate over the dataset and show error for each step
for (int i = 0; i < 10; i++) {
KMeans task = new KMeans();
task.clusters = clusters;
task.doAll(frame);
for (int c = 0; c < clusters.length; c++) {
if (task.counts[c] > 0) {
for (int v = 0; v < frame.vecs().length; v++) {
double value = task.sums[c][v] / task.counts[c];
clusters[c][v] = value;
}
}
}
System.out.println("Error is " + task.error);
}
System.out.println("Clusters:");
DecimalFormat df = new DecimalFormat("#.00");
for (int c = 0; c < clusters.length; c++) {
for (int v = 0; v < frame.vecs().length; v++) System.out.print(df.format(clusters[c][v]) + ", ");
System.out.println("");
}
}
use of water.Key in project h2o-3 by h2oai.
the class CategoricalWrappedVec method computeMap.
public static int[] computeMap(String[] from, String[] to) {
Key key = Vec.newKey();
CategoricalWrappedVec tmp = new CategoricalWrappedVec(key);
tmp.computeMap(from, to, false);
return tmp._map;
}
use of water.Key in project h2o-3 by h2oai.
the class AstRename method apply.
@Override
public ValNum apply(Env env, Env.StackHelp stk, AstRoot[] asts) {
Key oldKey = Key.make(env.expand(asts[1].exec(env).getStr()));
Key newKey = Key.make(env.expand(asts[2].exec(env).getStr()));
Iced o = DKV.remove(oldKey).get();
if (o instanceof Frame)
DKV.put(newKey, new Frame(newKey, ((Frame) o)._names, ((Frame) o).vecs()));
else if (o instanceof Model) {
((Model) o)._key = newKey;
DKV.put(newKey, o);
} else
throw new IllegalArgumentException("Trying to rename Value of type " + o.getClass());
return new ValNum(Double.NaN);
}
Aggregations