Search in sources :

Example 1 with ModelConfig

use of ml.shifu.shifu.container.obj.ModelConfig in project shifu by ShifuML.

the class PurifyDataUDFTest method setUp.

@BeforeClass
public void setUp() throws Exception {
    instanceC = new PurifyDataUDF("LOCAL", "src/test/resources/example/cancer-judgement/ModelStore/ModelSet1/ModelConfig.json", "src/test/resources/example/cancer-judgement/ModelStore/ModelSet1/ColumnConfig.json", "EvalA");
    instanceB = new PurifyDataUDF("LOCAL", "src/test/resources/example/cancer-judgement/ModelStore/ModelSet1/ModelConfig.json", "src/test/resources/example/cancer-judgement/ModelStore/ModelSet1/ColumnConfig.json");
    ModelConfig modelConfig = CommonUtils.loadModelConfig("src/test/resources/example/cancer-judgement/ModelStore/ModelSet1/ModelConfig.json", SourceType.LOCAL);
    modelConfig.getDataSet().setFilterExpressions("diagnosis == \"B\"");
    modelConfig.getEvalConfigByName("EvalA").getDataSet().setFilterExpressions("column_11");
    Writer writer = ShifuFileUtils.getWriter("ModelConfig.json", SourceType.LOCAL);
    JSONUtils.writeValue(writer, modelConfig);
    writer.close();
    instanceA = new PurifyDataUDF("LOCAL", "ModelConfig.json", "src/test/resources/example/cancer-judgement/ModelStore/ModelSet1/ColumnConfig.json");
    instanceD = new PurifyDataUDF("LOCAL", "ModelConfig.json", "src/test/resources/example/cancer-judgement/ModelStore/ModelSet1/ColumnConfig.json", "EvalA");
}
Also used : ModelConfig(ml.shifu.shifu.container.obj.ModelConfig) Writer(java.io.Writer) BeforeClass(org.testng.annotations.BeforeClass)

Example 2 with ModelConfig

use of ml.shifu.shifu.container.obj.ModelConfig in project shifu by ShifuML.

the class CommonUtilsTest method loadModelConfigTest.

@Test
public void loadModelConfigTest() throws JsonGenerationException, JsonMappingException, IOException {
    ModelConfig config = ModelConfig.createInitModelConfig(".", ALGORITHM.NN, "test", false);
    config.setModelSetName("shifu");
    jsonMapper.writerWithDefaultPrettyPrinter().writeValue(new File("ModelConfig.json"), config);
    ModelConfig anotherConfig = CommonUtils.loadModelConfig();
    Assert.assertEquals(config, anotherConfig);
    FileUtils.deleteQuietly(new File("ModelConfig.json"));
}
Also used : ModelConfig(ml.shifu.shifu.container.obj.ModelConfig) File(java.io.File) Test(org.testng.annotations.Test)

Example 3 with ModelConfig

use of ml.shifu.shifu.container.obj.ModelConfig in project shifu by ShifuML.

the class CommonUtilsTest method testLoadModelConfig.

@Test
public void testLoadModelConfig() throws IOException {
    ModelConfig config = CommonUtils.loadModelConfig("src/test/resources/example/wdbc/wdbcModelSetLocal/ModelConfig.json", SourceType.LOCAL);
    Assert.assertEquals(config.getDataSet().getNegTags().get(0), "B");
}
Also used : ModelConfig(ml.shifu.shifu.container.obj.ModelConfig) Test(org.testng.annotations.Test)

Example 4 with ModelConfig

use of ml.shifu.shifu.container.obj.ModelConfig in project shifu by ShifuML.

the class BaggingSubsampleUDFTest method setUp.

@BeforeClass
public void setUp() throws Exception {
    File file = new File("udf");
    if (!file.exists()) {
        FileUtils.forceMkdir(file);
    }
    ModelConfig modelConfig = CommonUtils.loadModelConfig("src/test/resources/example/cancer-judgement/ModelStore/ModelSet1/ModelConfig.json", SourceType.LOCAL);
    List<ColumnConfig> columnConfigList = CommonUtils.loadColumnConfigList("src/test/resources/example/cancer-judgement/ModelStore/ModelSet1/ColumnConfig.json", SourceType.LOCAL);
    modelConfig.getTrain().setBaggingNum(1);
    ;
    modelConfig.getTrain().setBaggingSampleRate(2.0);
    ;
    jsonMapper.writerWithDefaultPrettyPrinter().writeValue(new File("udf/ModelConfig.json"), modelConfig);
    jsonMapper.writerWithDefaultPrettyPrinter().writeValue(new File("udf/ColumnConfig.json"), columnConfigList);
}
Also used : ModelConfig(ml.shifu.shifu.container.obj.ModelConfig) ColumnConfig(ml.shifu.shifu.container.obj.ColumnConfig) File(java.io.File) BeforeClass(org.testng.annotations.BeforeClass)

Example 5 with ModelConfig

use of ml.shifu.shifu.container.obj.ModelConfig in project shifu by ShifuML.

the class ModelDataEncodeProcessor method updateEvalEncodeDataPath.

private void updateEvalEncodeDataPath(int status, String encodeRefModel, EvalConfig evalConfig) throws IOException {
    if (status == 0 && StringUtils.isNotBlank(encodeRefModel)) {
        String delimiter = Environment.getProperty(Constants.SHIFU_OUTPUT_DATA_DELIMITER, Constants.DEFAULT_DELIMITER);
        String encodeDataPath = this.pathFinder.getEncodeDataPath(evalConfig);
        ModelConfig encodeModel = loadSubModelConfig(encodeRefModel);
        EvalConfig encodeEvalConfig = encodeModel.getEvalConfigByName(evalConfig.getName());
        if (encodeEvalConfig == null) {
            // new EvalSet, add it to encode model
            encodeEvalConfig = evalConfig.clone();
            encodeModel.getEvals().add(encodeEvalConfig);
        }
        encodeEvalConfig.getDataSet().setDataPath(encodeDataPath);
        encodeEvalConfig.getDataSet().setDataDelimiter(delimiter);
        encodeEvalConfig.getDataSet().setHeaderPath(encodeDataPath + File.separator + ".pig_header");
        encodeEvalConfig.getDataSet().setHeaderDelimiter(delimiter);
        // remove filter
        encodeEvalConfig.getDataSet().setFilterExpressions("");
        saveModelConfig(encodeRefModel, encodeModel);
    }
}
Also used : EvalConfig(ml.shifu.shifu.container.obj.EvalConfig) ModelConfig(ml.shifu.shifu.container.obj.ModelConfig)

Aggregations

ModelConfig (ml.shifu.shifu.container.obj.ModelConfig)33 Test (org.testng.annotations.Test)18 ArrayList (java.util.ArrayList)9 File (java.io.File)8 ValidateResult (ml.shifu.shifu.container.meta.ValidateResult)8 ColumnConfig (ml.shifu.shifu.container.obj.ColumnConfig)8 TrainingDataSet (ml.shifu.shifu.core.dvarsel.dataset.TrainingDataSet)4 IOException (java.io.IOException)3 EvalConfig (ml.shifu.shifu.container.obj.EvalConfig)3 NNTrainer (ml.shifu.shifu.core.alg.NNTrainer)3 BeforeClass (org.testng.annotations.BeforeClass)3 FileInputStream (java.io.FileInputStream)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Properties (java.util.Properties)2 RawSourceData (ml.shifu.shifu.container.obj.RawSourceData)2 PathFinder (ml.shifu.shifu.fs.PathFinder)2 MLDataPair (org.encog.ml.data.MLDataPair)2 BasicMLDataPair (org.encog.ml.data.basic.BasicMLDataPair)2