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