Search in sources :

Example 16 with Job

use of water.Job in project h2o-3 by h2oai.

the class ModelBuilderHandler method handle.

// Invoke the handler with parameters.  Can throw any exception the called handler can throw.
@Override
S handle(int version, Route route, Properties parms, String postBody) throws Exception {
    // Peek out the desired algo from the URL
    String[] ss = route._url.split("/");
    // {}/{3}/{ModelBuilders}/{gbm}/{parameters}
    String algoURLName = ss[3];
    // gbm -> GBM; deeplearning -> DeepLearning
    String algoName = ModelBuilder.algoName(algoURLName);
    String schemaDir = ModelBuilder.schemaDirectory(algoURLName);
    // Build a Model Schema and a ModelParameters Schema
    String schemaName = schemaDir + algoName + "V" + version;
    S schema = (S) TypeMap.newFreezable(schemaName);
    schema.init_meta();
    String parmName = schemaDir + algoName + "V" + version + "$" + algoName + "ParametersV" + version;
    P parmSchema = (P) TypeMap.newFreezable(parmName);
    schema.parameters = parmSchema;
    // Only here for train or validate-parms
    String handlerName = route._handler_method.getName();
    boolean doTrain = handlerName.equals("train");
    assert doTrain || handlerName.equals("validate_parameters");
    // User specified key, or make a default?
    String model_id = parms.getProperty("model_id");
    Key<Model> key = doTrain ? (model_id == null ? ModelBuilder.defaultKey(algoName) : Key.<Model>make(model_id)) : null;
    // Default Job for just this training
    Job job = doTrain ? new Job<>(key, ModelBuilder.javaName(algoURLName), algoName) : null;
    // ModelBuilder
    B builder = ModelBuilder.make(algoURLName, job, key);
    // Defaults for this builder into schema
    schema.parameters.fillFromImpl(builder._parms);
    // Overwrite with user parms
    schema.parameters.fillFromParms(parms);
    // Merged parms back over Model.Parameter object
    schema.parameters.fillImpl(builder._parms);
    // validate parameters
    builder.init(false);
    // Fill in the result Schema with the Job at least, plus any extra trainModel errors
    schema.fillFromImpl(builder);
    PojoUtils.copyProperties(schema.parameters, builder._parms, PojoUtils.FieldNaming.ORIGIN_HAS_UNDERSCORES, null, new String[] { "error_count", "messages" });
    schema.setHttpStatus(HttpResponseStatus.OK.getCode());
    if (doTrain)
        schema.job.fillFromImpl(builder.trainModel());
    return schema;
}
Also used : Model(hex.Model) Job(water.Job)

Example 17 with Job

use of water.Job in project h2o-3 by h2oai.

the class Interaction method execImpl.

public Job<Frame> execImpl(Key<Frame> dest) {
    _job = new Job(dest == null ? Key.make() : dest, Frame.class.getName(), "CreateFrame");
    Frame source_frame = DKV.getGet(_source_frame);
    assert (source_frame != null);
    if (_factor_columns == null || _factor_columns.length == 0)
        throw new IllegalArgumentException("factor_columns must be specified.");
    if (_pairwise && _factor_columns.length < 3)
        Log.info("Ignoring the pairwise option, requires 3 or more factors.");
    _factors = new int[_factor_columns.length];
    int count = 0;
    for (String v : _factor_columns) {
        int idx = source_frame.find(v);
        if (idx >= 0) {
            if (!source_frame.vecs()[idx].isCategorical()) {
                throw new IllegalArgumentException("Column " + v + " is not categorical.");
            }
            _factors[count++] = idx;
        } else {
            throw new IllegalArgumentException("Column " + v + " not found.");
        }
    }
    CreateInteractions in = new CreateInteractions(this);
    return _job.start(in, in.work());
}
Also used : Frame(water.fvec.Frame) CreateInteractions(water.fvec.CreateInteractions) Job(water.Job) PrettyPrint(water.util.PrettyPrint)

Example 18 with Job

use of water.Job in project h2o-2 by h2oai.

the class Parse2 method serve.

@Override
protected Response serve() {
    PSetup p = _source.value();
    CustomParser.ParserSetup setup = p != null ? p._setup._setup : new CustomParser.ParserSetup();
    setup._singleQuotes = _sQuotes.value();
    destination_key = Key.make(_dest.value());
    try {
        // Make a new Setup, with the 'header' flag set according to user wishes.
        Key[] keys = p._keys.toArray(new Key[p._keys.size()]);
        Job parseJob = ParseDataset2.forkParseDataset(destination_key, keys, setup, delete_on_done.value());
        job_key = parseJob.self();
        // Allow the user to specify whether to block synchronously for a response or not.
        if (_blocking.value()) {
            // block until the end of job
            parseJob.get();
            assert Job.isEnded(job_key) : "Job is still running but we already passed over its end. Job = " + job_key;
        }
        return Progress2.redirect(this, job_key, destination_key);
    } catch (Throwable e) {
        return Response.error(e);
    }
}
Also used : Job(water.Job) CustomParser(water.parser.CustomParser) Key(water.Key)

Example 19 with Job

use of water.Job in project h2o-3 by h2oai.

the class QuantileTest method testWeights2.

@Ignore
@Test
public void testWeights2() {
    //same behavior as wtd.quantile in R -> results with all weights=1 and all weights=2 don't agree (unless normwt=TRUE)
    QuantileModel kmm1;
    QuantileModel kmm2;
    Frame fr1 = null;
    Frame fr2 = null;
    try {
        fr1 = parse_test_file("smalldata/junit/weights_all_twos.csv");
        fr2 = parse_test_file("smalldata/junit/weights_all_ones.csv");
        for (QuantileModel.CombineMethod comb : new QuantileModel.CombineMethod[] { QuantileModel.CombineMethod.AVERAGE, QuantileModel.CombineMethod.LOW, QuantileModel.CombineMethod.HIGH, QuantileModel.CombineMethod.INTERPOLATE }) {
            {
                QuantileModel.QuantileParameters parms = new QuantileModel.QuantileParameters();
                parms._train = fr1._key;
                parms._combine_method = comb;
                parms._weights_column = "weight";
                Job<QuantileModel> job1 = new Quantile(parms).trainModel();
                kmm1 = job1.get();
                job1.remove();
            }
            {
                QuantileModel.QuantileParameters parms = new QuantileModel.QuantileParameters();
                parms._train = fr2._key;
                parms._combine_method = comb;
                parms._weights_column = "weight";
                Job<QuantileModel> job2 = new Quantile(parms).trainModel();
                kmm2 = job2.get();
                job2.remove();
            }
            try {
                assert (Arrays.deepEquals(kmm1._output._quantiles, kmm2._output._quantiles));
                Assert.assertTrue(Arrays.deepEquals(kmm1._output._quantiles, kmm2._output._quantiles));
            } finally {
                if (kmm1 != null)
                    kmm1.delete();
                if (kmm2 != null)
                    kmm2.delete();
            }
        }
    } finally {
        if (fr1 != null)
            fr1.remove();
        if (fr2 != null)
            fr2.remove();
    }
}
Also used : Frame(water.fvec.Frame) Job(water.Job) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

Job (water.Job)19 Frame (water.fvec.Frame)7 Test (org.junit.Test)5 Value (water.Value)3 JsonObject (dontweave.gson.JsonObject)2 Ignore (org.junit.Ignore)2 JsonArray (dontweave.gson.JsonArray)1 JsonElement (dontweave.gson.JsonElement)1 Model (hex.Model)1 NeuralNet (hex.NeuralNet)1 SplitFrame (hex.SplitFrame)1 DeepLearningModel (hex.deeplearning.DeepLearningModel)1 DRFModel (hex.drf.DRF.DRFModel)1 Quantile (hex.quantile.Quantile)1 QuantileModel (hex.quantile.QuantileModel)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Date (java.util.Date)1 Futures (water.Futures)1 Key (water.Key)1 MRTask (water.MRTask)1