Search in sources :

Example 1 with RStringVector

use of org.jpmml.rexp.RStringVector 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)

Aggregations

Feature (org.jpmml.converter.Feature)1 Label (org.jpmml.converter.Label)1 RGenericVector (org.jpmml.rexp.RGenericVector)1 RStringVector (org.jpmml.rexp.RStringVector)1 FeatureMap (org.jpmml.xgboost.FeatureMap)1 Learner (org.jpmml.xgboost.Learner)1 ObjFunction (org.jpmml.xgboost.ObjFunction)1