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