Search in sources :

Example 1 with Interaction

use of hex.Interaction in project h2o-3 by h2oai.

the class InteractionHandler method run.

public JobV3 run(int version, InteractionV3 cf) {
    Interaction cfr = new Interaction();
    cf.fillImpl(cfr);
    return new JobV3(cfr.execImpl(cf.dest == null ? null : cf.dest.key()));
}
Also used : Interaction(hex.Interaction) JobV3(water.api.schemas3.JobV3)

Example 2 with Interaction

use of hex.Interaction in project h2o-3 by h2oai.

the class Tabulate method execImpl.

public Tabulate execImpl() {
    if (_dataset == null)
        throw new H2OIllegalArgumentException("Dataset not found");
    if (_nbins_predictor < 1)
        throw new H2OIllegalArgumentException("Number of bins for predictor must be >= 1");
    if (_nbins_response < 1)
        throw new H2OIllegalArgumentException("Number of bins for response must be >= 1");
    Vec x = _dataset.vec(_predictor);
    if (x == null)
        throw new H2OIllegalArgumentException("Predictor column " + _predictor + " not found");
    if (x.cardinality() > _nbins_predictor) {
        Interaction in = new Interaction();
        in._source_frame = _dataset._key;
        in._factor_columns = new String[] { _predictor };
        in._max_factors = _nbins_predictor - 1;
        in.execImpl(null);
        x = in._job._result.get().anyVec();
    } else if (x.isInt() && (x.max() - x.min() + 1) <= _nbins_predictor) {
        x = x.toCategoricalVec();
    }
    Vec y = _dataset.vec(_response);
    if (y == null)
        throw new H2OIllegalArgumentException("Response column " + _response + " not found");
    if (y.cardinality() > _nbins_response) {
        Interaction in = new Interaction();
        in._source_frame = _dataset._key;
        in._factor_columns = new String[] { _response };
        in._max_factors = _nbins_response - 1;
        in.execImpl(null);
        y = in._job._result.get().anyVec();
    } else if (y.isInt() && (y.max() - y.min() + 1) <= _nbins_response) {
        y = y.toCategoricalVec();
    }
    if (y != null && y.cardinality() > 2)
        Log.warn("Response column has more than two factor levels - mean response depends on lexicographic order of factors!");
    //can be null
    Vec w = _dataset.vec(_weight);
    if (w != null && (!w.isNumeric() && w.min() < 0))
        throw new H2OIllegalArgumentException("Observation weights must be numeric with values >= 0");
    if (x != null) {
        _vecs[0] = x._key;
        _stats[0] = new Stats(x);
    }
    if (y != null) {
        _vecs[1] = y._key;
        _stats[1] = new Stats(y);
    }
    Tabulate sp = w != null ? new CoOccurrence(this).doAll(x, y, w)._sp : new CoOccurrence(this).doAll(x, y)._sp;
    _count_table = sp.tabulationTwoDimTable();
    _response_table = sp.responseCharTwoDimTable();
    Log.info(_count_table.toString(2, false));
    Log.info(_response_table.toString(2, false));
    return sp;
}
Also used : Vec(water.fvec.Vec) Interaction(hex.Interaction) H2OIllegalArgumentException(water.exceptions.H2OIllegalArgumentException)

Aggregations

Interaction (hex.Interaction)2 JobV3 (water.api.schemas3.JobV3)1 H2OIllegalArgumentException (water.exceptions.H2OIllegalArgumentException)1 Vec (water.fvec.Vec)1