Search in sources :

Example 6 with Vec

use of water.fvec.Vec in project h2o-2 by h2oai.

the class ToInt2 method serve.

@Override
protected Response serve() {
    try {
        if (column_index <= 0 || column_index > src_key.numCols())
            throw new IllegalArgumentException("Column index is 1 based. Please supply a valid column index in the range [1," + src_key.numCols() + "]");
        Log.info("Integerizing column " + column_index);
        Vec nv;
        if ((nv = src_key.vecs()[column_index - 1].masterVec()) == null) {
            assert src_key.vecs()[column_index - 1].isInt();
            nv = src_key.vecs()[column_index - 1];
            nv._domain = null;
        } else {
            assert src_key.vecs()[column_index - 1].masterVec().isInt();
            nv = src_key.vecs()[column_index - 1].masterVec();
        }
        src_key.replace(column_index - 1, nv);
    } catch (Throwable e) {
        return Response.error(e);
    }
    return Inspect2.redirect(this, src_key._key.toString());
}
Also used : Vec(water.fvec.Vec)

Example 7 with Vec

use of water.fvec.Vec in project h2o-2 by h2oai.

the class ASTNum method select.

// Execute a col/row selection & return the selection.  NULL means "all".
// Error to mix negatives & positive.  Negative list is sorted, with dups
// removed.  Positive list can have dups (which replicates cols) and is
// ordered.  numbers.  1-based numbering; 0 is ignored & removed.
static Object select(long len, AST ast, Env env) {
    // Trivial "all"
    if (ast == null)
        return null;
    ast.exec(env);
    long[] cols;
    if (!env.isAry()) {
        // Peek double; Silent truncation (R semantics)
        int col = (int) env._d[env._sp - 1];
        // Ignore a non-existent column
        if (col < 0 && col < -len)
            col = 0;
        if (col == 0)
            return new long[0];
        return new long[] { col };
    }
    // Got a frame/list of results.
    // Decide if we're a toss-out or toss-in list
    // Peek-frame
    Frame ary = env._ary[env._sp - 1];
    if (ary.numCols() != 1)
        throw new IllegalArgumentException("Selector must be a single column: " + ary.toStringNames());
    Vec vec = ary.anyVec();
    // Check for a matching column of bools.
    if (ary.numRows() == len && vec.min() >= 0 && vec.max() <= 1 && vec.isInt() && ary.numRows() > 1)
        // Boolean vector selection.
        return ary;
    // Convert single vector to a list of longs selecting rows
    if (ary.numRows() > 10000000)
        throw H2O.fail("Unimplemented: Cannot explicitly select > 10000000 rows in slice.");
    cols = MemoryManager.malloc8((int) ary.numRows());
    for (int i = 0; i < cols.length; ++i) {
        if (vec.isNA(i))
            throw new IllegalArgumentException("Can not use NA as index!");
        cols[i] = vec.at8(i);
    }
    return cols;
}
Also used : Frame(water.fvec.Frame) Vec(water.fvec.Vec)

Example 8 with Vec

use of water.fvec.Vec in project h2o-3 by h2oai.

the class DeepWaterParameters method guessProblemType.

/**
   * Attempt to guess the problem type from the dataset
   * @return
   */
ProblemType guessProblemType() {
    if (_problem_type == auto) {
        boolean image = false;
        boolean text = false;
        String first = null;
        Vec v = train().vec(0);
        if (v.isString() || v.isCategorical()) /*small data parser artefact*/
        {
            BufferedString bs = new BufferedString();
            first = v.atStr(bs, 0).toString();
            try {
                ImageIO.read(new File(first));
                image = true;
            } catch (Throwable t) {
            }
            try {
                ImageIO.read(new URL(first));
                image = true;
            } catch (Throwable t) {
            }
        }
        if (first != null) {
            if (!image && (first.endsWith(".jpg") || first.endsWith(".png") || first.endsWith(".tif"))) {
                image = true;
                Log.warn("Cannot read first image at " + first + " - Check data.");
            } else if (v.isString() && train().numCols() <= 4) {
                //at most text, label, fold_col, weight
                text = true;
            }
        }
        if (image)
            return ProblemType.image;
        else if (text)
            return ProblemType.text;
        else
            return ProblemType.dataset;
    } else {
        return _problem_type;
    }
}
Also used : Vec(water.fvec.Vec) BufferedString(water.parser.BufferedString) BufferedString(water.parser.BufferedString) File(java.io.File) URL(java.net.URL)

Example 9 with Vec

use of water.fvec.Vec in project h2o-3 by h2oai.

the class StackedEnsemble method addModelPredictionsToLevelOneFrame.

public static void addModelPredictionsToLevelOneFrame(Model aModel, Frame aModelsPredictions, Frame levelOneFrame) {
    if (aModel._output.isBinomialClassifier()) {
        // GLM uses a different column name than the other algos, yay!
        // Predictions column names have been changed. . .
        Vec preds = aModelsPredictions.vec(2);
        levelOneFrame.add(aModel._key.toString(), preds);
    } else if (aModel._output.isClassifier()) {
        throw new H2OIllegalArgumentException("Don't yet know how to stack multinomial classifiers: " + aModel._key);
    } else if (aModel._output.isAutoencoder()) {
        throw new H2OIllegalArgumentException("Don't yet know how to stack autoencoders: " + aModel._key);
    } else if (!aModel._output.isSupervised()) {
        throw new H2OIllegalArgumentException("Don't yet know how to stack unsupervised models: " + aModel._key);
    } else {
        levelOneFrame.add(aModel._key.toString(), aModelsPredictions.vec("predict"));
    }
}
Also used : Vec(water.fvec.Vec) H2OIllegalArgumentException(water.exceptions.H2OIllegalArgumentException)

Example 10 with Vec

use of water.fvec.Vec in project h2o-3 by h2oai.

the class GLMMetricBuilder method makeModelMetrics.

@Override
public ModelMetrics makeModelMetrics(Model m, Frame f, Frame adaptedFrame, Frame preds) {
    GLMModel gm = (GLMModel) m;
    computeAIC();
    ModelMetrics metrics = _metricBuilder.makeModelMetrics(gm, f, null, null);
    if (_glmf._family == Family.binomial) {
        ModelMetricsBinomial metricsBinommial = (ModelMetricsBinomial) metrics;
        GainsLift gl = null;
        if (preds != null) {
            Vec resp = f.vec(m._parms._response_column);
            Vec weights = f.vec(m._parms._weights_column);
            if (resp != null) {
                gl = new GainsLift(preds.lastVec(), resp, weights);
                gl.exec(m._output._job);
            }
        }
        metrics = new ModelMetricsBinomialGLM(m, f, metrics._nobs, metrics._MSE, _domain, metricsBinommial._sigma, metricsBinommial._auc, metricsBinommial._logloss, residualDeviance(), null_devince, _aic, nullDOF(), resDOF(), gl);
    } else if (_glmf._family == Family.multinomial) {
        ModelMetricsMultinomial metricsMultinomial = (ModelMetricsMultinomial) metrics;
        metrics = new ModelMetricsMultinomialGLM(m, f, metricsMultinomial._nobs, metricsMultinomial._MSE, metricsMultinomial._domain, metricsMultinomial._sigma, metricsMultinomial._cm, metricsMultinomial._hit_ratios, metricsMultinomial._logloss, residualDeviance(), null_devince, _aic, nullDOF(), resDOF());
    } else {
        ModelMetricsRegression metricsRegression = (ModelMetricsRegression) metrics;
        metrics = new ModelMetricsRegressionGLM(m, f, metricsRegression._nobs, metricsRegression._MSE, metricsRegression._sigma, metricsRegression._mean_absolute_error, metricsRegression._root_mean_squared_log_error, residualDeviance(), residualDeviance() / _wcount, null_devince, _aic, nullDOF(), resDOF());
    }
    // Update the metrics in-place with the GLM version
    return gm.addModelMetrics(metrics);
}
Also used : Vec(water.fvec.Vec) ModelMetricsMultinomialGLM(hex.ModelMetricsBinomialGLM.ModelMetricsMultinomialGLM)

Aggregations

Vec (water.fvec.Vec)280 Frame (water.fvec.Frame)213 Test (org.junit.Test)82 NFSFileVec (water.fvec.NFSFileVec)48 ValFrame (water.rapids.vals.ValFrame)47 Chunk (water.fvec.Chunk)30 Random (java.util.Random)25 NewChunk (water.fvec.NewChunk)23 DeepLearningParameters (hex.deeplearning.DeepLearningModel.DeepLearningParameters)22 Key (water.Key)21 MRTask (water.MRTask)17 Val (water.rapids.Val)14 File (java.io.File)11 ArrayList (java.util.ArrayList)11 Futures (water.Futures)11 H2OIllegalArgumentException (water.exceptions.H2OIllegalArgumentException)11 ValNum (water.rapids.vals.ValNum)11 ShuffleSplitFrame (hex.splitframe.ShuffleSplitFrame)10 BufferedString (water.parser.BufferedString)10 AppendableVec (water.fvec.AppendableVec)9