Search in sources :

Example 1 with PartialDependence

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

the class ModelsHandler method makePartialDependence.

// called from the RequestServer through reflection
@SuppressWarnings("unused")
public JobV3 makePartialDependence(int version, PartialDependenceV3 s) {
    PartialDependence partialDependence;
    if (s.destination_key != null)
        partialDependence = new PartialDependence(s.destination_key.key());
    else
        partialDependence = new PartialDependence(Key.<PartialDependence>make());
    //fill frame_id/model_id/nbins/etc.
    s.fillImpl(partialDependence);
    return new JobV3(partialDependence.execImpl());
}
Also used : PartialDependence(hex.PartialDependence)

Example 2 with PartialDependence

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

the class PartialDependenceTest method prostateBinary.

@Test
public void prostateBinary() {
    Frame fr = null;
    GBMModel model = null;
    PartialDependence partialDependence = null;
    try {
        // Frame
        fr = parse_test_file("smalldata/prostate/prostate.csv");
        for (String s : new String[] { "RACE", "GLEASON", "DPROS", "DCAPS", "CAPSULE" }) {
            Vec v = fr.remove(s);
            fr.add(s, v.toCategoricalVec());
            v.remove();
        }
        DKV.put(fr);
        // Model
        GBMModel.GBMParameters parms = new GBMModel.GBMParameters();
        parms._train = fr._key;
        parms._ignored_columns = new String[] { "ID" };
        parms._response_column = "CAPSULE";
        model = new GBM(parms).trainModel().get();
        // PartialDependence
        partialDependence = new PartialDependence(Key.<PartialDependence>make());
        //      partialDependence._cols = model._output._names;
        partialDependence._nbins = 10;
        partialDependence._model_id = (Key) model._key;
        partialDependence._frame_id = fr._key;
        partialDependence.execImpl().get();
        for (TwoDimTable t : partialDependence._partial_dependence_data) Log.info(t);
    } finally {
        if (fr != null)
            fr.remove();
        if (model != null)
            model.remove();
        if (partialDependence != null)
            partialDependence.remove();
    }
}
Also used : PartialDependence(hex.PartialDependence) Frame(water.fvec.Frame) GBMModel(hex.tree.gbm.GBMModel) GBM(hex.tree.gbm.GBM) TwoDimTable(water.util.TwoDimTable) Vec(water.fvec.Vec) Test(org.junit.Test)

Example 3 with PartialDependence

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

the class PartialDependenceTest method prostateRegression.

@Test
public void prostateRegression() {
    Frame fr = null;
    GBMModel model = null;
    PartialDependence partialDependence = null;
    try {
        // Frame
        fr = parse_test_file("smalldata/prostate/prostate.csv");
        for (String s : new String[] { "RACE", "GLEASON", "DPROS", "DCAPS", "CAPSULE" }) {
            Vec v = fr.remove(s);
            fr.add(s, v.toCategoricalVec());
            v.remove();
        }
        DKV.put(fr);
        // Model
        GBMModel.GBMParameters parms = new GBMModel.GBMParameters();
        parms._train = fr._key;
        parms._ignored_columns = new String[] { "ID" };
        parms._response_column = "AGE";
        model = new GBM(parms).trainModel().get();
        // PartialDependence
        partialDependence = new PartialDependence(Key.<PartialDependence>make());
        partialDependence._nbins = 10;
        partialDependence._model_id = (Key) model._key;
        partialDependence._frame_id = fr._key;
        partialDependence.execImpl().get();
        for (TwoDimTable t : partialDependence._partial_dependence_data) Log.info(t);
    } finally {
        if (fr != null)
            fr.remove();
        if (model != null)
            model.remove();
        if (partialDependence != null)
            partialDependence.remove();
    }
}
Also used : PartialDependence(hex.PartialDependence) Frame(water.fvec.Frame) GBMModel(hex.tree.gbm.GBMModel) GBM(hex.tree.gbm.GBM) TwoDimTable(water.util.TwoDimTable) Vec(water.fvec.Vec) Test(org.junit.Test)

Example 4 with PartialDependence

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

the class PartialDependenceTest method weatherBinary.

@Test
public void weatherBinary() {
    Frame fr = null;
    GBMModel model = null;
    PartialDependence partialDependence = null;
    try {
        // Frame
        fr = parse_test_file("smalldata/junit/weather.csv");
        // Model
        GBMModel.GBMParameters parms = new GBMModel.GBMParameters();
        parms._train = fr._key;
        parms._ignored_columns = new String[] { "Date", "RISK_MM", "EvapMM" };
        parms._response_column = "RainTomorrow";
        model = new GBM(parms).trainModel().get();
        // PartialDependence
        partialDependence = new PartialDependence(Key.<PartialDependence>make());
        partialDependence._nbins = 33;
        partialDependence._cols = new String[] { "Sunshine", "MaxWindPeriod", "WindSpeed9am" };
        partialDependence._model_id = (Key) model._key;
        partialDependence._frame_id = fr._key;
        partialDependence.execImpl().get();
        for (TwoDimTable t : partialDependence._partial_dependence_data) Log.info(t);
    } finally {
        if (fr != null)
            fr.remove();
        if (model != null)
            model.remove();
        if (partialDependence != null)
            partialDependence.remove();
    }
}
Also used : PartialDependence(hex.PartialDependence) Frame(water.fvec.Frame) GBMModel(hex.tree.gbm.GBMModel) GBM(hex.tree.gbm.GBM) TwoDimTable(water.util.TwoDimTable) Test(org.junit.Test)

Example 5 with PartialDependence

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

the class PartialDependenceTest method prostateBinaryPickCols.

@Test
public void prostateBinaryPickCols() {
    Frame fr = null;
    GBMModel model = null;
    PartialDependence partialDependence = null;
    try {
        // Frame
        fr = parse_test_file("smalldata/prostate/prostate.csv");
        for (String s : new String[] { "RACE", "GLEASON", "DPROS", "DCAPS", "CAPSULE" }) {
            Vec v = fr.remove(s);
            fr.add(s, v.toCategoricalVec());
            v.remove();
        }
        DKV.put(fr);
        // Model
        GBMModel.GBMParameters parms = new GBMModel.GBMParameters();
        parms._train = fr._key;
        parms._ignored_columns = new String[] { "ID" };
        parms._response_column = "CAPSULE";
        model = new GBM(parms).trainModel().get();
        // PartialDependence
        partialDependence = new PartialDependence(Key.<PartialDependence>make());
        //pick columns manually
        partialDependence._cols = new String[] { "DPROS", "GLEASON" };
        partialDependence._nbins = 10;
        partialDependence._model_id = (Key) model._key;
        partialDependence._frame_id = fr._key;
        partialDependence.execImpl().get();
        for (TwoDimTable t : partialDependence._partial_dependence_data) Log.info(t);
        Assert.assertTrue(partialDependence._partial_dependence_data.length == 2);
    } finally {
        if (fr != null)
            fr.remove();
        if (model != null)
            model.remove();
        if (partialDependence != null)
            partialDependence.remove();
    }
}
Also used : PartialDependence(hex.PartialDependence) Frame(water.fvec.Frame) GBMModel(hex.tree.gbm.GBMModel) GBM(hex.tree.gbm.GBM) TwoDimTable(water.util.TwoDimTable) Vec(water.fvec.Vec) Test(org.junit.Test)

Aggregations

PartialDependence (hex.PartialDependence)6 Frame (water.fvec.Frame)5 GBM (hex.tree.gbm.GBM)4 GBMModel (hex.tree.gbm.GBMModel)4 Test (org.junit.Test)4 TwoDimTable (water.util.TwoDimTable)4 Vec (water.fvec.Vec)3 H2OIllegalArgumentException (water.exceptions.H2OIllegalArgumentException)1