Search in sources :

Example 1 with Evaluator

use of org.jpmml.evaluator.Evaluator in project openscoring by openscoring.

the class ModelRegistry method load.

@SuppressWarnings(value = { "resource" })
public Model load(InputStream is) throws Exception {
    CountingInputStream countingIs = new CountingInputStream(is);
    HashingInputStream hashingIs = new HashingInputStream(Hashing.md5(), countingIs);
    PMML pmml = unmarshal(hashingIs, this.validate);
    this.visitorBattery.applyTo(pmml);
    ModelEvaluatorFactory modelEvaluatorFactory = this.modelEvaluatorFactory;
    Evaluator evaluator = modelEvaluatorFactory.newModelEvaluator(pmml);
    evaluator.verify();
    Model model = new Model(evaluator);
    model.putProperty(Model.PROPERTY_FILE_SIZE, countingIs.getCount());
    model.putProperty(Model.PROPERTY_FILE_MD5SUM, (hashingIs.hash()).toString());
    return model;
}
Also used : CountingInputStream(com.google.common.io.CountingInputStream) PMML(org.dmg.pmml.PMML) HasPMML(org.jpmml.evaluator.HasPMML) ModelEvaluatorFactory(org.jpmml.evaluator.ModelEvaluatorFactory) Evaluator(org.jpmml.evaluator.Evaluator) HashingInputStream(com.google.common.hash.HashingInputStream)

Example 2 with Evaluator

use of org.jpmml.evaluator.Evaluator in project registry by hortonworks.

the class MLModelRegistryService method doGetInputFieldsFromPMMLStream.

private List<MLModelField> doGetInputFieldsFromPMMLStream(String pmmlContents) throws SAXException, JAXBException {
    final List<MLModelField> fieldNames = new ArrayList<>();
    PMMLManager pmmlManager = new PMMLManager(IOUtil.unmarshal(new ByteArrayInputStream(pmmlContents.getBytes())));
    Evaluator modelEvaluator = (ModelEvaluator<?>) pmmlManager.getModelManager(null, ModelEvaluatorFactory.getInstance());
    for (FieldName predictedField : modelEvaluator.getActiveFields()) {
        fieldNames.add(getModelField(modelEvaluator.getDataField(predictedField)));
    }
    return fieldNames;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ModelEvaluator(org.jpmml.evaluator.ModelEvaluator) ArrayList(java.util.ArrayList) Evaluator(org.jpmml.evaluator.Evaluator) ModelEvaluator(org.jpmml.evaluator.ModelEvaluator) FieldName(org.dmg.pmml.FieldName) PMMLManager(org.jpmml.manager.PMMLManager)

Example 3 with Evaluator

use of org.jpmml.evaluator.Evaluator in project registry by hortonworks.

the class MLModelRegistryService method doGetOutputFieldsForPMMLStream.

private List<MLModelField> doGetOutputFieldsForPMMLStream(String pmmlContents) throws SAXException, JAXBException {
    List<MLModelField> fieldNames = new ArrayList<>();
    PMMLManager pmmlManager = new PMMLManager(IOUtil.unmarshal(new ByteArrayInputStream(pmmlContents.getBytes())));
    Evaluator modelEvaluator = (ModelEvaluator<?>) pmmlManager.getModelManager(null, ModelEvaluatorFactory.getInstance());
    modelEvaluator.getPredictedFields().forEach((f) -> fieldNames.add(getModelField(modelEvaluator.getDataField(f))));
    modelEvaluator.getOutputFields().forEach((f) -> {
        OutputField outputField = modelEvaluator.getOutputField(f);
        ResultFeatureType resultFeatureType = outputField.getFeature();
        if (resultFeatureType != ResultFeatureType.PREDICTED_VALUE && resultFeatureType != ResultFeatureType.PREDICTED_DISPLAY_VALUE) {
            fieldNames.add(getModelField(outputField));
        }
    });
    return fieldNames;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ModelEvaluator(org.jpmml.evaluator.ModelEvaluator) ArrayList(java.util.ArrayList) OutputField(org.dmg.pmml.OutputField) ResultFeatureType(org.dmg.pmml.ResultFeatureType) Evaluator(org.jpmml.evaluator.Evaluator) ModelEvaluator(org.jpmml.evaluator.ModelEvaluator) PMMLManager(org.jpmml.manager.PMMLManager)

Example 4 with Evaluator

use of org.jpmml.evaluator.Evaluator in project streamline by hortonworks.

the class MLModelRegistryService method doGetInputFieldsFromPMMLStream.

private List<MLModelField> doGetInputFieldsFromPMMLStream(String pmmlContents) throws SAXException, JAXBException, UnsupportedEncodingException {
    final List<MLModelField> fieldNames = new ArrayList<>();
    PMMLManager pmmlManager = new PMMLManager(IOUtil.unmarshal(new ByteArrayInputStream(pmmlContents.getBytes("UTF-8"))));
    Evaluator modelEvaluator = (ModelEvaluator<?>) pmmlManager.getModelManager(null, ModelEvaluatorFactory.getInstance());
    for (FieldName predictedField : modelEvaluator.getActiveFields()) {
        fieldNames.add(getModelField(modelEvaluator.getDataField(predictedField)));
    }
    return fieldNames;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ModelEvaluator(org.jpmml.evaluator.ModelEvaluator) ArrayList(java.util.ArrayList) Evaluator(org.jpmml.evaluator.Evaluator) ModelEvaluator(org.jpmml.evaluator.ModelEvaluator) FieldName(org.dmg.pmml.FieldName) PMMLManager(org.jpmml.manager.PMMLManager)

Example 5 with Evaluator

use of org.jpmml.evaluator.Evaluator in project streamline by hortonworks.

the class MLModelRegistryService method doGetOutputFieldsForPMMLStream.

private List<MLModelField> doGetOutputFieldsForPMMLStream(String pmmlContents) throws SAXException, JAXBException, UnsupportedEncodingException {
    List<MLModelField> fieldNames = new ArrayList<>();
    PMMLManager pmmlManager = new PMMLManager(IOUtil.unmarshal(new ByteArrayInputStream(pmmlContents.getBytes("UTF-8"))));
    Evaluator modelEvaluator = (ModelEvaluator<?>) pmmlManager.getModelManager(null, ModelEvaluatorFactory.getInstance());
    modelEvaluator.getPredictedFields().forEach((f) -> fieldNames.add(getModelField(modelEvaluator.getDataField(f))));
    modelEvaluator.getOutputFields().forEach((f) -> {
        OutputField outputField = modelEvaluator.getOutputField(f);
        ResultFeatureType resultFeatureType = outputField.getFeature();
        if (resultFeatureType != ResultFeatureType.PREDICTED_VALUE && resultFeatureType != ResultFeatureType.PREDICTED_DISPLAY_VALUE) {
            fieldNames.add(getModelField(outputField));
        }
    });
    return fieldNames;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ModelEvaluator(org.jpmml.evaluator.ModelEvaluator) ArrayList(java.util.ArrayList) OutputField(org.dmg.pmml.OutputField) ResultFeatureType(org.dmg.pmml.ResultFeatureType) Evaluator(org.jpmml.evaluator.Evaluator) ModelEvaluator(org.jpmml.evaluator.ModelEvaluator) PMMLManager(org.jpmml.manager.PMMLManager)

Aggregations

Evaluator (org.jpmml.evaluator.Evaluator)8 ArrayList (java.util.ArrayList)6 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ModelEvaluator (org.jpmml.evaluator.ModelEvaluator)4 PMMLManager (org.jpmml.manager.PMMLManager)4 FieldName (org.dmg.pmml.FieldName)3 PMML (org.dmg.pmml.PMML)3 OutputField (org.dmg.pmml.OutputField)2 ResultFeatureType (org.dmg.pmml.ResultFeatureType)2 HasPMML (org.jpmml.evaluator.HasPMML)2 Counter (com.codahale.metrics.Counter)1 Timer (com.codahale.metrics.Timer)1 HashingInputStream (com.google.common.hash.HashingInputStream)1 CountingInputStream (com.google.common.io.CountingInputStream)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Collections (java.util.Collections)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1