Search in sources :

Example 1 with OutputField

use of org.dmg.pmml.OutputField in project jpmml-sparkml by jpmml.

the class MultilayerPerceptronClassificationModelConverter method registerOutputFields.

@Override
public List<OutputField> registerOutputFields(Label label, SparkMLEncoder encoder) {
    MultilayerPerceptronClassificationModel model = getTransformer();
    List<OutputField> result = super.registerOutputFields(label, encoder);
    if (!(model instanceof HasProbabilityCol)) {
        CategoricalLabel categoricalLabel = (CategoricalLabel) label;
        result = new ArrayList<>(result);
        result.addAll(ModelUtil.createProbabilityFields(DataType.DOUBLE, categoricalLabel.getValues()));
    }
    return result;
}
Also used : HasProbabilityCol(org.apache.spark.ml.param.shared.HasProbabilityCol) CategoricalLabel(org.jpmml.converter.CategoricalLabel) MultilayerPerceptronClassificationModel(org.apache.spark.ml.classification.MultilayerPerceptronClassificationModel) OutputField(org.dmg.pmml.OutputField)

Example 2 with OutputField

use of org.dmg.pmml.OutputField in project jpmml-sparkml by jpmml.

the class RegressionModelConverter method registerOutputFields.

@Override
public List<OutputField> registerOutputFields(Label label, SparkMLEncoder encoder) {
    T model = getTransformer();
    String predictionCol = model.getPredictionCol();
    OutputField predictedField = ModelUtil.createPredictedField(FieldName.create(predictionCol), label.getDataType(), OpType.CONTINUOUS);
    encoder.putOnlyFeature(predictionCol, new ContinuousFeature(encoder, predictedField.getName(), predictedField.getDataType()));
    return Collections.singletonList(predictedField);
}
Also used : ContinuousFeature(org.jpmml.converter.ContinuousFeature) OutputField(org.dmg.pmml.OutputField)

Example 3 with OutputField

use of org.dmg.pmml.OutputField in project jpmml-sparkml by jpmml.

the class ClusteringModelConverter method registerOutputFields.

@Override
public List<OutputField> registerOutputFields(Label label, SparkMLEncoder encoder) {
    T model = getTransformer();
    String predictionCol = model.getPredictionCol();
    OutputField predictedField = ModelUtil.createPredictedField(FieldName.create(predictionCol), DataType.STRING, OpType.CATEGORICAL);
    Feature feature = new Feature(encoder, predictedField.getName(), predictedField.getDataType()) {

        @Override
        public ContinuousFeature toContinuousFeature() {
            throw new UnsupportedOperationException();
        }
    };
    encoder.putOnlyFeature(predictionCol, feature);
    return Collections.singletonList(predictedField);
}
Also used : OutputField(org.dmg.pmml.OutputField) Feature(org.jpmml.converter.Feature) ContinuousFeature(org.jpmml.converter.ContinuousFeature)

Example 4 with OutputField

use of org.dmg.pmml.OutputField 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 5 with OutputField

use of org.dmg.pmml.OutputField in project drools by kiegroup.

the class PMMLModelTestUtils method getRandomOutputField.

public static OutputField getRandomOutputField() {
    FieldName fieldName = FieldName.create(RandomStringUtils.random(6, true, false));
    OutputField toReturn = new OutputField();
    toReturn.setName(fieldName);
    toReturn.setOpType(getRandomOpType());
    toReturn.setDataType(getRandomDataType());
    toReturn.setValue(getRandomValue(toReturn.getDataType()));
    fieldName = FieldName.create(RandomStringUtils.random(6, true, false));
    toReturn.setTargetField(fieldName);
    toReturn.setResultFeature(getRandomResultFeature());
    toReturn.setExpression(getRandomConstant());
    return toReturn;
}
Also used : OutputField(org.dmg.pmml.OutputField) FieldName(org.dmg.pmml.FieldName)

Aggregations

OutputField (org.dmg.pmml.OutputField)28 Test (org.junit.Test)10 DataField (org.dmg.pmml.DataField)9 MiningField (org.dmg.pmml.MiningField)9 MiningSchema (org.dmg.pmml.MiningSchema)7 Output (org.dmg.pmml.Output)7 PMML (org.dmg.pmml.PMML)7 DataDictionary (org.dmg.pmml.DataDictionary)4 FieldName (org.dmg.pmml.FieldName)4 ResultFeature (org.dmg.pmml.ResultFeature)4 MiningModel (org.dmg.pmml.mining.MiningModel)4 DATA_TYPE (org.kie.pmml.api.enums.DATA_TYPE)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 InputStream (java.io.InputStream)3 ArrayList (java.util.ArrayList)3 LinkedHashMap (java.util.LinkedHashMap)3 Collectors (java.util.stream.Collectors)3 Model (org.dmg.pmml.Model)3 OpType (org.dmg.pmml.OpType)3 RegressionModel (org.dmg.pmml.regression.RegressionModel)3