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);
}
}
Aggregations