Search in sources :

Example 6 with Label

use of org.jpmml.converter.Label in project jpmml-r by jpmml.

the class XGBoostConverter method encodeSchema.

@Override
public void encodeSchema(RExpEncoder encoder) {
    RGenericVector booster = getObject();
    RGenericVector schema = (RGenericVector) booster.getValue("schema", true);
    RVector<?> fmap;
    try {
        fmap = (RVector<?>) booster.getValue("fmap");
    } catch (IllegalArgumentException iae) {
        throw new IllegalArgumentException("No feature map information. Please initialize the \'fmap\' element");
    }
    FeatureMap featureMap;
    try {
        featureMap = loadFeatureMap(fmap);
    } catch (IOException ioe) {
        throw new IllegalArgumentException(ioe);
    }
    if (schema != null) {
        RVector<?> missing = (RVector<?>) schema.getValue("missing", true);
        if (missing != null) {
            featureMap.addMissingValue(ValueUtil.formatValue(missing.asScalar()));
        }
    }
    Learner learner = ensureLearner();
    // Dependent variable
    {
        ObjFunction obj = learner.getObj();
        FieldName targetField = FieldName.create("_target");
        List<String> targetCategories = null;
        if (schema != null) {
            RStringVector responseName = (RStringVector) schema.getValue("response_name", true);
            RStringVector responseLevels = (RStringVector) schema.getValue("response_levels", true);
            if (responseName != null) {
                targetField = FieldName.create(responseName.asScalar());
            }
            if (responseLevels != null) {
                targetCategories = responseLevels.getValues();
            }
        }
        Label label = obj.encodeLabel(targetField, targetCategories, encoder);
        encoder.setLabel(label);
    }
    // Independent variables
    {
        List<Feature> features = featureMap.encodeFeatures(encoder);
        for (Feature feature : features) {
            encoder.addFeature(feature);
        }
    }
}
Also used : Label(org.jpmml.converter.Label) IOException(java.io.IOException) Feature(org.jpmml.converter.Feature) Learner(org.jpmml.xgboost.Learner) FeatureMap(org.jpmml.xgboost.FeatureMap) List(java.util.List) FieldName(org.dmg.pmml.FieldName) ObjFunction(org.jpmml.xgboost.ObjFunction)

Example 7 with Label

use of org.jpmml.converter.Label in project jpmml-r by jpmml.

the class RExpEncoder method setLabel.

public void setLabel(DataField dataField) {
    Label label;
    OpType opType = dataField.getOpType();
    switch(opType) {
        case CATEGORICAL:
            label = new CategoricalLabel(dataField);
            break;
        case CONTINUOUS:
            label = new ContinuousLabel(dataField);
            break;
        default:
            throw new IllegalArgumentException();
    }
    setLabel(label);
}
Also used : CategoricalLabel(org.jpmml.converter.CategoricalLabel) CategoricalLabel(org.jpmml.converter.CategoricalLabel) ContinuousLabel(org.jpmml.converter.ContinuousLabel) Label(org.jpmml.converter.Label) OpType(org.dmg.pmml.OpType) ContinuousLabel(org.jpmml.converter.ContinuousLabel)

Example 8 with Label

use of org.jpmml.converter.Label in project jpmml-sparkml by jpmml.

the class ModelConverter method registerModel.

public org.dmg.pmml.Model registerModel(SparkMLEncoder encoder) {
    Schema schema = encodeSchema(encoder);
    Label label = schema.getLabel();
    org.dmg.pmml.Model model = encodeModel(schema);
    List<OutputField> sparkOutputFields = registerOutputFields(label, encoder);
    if (sparkOutputFields != null && sparkOutputFields.size() > 0) {
        org.dmg.pmml.Model lastModel = getLastModel(model);
        Output output = lastModel.getOutput();
        if (output == null) {
            output = new Output();
            lastModel.setOutput(output);
        }
        List<OutputField> outputFields = output.getOutputFields();
        outputFields.addAll(0, sparkOutputFields);
    }
    return model;
}
Also used : Schema(org.jpmml.converter.Schema) Output(org.dmg.pmml.Output) ContinuousLabel(org.jpmml.converter.ContinuousLabel) CategoricalLabel(org.jpmml.converter.CategoricalLabel) Label(org.jpmml.converter.Label) OutputField(org.dmg.pmml.OutputField)

Aggregations

Label (org.jpmml.converter.Label)8 CategoricalLabel (org.jpmml.converter.CategoricalLabel)6 ContinuousLabel (org.jpmml.converter.ContinuousLabel)4 DataField (org.dmg.pmml.DataField)3 MiningFunction (org.dmg.pmml.MiningFunction)3 ArrayList (java.util.ArrayList)2 OutputField (org.dmg.pmml.OutputField)2 Feature (org.jpmml.converter.Feature)2 Schema (org.jpmml.converter.Schema)2 IOException (java.io.IOException)1 List (java.util.List)1 PredictionModel (org.apache.spark.ml.PredictionModel)1 ClassificationModel (org.apache.spark.ml.classification.ClassificationModel)1 HasLabelCol (org.apache.spark.ml.param.shared.HasLabelCol)1 Field (org.dmg.pmml.Field)1 FieldName (org.dmg.pmml.FieldName)1 OpType (org.dmg.pmml.OpType)1 Output (org.dmg.pmml.Output)1 GeneralRegressionModel (org.dmg.pmml.general_regression.GeneralRegressionModel)1 NeuralInputs (org.dmg.pmml.neural_network.NeuralInputs)1