Search in sources :

Example 1 with RGenericVector

use of org.jpmml.rexp.RGenericVector in project jpmml-r by jpmml.

the class XGBoostConverter method encodeModel.

@Override
public MiningModel encodeModel(Schema schema) {
    RGenericVector booster = getObject();
    RNumberVector<?> ntreeLimit = booster.getNumericElement("ntreelimit", false);
    Learner learner = ensureLearner();
    Map<String, Object> options = new LinkedHashMap<>();
    options.put(HasXGBoostOptions.OPTION_COMPACT, this.compact);
    options.put(HasXGBoostOptions.OPTION_NUMERIC, true);
    options.put(HasXGBoostOptions.OPTION_NTREE_LIMIT, ntreeLimit != null ? ValueUtil.asInteger(ntreeLimit.asScalar()) : null);
    Schema xgbSchema = learner.toXGBoostSchema(true, schema);
    MiningModel miningModel = learner.encodeMiningModel(options, xgbSchema);
    return miningModel;
}
Also used : MiningModel(org.dmg.pmml.mining.MiningModel) Schema(org.jpmml.converter.Schema) RGenericVector(org.jpmml.rexp.RGenericVector) Learner(org.jpmml.xgboost.Learner) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with RGenericVector

use of org.jpmml.rexp.RGenericVector in project jpmml-r by jpmml.

the class XGBoostConverter method loadLearner.

private Learner loadLearner() {
    RGenericVector booster = getObject();
    RRaw raw = (RRaw) booster.getElement("raw");
    try {
        return loadLearner(raw);
    } catch (IOException ioe) {
        throw new IllegalArgumentException(ioe);
    }
}
Also used : RRaw(org.jpmml.rexp.RRaw) RGenericVector(org.jpmml.rexp.RGenericVector) IOException(java.io.IOException)

Example 3 with RGenericVector

use of org.jpmml.rexp.RGenericVector in project jpmml-r by jpmml.

the class XGBoostConverter method encodeSchema.

@Override
public void encodeSchema(RExpEncoder encoder) {
    RGenericVector booster = getObject();
    RStringVector featureNames = booster.getStringElement("feature_names", false);
    RGenericVector schema = booster.getGenericElement("schema", false);
    FeatureMap featureMap = ensureFeatureMap();
    if (featureNames != null) {
        checkFeatureMap(featureMap, featureNames);
    }
    if (schema != null) {
        RVector<?> missing = schema.getVectorElement("missing", false);
        if (missing != null) {
            featureMap.addMissingValue(ValueUtil.asString(missing.asScalar()));
        }
    }
    Learner learner = ensureLearner();
    ObjFunction obj = learner.obj();
    String targetField = "_target";
    List<String> targetCategories = null;
    if (schema != null) {
        RStringVector responseName = schema.getStringElement("response_name", false);
        RStringVector responseLevels = schema.getStringElement("response_levels", false);
        if (responseName != null) {
            targetField = responseName.asScalar();
        }
        if (responseLevels != null) {
            targetCategories = responseLevels.getValues();
        }
    }
    Label label = obj.encodeLabel(targetField, targetCategories, encoder);
    encoder.setLabel(label);
    List<Feature> features = featureMap.encodeFeatures(encoder);
    for (Feature feature : features) {
        encoder.addFeature(feature);
    }
}
Also used : FeatureMap(org.jpmml.xgboost.FeatureMap) Label(org.jpmml.converter.Label) RGenericVector(org.jpmml.rexp.RGenericVector) Feature(org.jpmml.converter.Feature) Learner(org.jpmml.xgboost.Learner) RStringVector(org.jpmml.rexp.RStringVector) ObjFunction(org.jpmml.xgboost.ObjFunction)

Example 4 with RGenericVector

use of org.jpmml.rexp.RGenericVector in project jpmml-r by jpmml.

the class XGBoostConverter method loadFeatureMap.

private FeatureMap loadFeatureMap() {
    RGenericVector booster = getObject();
    RVector<?> fmap = DecorationUtil.getVectorElement(booster, "fmap");
    try {
        return loadFeatureMap(fmap);
    } catch (IOException ioe) {
        throw new IllegalArgumentException(ioe);
    }
}
Also used : RGenericVector(org.jpmml.rexp.RGenericVector) IOException(java.io.IOException)

Aggregations

RGenericVector (org.jpmml.rexp.RGenericVector)4 IOException (java.io.IOException)2 Learner (org.jpmml.xgboost.Learner)2 LinkedHashMap (java.util.LinkedHashMap)1 MiningModel (org.dmg.pmml.mining.MiningModel)1 Feature (org.jpmml.converter.Feature)1 Label (org.jpmml.converter.Label)1 Schema (org.jpmml.converter.Schema)1 RRaw (org.jpmml.rexp.RRaw)1 RStringVector (org.jpmml.rexp.RStringVector)1 FeatureMap (org.jpmml.xgboost.FeatureMap)1 ObjFunction (org.jpmml.xgboost.ObjFunction)1