private void run() throws Exception { Learner learner; ByteOrder byteOrder = ByteOrderUtil.forValue(this.byteOrder); try(InputStream is = new FileInputStream(this.modelInput)){ learner = XGBoostUtil.loadLearner(is, byteOrder, this.charset); } FeatureMap featureMap; try(InputStream is = new FileInputStream(this.fmapInput)){ featureMap = XGBoostUtil.loadFeatureMap(is); } if(this.missingValue != null){ featureMap.addMissingValue(this.missingValue); } Map<String, Object> options = new LinkedHashMap<>(); options.put(HasXGBoostOptions.OPTION_COMPACT, this.compact); options.put(HasXGBoostOptions.OPTION_NTREE_LIMIT, this.ntreeLimit); PMML pmml = learner.encodePMML(this.targetName != null ? FieldName.create(this.targetName) : null, this.targetCategories, featureMap, options); try(OutputStream os = new FileOutputStream(this.pmmlOutput)){ MetroJAXBUtil.marshalPMML(pmml, os); } } }
private void run() throws Exception { Learner learner; ByteOrder byteOrder = ByteOrderUtil.forValue(this.byteOrder); try(InputStream is = new FileInputStream(this.modelInput)){ learner = XGBoostUtil.loadLearner(is, byteOrder, this.charset); } FeatureMap featureMap; try(InputStream is = new FileInputStream(this.fmapInput)){ featureMap = XGBoostUtil.loadFeatureMap(is); } if(this.missingValue != null){ featureMap.addMissingValue(this.missingValue); } Map<String, Object> options = new LinkedHashMap<>(); options.put(HasXGBoostOptions.OPTION_COMPACT, this.compact); options.put(HasXGBoostOptions.OPTION_NTREE_LIMIT, this.ntreeLimit); PMML pmml = learner.encodePMML(this.targetName != null ? FieldName.create(this.targetName) : null, this.targetCategories, featureMap, options); try(OutputStream os = new FileOutputStream(this.pmmlOutput)){ MetroJAXBUtil.marshalPMML(pmml, os); } } }
static private <E extends Estimator & HasBooster & HasXGBoostOptions> Learner getLearner(E estimator){ Booster booster = estimator.getBooster(); String byteOrder = (String)estimator.getOption(HasXGBoostOptions.OPTION_BYTE_ORDER, (ByteOrder.nativeOrder()).toString()); String charset = (String)estimator.getOption(HasXGBoostOptions.OPTION_CHARSET, null); return booster.getLearner(ByteOrderUtil.forValue(byteOrder), charset); } }