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


Java Model类代码示例

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


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

示例1: reconfigureModel

import com.feedzai.fos.api.Model; //导入依赖的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

示例2: train

import com.feedzai.fos.api.Model; //导入依赖的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

示例3: addModel

import com.feedzai.fos.api.Model; //导入依赖的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

示例4: addModel

import com.feedzai.fos.api.Model; //导入依赖的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

示例5: trainFile

import com.feedzai.fos.api.Model; //导入依赖的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

示例6: getModelDescriptor

import com.feedzai.fos.api.Model; //导入依赖的package包/类
/**
 * Returns a new {@link com.feedzai.fos.api.ModelDescriptor} for the given {@code model} and {@code file}.
 *
 * @param model     The {@link Model} with the classifier.
 * @param modelFile The file where the model will be saved.
 * @return          A new {@link com.feedzai.fos.api.ModelDescriptor}
 * @throws FOSException If the given {@code model} is of an unknown instance.
 */
private ModelDescriptor getModelDescriptor(Model model, File modelFile) throws FOSException {
    if (model instanceof ModelBinary) {
        return new ModelDescriptor(ModelDescriptor.Format.BINARY, modelFile.getAbsolutePath());
    } else if (model instanceof ModelPMML) {
        return new ModelDescriptor(ModelDescriptor.Format.PMML, modelFile.getAbsolutePath());
    } else {
        throw new FOSException("Unsupported Model type '" + model.getClass().getSimpleName() + "'.");
    }
}
 
开发者ID:feedzai,项目名称:fos-weka,代码行数:18,代码来源:WekaManager.java

示例7: train

import com.feedzai.fos.api.Model; //导入依赖的package包/类
@Override
public Model train(ModelConfig config,List<Object[]> instances) throws FOSException {
    try {
        File instanceFile = writeInstancesToTempFile(instances, config.getAttributes());
        return trainFile(config, instanceFile.getAbsolutePath());
    } catch (IOException e) {
        throw new FOSException(e);
    }
}
 
开发者ID:feedzai,项目名称:fos-r,代码行数:10,代码来源:RManager.java

示例8: addModel

import com.feedzai.fos.api.Model; //导入依赖的package包/类
@Override
public UUID addModel(ModelConfig modelConfig, Model binary) throws FOSException {
    try {
        return manager.addModel(modelConfig, binary);
    } catch (RemoteException e) {
        throw new FOSException(e);
    }
}
 
开发者ID:feedzai,项目名称:fos-core,代码行数:9,代码来源:FOSManagerAdapter.java

示例9: reconfigureModel

import com.feedzai.fos.api.Model; //导入依赖的package包/类
@Override
public void reconfigureModel(UUID uuid, ModelConfig modelConfig, Model bytes) throws FOSException {
    try {
        manager.reconfigureModel(uuid, modelConfig, bytes);
    } catch (RemoteException e) {
        throw new FOSException(e);
    }
}
 
开发者ID:feedzai,项目名称:fos-core,代码行数:9,代码来源:FOSManagerAdapter.java

示例10: train

import com.feedzai.fos.api.Model; //导入依赖的package包/类
@Override
public Model train(ModelConfig modelConfig, List<Object[]> objects) throws FOSException {
    try {
        return manager.train(modelConfig, objects);
    } catch (RemoteException e) {
        throw new FOSException(e);
    }

}
 
开发者ID:feedzai,项目名称:fos-core,代码行数:10,代码来源:FOSManagerAdapter.java

示例11: trainFile

import com.feedzai.fos.api.Model; //导入依赖的package包/类
@Override
public Model trainFile(ModelConfig modelConfig, String s) throws FOSException {
    try {
        return manager.trainFile(modelConfig, s);
    } catch (RemoteException e) {
        throw new FOSException(e);
    }

}
 
开发者ID:feedzai,项目名称:fos-core,代码行数:10,代码来源:FOSManagerAdapter.java

示例12: trainAndAdd

import com.feedzai.fos.api.Model; //导入依赖的package包/类
@Override
public synchronized UUID trainAndAdd(ModelConfig config, List<Object[]> instances) throws FOSException {
    Model trainedModel = train(config, instances);
    return addModel(config, trainedModel);
}
 
开发者ID:feedzai,项目名称:fos-weka,代码行数:6,代码来源:WekaManager.java

示例13: trainAndAddFile

import com.feedzai.fos.api.Model; //导入依赖的package包/类
@Override
public synchronized UUID trainAndAddFile(ModelConfig config, String path) throws FOSException {
    Model trainedModel = trainFile(config, path);
    return addModel(config, trainedModel);
}
 
开发者ID:feedzai,项目名称:fos-weka,代码行数:6,代码来源:WekaManager.java

示例14: reconfigureModel

import com.feedzai.fos.api.Model; //导入依赖的package包/类
@Override
public synchronized void reconfigureModel(UUID modelId, ModelConfig modelConfig, Model model) throws FOSException {
    throw new FOSException("Model reconfiguration not yet supported for R");
}
 
开发者ID:feedzai,项目名称:fos-r,代码行数:5,代码来源:RManager.java

示例15: testDelegation

import com.feedzai.fos.api.Model; //导入依赖的package包/类
@Test
public void testDelegation() throws Exception {
    UUID dummy = UUID.nameUUIDFromBytes(new byte[0]);
    EasyMock.expect(innerManager.listModels()).andReturn(null).once();
    EasyMock.expect(innerManager.addModel(null, (ModelDescriptor) null)).andReturn(dummy).once();
    EasyMock.expect(innerManager.addModel(null, (Model) null)).andReturn(dummy).once();
    EasyMock.expect(innerManager.getScorer()).andReturn(null).once();
    EasyMock.expect(innerManager.train(null,null)).andReturn(null).once();
    EasyMock.expect(innerManager.trainAndAdd(null, null)).andReturn(dummy).once();
    innerManager.removeModel(dummy);
    EasyMock.expectLastCall().once();


    innerManager.close();
    EasyMock.expectLastCall().once();

    innerManager.reconfigureModel(dummy, null);
    EasyMock.expectLastCall().once();

    innerManager.reconfigureModel(dummy, null, (ModelDescriptor) null);
    EasyMock.expectLastCall().once();

    innerManager.reconfigureModel(dummy, null, (Model) null);
    EasyMock.expectLastCall().once();

    innerManager.save(dummy, null);
    EasyMock.expectLastCall().once();

    PowerMock.replay(innerManager);


    RemoteManager remote = new RemoteManager(innerManager);
    remote.removeModel(dummy);
    remote.close();
    remote.reconfigureModel(dummy, null);
    remote.reconfigureModel(dummy, null, (ModelDescriptor) null);
    remote.reconfigureModel(dummy, null, (Model) null);
    remote.listModels();
    remote.addModel(null, (ModelDescriptor) null);
    remote.addModel(null, (Model) null);
    remote.train(null,null);
    remote.trainAndAdd(null,null);
    remote.save(dummy, null);

    PowerMock.verify(innerManager);
}
 
开发者ID:feedzai,项目名称:fos-core,代码行数:47,代码来源:RemoteClassifierManagerTest.java


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