当前位置: 首页>>代码示例>>Java>>正文


Java ModelConfig类代码示例

本文整理汇总了Java中com.feedzai.fos.api.ModelConfig的典型用法代码示例。如果您正苦于以下问题:Java ModelConfig类的具体用法?Java ModelConfig怎么用?Java ModelConfig使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ModelConfig类属于com.feedzai.fos.api包,在下文中一共展示了ModelConfig类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testMultipleModels

import com.feedzai.fos.api.ModelConfig; //导入依赖的package包/类
@Test
public void testMultipleModels() throws FOSException {
    ModelConfig modelConfig = new ModelConfig();
    modelConfig.setProperty(WekaModelConfig.CLASSIFIER_IMPL, Vote.class.getName());
    modelConfig.setProperty(WekaModelConfig.CLASSIFIER_CONFIG, "-R MAX -B \""+J48.class.getName()+"\" -B \"" + NaiveBayes.class.getName() + "\"");

    MultipleClassifiersCombiner classifier = (MultipleClassifiersCombiner)WekaClassifierFactory.create(modelConfig);
    Assert.assertEquals(2,classifier.getClassifiers().length);
    Assert.assertEquals(J48.class,classifier.getClassifiers()[0].getClass());
    Assert.assertEquals(NaiveBayes.class,classifier.getClassifiers()[1].getClass());
}
 
开发者ID:feedzai,项目名称:fos-weka,代码行数:12,代码来源:WekaClassifierFactoryTest.java

示例2: reconfigureModel

import com.feedzai.fos.api.ModelConfig; //导入依赖的package包/类
@Override
public synchronized void reconfigureModel(UUID modelId, ModelConfig modelConfig, Model model) throws FOSException {
    try {
        File modelFile = createModelFile(wekaManagerConfig.getHeaderLocation(), modelId, model);

        WekaModelConfig wekaModelConfig = this.modelConfigs.get(modelId);
        wekaModelConfig.update(modelConfig);
        ModelDescriptor descriptor = getModelDescriptor(model, modelFile);
        wekaModelConfig.setModelDescriptor(descriptor);

        wekaScorer.addOrUpdate(wekaModelConfig);
        saveConfiguration();
        logger.debug("Model {} reconfigured", modelId);
    } catch (IOException e) {
        throw new FOSException(e);
    }
}
 
开发者ID:feedzai,项目名称:fos-weka,代码行数:18,代码来源:WekaManager.java

示例3: train

import com.feedzai.fos.api.ModelConfig; //导入依赖的package包/类
@Override
public Model train(ModelConfig config, List<Object[]> instances) throws FOSException {
    checkNotNull(instances, "Instances must be supplied");
    checkNotNull(config, "Config must be supplied");
    long time = System.currentTimeMillis();
    WekaModelConfig wekaModelConfig = new WekaModelConfig(config, wekaManagerConfig);
    Classifier classifier = WekaClassifierFactory.create(config);
    FastVector attributes = WekaUtils.instanceFields2Attributes(wekaModelConfig.getClassIndex(), config.getAttributes());
    InstanceSetter[] instanceSetters = WekaUtils.instanceFields2ValueSetters(config.getAttributes(), InstanceType.TRAINING);

    Instances wekaInstances = new Instances(config.getProperty(WekaModelConfig.CLASSIFIER_IMPL), attributes, instances.size());

    for (Object[] objects : instances) {
        wekaInstances.add(WekaUtils.objectArray2Instance(objects, instanceSetters, attributes));
    }

    trainClassifier(wekaModelConfig.getClassIndex(), classifier, wekaInstances);

    final byte[] bytes = SerializationUtils.serialize(classifier);

    logger.debug("Trained model with {} instances in {}ms", instances.size(), (System.currentTimeMillis() - time));

    return new ModelBinary(bytes);
}
 
开发者ID:feedzai,项目名称:fos-weka,代码行数:25,代码来源:WekaManager.java

示例4: create

import com.feedzai.fos.api.ModelConfig; //导入依赖的package包/类
/**
 * @param modelConfig model config should contain the wanted classifier
 * @return instantiated classifier
 * @throws FOSException if it has failed to create a classifier
 */
public static Classifier create(ModelConfig modelConfig) throws FOSException {
    checkNotNull(modelConfig, "Model config cannot be null");

    String classifierNames = modelConfig.getProperty(WekaModelConfig.CLASSIFIER_IMPL);

    try {
        Classifier classifier = (Classifier) Class.forName(modelConfig.getProperty(WekaModelConfig.CLASSIFIER_IMPL)).newInstance();

        classifier.setOptions(weka.core.Utils.splitOptions(StringUtils.defaultString(modelConfig.getProperty(WekaModelConfig.CLASSIFIER_CONFIG))));

        return classifier;
    } catch (Exception e) {
        throw new FOSException(e);
    }
}
 
开发者ID:feedzai,项目名称:fos-weka,代码行数:21,代码来源:WekaClassifierFactory.java

示例5: testScoring

import com.feedzai.fos.api.ModelConfig; //导入依赖的package包/类
@Test
public void testScoring() throws Exception {
    BaseConfiguration configuration = new BaseConfiguration();
    configuration.setProperty(GenericObjectPoolConfig.class.getName() + ".minIdle", 10);
    configuration.setProperty(GenericObjectPoolConfig.class.getName() + ".maxActive", 10);
    configuration.setProperty(FosConfig.HEADER_LOCATION, "target/test-classes/models/threadsafe");
    configuration.setProperty(FosConfig.FACTORY_NAME, WekaManagerFactory.class.getName());

    FileInputStream fis = new FileInputStream("target/test-classes/models/threadsafe/test.header");
    String modelConfigJson = IOUtils.toString(fis);
    ObjectMapper mapper = new ObjectMapper();

    ModelConfig modelConfig = mapper.readValue(modelConfigJson, ModelConfig.class);


    WekaManagerConfig wekaManagerConfig = new WekaManagerConfig(new FosConfig(configuration));
    WekaThreadSafeScorer wekaThreadSafeScorer = new WekaThreadSafeScorerPool(new WekaModelConfig(modelConfig,wekaManagerConfig), wekaManagerConfig);

    double[] score = wekaThreadSafeScorer.score(new Object[]{1.5, 0, "gray", "positive"});
    assertEquals(2, score.length);
    assertEquals(1.0, score[0] + score[1], 0.001);
}
 
开发者ID:feedzai,项目名称:fos-weka,代码行数:23,代码来源:WekaThreadSafeScorerPoolTest.java

示例6: addModel

import com.feedzai.fos.api.ModelConfig; //导入依赖的package包/类
@Override
public synchronized UUID addModel(ModelConfig config, Model model) throws FOSException {
    if (!(model instanceof ModelBinary)) {
        throw new FOSException("Currently FOS-R only supports binary models.");
    }

    try {
        UUID uuid = getUuid(config);

        File file = createModelFile(modelConfigs.get(uuid).getModel(), uuid, model);

        RModelConfig rModelConfig = new RModelConfig(config, rManagerConfig);
        rModelConfig.setId(uuid);
        rModelConfig.setModel(file);

        modelConfigs.put(uuid, rModelConfig);
        rScorer.addOrUpdate(rModelConfig);


        return uuid;
    } catch (IOException e) {
        throw new FOSException(e);
    }
}
 
开发者ID:feedzai,项目名称:fos-r,代码行数:25,代码来源:RManager.java

示例7: testUncompressed

import com.feedzai.fos.api.ModelConfig; //导入依赖的package包/类
@Test
public void testUncompressed() throws Exception {
    ModelConfig modelConfig = setupConfig();
    RManager rManager = setupManager();

    UUID uuid  = rManager.trainAndAdd(modelConfig, RIntegrationTest.getTrainingInstances());

    File targetFile = Files.createTempFile("targetPMML", ".xml").toFile();

    // Save the model as PMML and load it.
    rManager.saveAsPMML(uuid, targetFile.getAbsolutePath(), false);

    try (FileInputStream fis = new FileInputStream(targetFile)) {
        JAXBUtil.unmarshalPMML(new StreamSource(fis));
    }

    targetFile.delete();
}
 
开发者ID:feedzai,项目名称:fos-r,代码行数:19,代码来源:RandomForestPMMLProducerConsumerTest.java

示例8: testCompressed

import com.feedzai.fos.api.ModelConfig; //导入依赖的package包/类
@Test
public void testCompressed() throws Exception {
    ModelConfig modelConfig = setupConfig();
    RManager rManager = setupManager();

    UUID uuid  = rManager.trainAndAdd(modelConfig, RIntegrationTest.getTrainingInstances());

    File targetFile = Files.createTempFile("targetPMML", ".xml").toFile();

    // Save the model as PMML and load it.
    rManager.saveAsPMML(uuid, targetFile.getAbsolutePath(), true);

    try (FileInputStream fis = new FileInputStream(targetFile);
         GZIPInputStream gis = new GZIPInputStream(fis)) {

        JAXBUtil.unmarshalPMML(new StreamSource(gis));
    }

    targetFile.delete();
}
 
开发者ID:feedzai,项目名称:fos-r,代码行数:21,代码来源:RandomForestPMMLProducerConsumerTest.java

示例9: addModel

import com.feedzai.fos.api.ModelConfig; //导入依赖的package包/类
@Override
public synchronized UUID addModel(ModelConfig config, Model model) throws FOSException {
    File modelFile;

    try {
        modelFile = createModelFile(wekaManagerConfig.getHeaderLocation(), getUuid(config), model);
    } catch (IOException e) {
        throw new FOSException("Unable to create model file", e);
    }

    return addModel(config, getModelDescriptor(model, modelFile));
}
 
开发者ID:feedzai,项目名称:fos-weka,代码行数:13,代码来源:WekaManager.java

示例10: listModels

import com.feedzai.fos.api.ModelConfig; //导入依赖的package包/类
@Override
@NotNull
public synchronized Map<UUID, ModelConfig> listModels() {
    Map<UUID, ModelConfig> result = new HashMap<>(modelConfigs.size());
    for (Map.Entry<UUID, WekaModelConfig> entry : modelConfigs.entrySet()) {
        result.put(entry.getKey(), entry.getValue().getModelConfig());
    }

    return result;
}
 
开发者ID:feedzai,项目名称:fos-weka,代码行数:11,代码来源:WekaManager.java

示例11: trainFile

import com.feedzai.fos.api.ModelConfig; //导入依赖的package包/类
@Override
public Model trainFile(ModelConfig config, String path) throws FOSException {
    checkNotNull(path, "Config must be supplied");
    checkNotNull(path, "Path must be supplied");

    long time = System.currentTimeMillis();
    WekaModelConfig wekaModelConfig = new WekaModelConfig(config, wekaManagerConfig);
    Classifier classifier = WekaClassifierFactory.create(config);
    List<Attribute> attributeList = config.getAttributes();
    FastVector attributes = WekaUtils.instanceFields2Attributes(wekaModelConfig.getClassIndex(), config.getAttributes());
    InstanceSetter[] instanceSetters = WekaUtils.instanceFields2ValueSetters(config.getAttributes(), InstanceType.TRAINING);

    List<Instance> instances = new ArrayList();

    String[] line;
    try {
        FileReader fileReader = new FileReader(path);
        CSVReader csvReader = new CSVReader(fileReader);
        while ((line = csvReader.readNext()) != null) {
            // parsing is done by InstanceSetter's
            instances.add(WekaUtils.objectArray2Instance(line, instanceSetters, attributes));
        }

    } catch (Exception e) {
        throw new FOSException(e.getMessage(), e);
    }

    Instances wekaInstances = new Instances(config.getProperty(WekaModelConfig.CLASSIFIER_IMPL), attributes, instances.size());

    for (Instance instance : instances) {
        wekaInstances.add(instance);
    }

    trainClassifier(wekaModelConfig.getClassIndex(), classifier, wekaInstances);

    final byte[] bytes = SerializationUtils.serialize(classifier);
    logger.debug("Trained model with {} instances in {}ms", instances.size(), (System.currentTimeMillis() - time));

    return new ModelBinary( bytes);
}
 
开发者ID:feedzai,项目名称:fos-weka,代码行数:41,代码来源:WekaManager.java

示例12: testOneModel

import com.feedzai.fos.api.ModelConfig; //导入依赖的package包/类
@Test
public void testOneModel() throws FOSException {
    ModelConfig modelConfig = new ModelConfig();
    modelConfig.setProperty(WekaModelConfig.CLASSIFIER_IMPL, J48.class.getName());

    Classifier classifier = WekaClassifierFactory.create(modelConfig);
    Assert.assertEquals(J48.class, classifier.getClass());
}
 
开发者ID:feedzai,项目名称:fos-weka,代码行数:9,代码来源:WekaClassifierFactoryTest.java

示例13: testFastRandomForestModel

import com.feedzai.fos.api.ModelConfig; //导入依赖的package包/类
@Test
public void testFastRandomForestModel() throws FOSException {
    ModelConfig modelConfig = new ModelConfig();
    modelConfig.setProperty(WekaModelConfig.CLASSIFIER_IMPL, "hr.irb.fastRandomForest.FastRandomForest");

    Classifier classifier = WekaClassifierFactory.create(modelConfig);

    Assert.assertEquals("A FastRandomForest model was created", FastRandomForest.class, classifier.getClass());
}
 
开发者ID:feedzai,项目名称:fos-weka,代码行数:10,代码来源:WekaClassifierFactoryTest.java

示例14: reconfigureModel

import com.feedzai.fos.api.ModelConfig; //导入依赖的package包/类
@Override
public synchronized void reconfigureModel(UUID modelId, ModelConfig modelConfig) throws FOSException {
    RModelConfig rModelConfig = this.modelConfigs.get(modelId);
    rModelConfig.update(modelConfig);

    rScorer.addOrUpdate(rModelConfig);
}
 
开发者ID:feedzai,项目名称:fos-r,代码行数:8,代码来源:RManager.java

示例15: listModels

import com.feedzai.fos.api.ModelConfig; //导入依赖的package包/类
@Override
@NotNull
public synchronized Map<UUID, ModelConfig> listModels() {
    Map<UUID, ModelConfig> result = new HashMap<>(modelConfigs.size());
    for (Map.Entry<UUID, RModelConfig> entry : modelConfigs.entrySet()) {
        result.put(entry.getKey(), entry.getValue().getModelConfig());
    }

    return result;
}
 
开发者ID:feedzai,项目名称:fos-r,代码行数:11,代码来源:RManager.java


注:本文中的com.feedzai.fos.api.ModelConfig类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。