Search in sources :

Example 6 with Key

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

Example 7 with Key

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);
}
Also used : File(java.io.File) Key(water.Key)

Example 8 with Key

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("");
    }
}
Also used : Random(java.util.Random) DecimalFormat(java.text.DecimalFormat) File(java.io.File) Key(water.Key)

Example 9 with Key

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

Example 10 with Key

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);
}
Also used : Frame(water.fvec.Frame) Model(hex.Model) Iced(water.Iced) ValNum(water.rapids.vals.ValNum) Key(water.Key)

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