Java Code Examples for org.dmg.pmml.MiningField#getUsageType()
The following examples show how to use
org.dmg.pmml.MiningField#getUsageType() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AppPMMLUtils.java From oryx with Apache License 2.0 | 5 votes |
/** * @param schema {@link InputSchema} whose information should be encoded in PMML * @param importances optional feature importances. May be {@code null}, or else the size * of the array must match the number of predictors in the schema, which may be * less than the total number of features. * @return a {@link MiningSchema} representing the information contained in an * {@link InputSchema} */ public static MiningSchema buildMiningSchema(InputSchema schema, double[] importances) { Preconditions.checkArgument( importances == null || (importances.length == schema.getNumPredictors())); List<String> featureNames = schema.getFeatureNames(); List<MiningField> miningFields = new ArrayList<>(); for (int featureIndex = 0; featureIndex < featureNames.size(); featureIndex++) { String featureName = featureNames.get(featureIndex); MiningField field = new MiningField(FieldName.create(featureName)); if (schema.isNumeric(featureName)) { field.setOpType(OpType.CONTINUOUS); field.setUsageType(MiningField.UsageType.ACTIVE); } else if (schema.isCategorical(featureName)) { field.setOpType(OpType.CATEGORICAL); field.setUsageType(MiningField.UsageType.ACTIVE); } else { // ID, or ignored field.setUsageType(MiningField.UsageType.SUPPLEMENTARY); } if (schema.hasTarget() && schema.isTarget(featureName)) { // Override to PREDICTED field.setUsageType(MiningField.UsageType.PREDICTED); } // Will be active if and only if it's a predictor if (field.getUsageType() == MiningField.UsageType.ACTIVE && importances != null) { int predictorIndex = schema.featureToPredictorIndex(featureIndex); field.setImportance(importances[predictorIndex]); } miningFields.add(field); } return new MiningSchema(miningFields); }
Example 2
Source File: ModelEvaluationContext.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 5 votes |
@Override protected FieldValue prepare(FieldName name, Object value){ ModelEvaluator<?> modelEvaluator = getModelEvaluator(); DataField dataField = modelEvaluator.getDataField(name); if(dataField == null){ throw new MissingFieldException(name); } MiningField miningField = modelEvaluator.getMiningField(name); if(miningField == null){ throw new InvisibleFieldException(name); } MiningField.UsageType usageType = miningField.getUsageType(); switch(usageType){ case ACTIVE: case GROUP: case ORDER: { return InputFieldUtil.prepareInputValue(dataField, miningField, value); } case PREDICTED: case TARGET: { return InputFieldUtil.prepareResidualInputValue(dataField, miningField, value); } default: throw new UnsupportedAttributeException(miningField, usageType); } }
Example 3
Source File: TargetCategoryParser.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 5 votes |
private void processModel(Model model){ MiningSchema miningSchema = model.getMiningSchema(); if(miningSchema == null){ throw new MissingElementException(MissingElementException.formatMessage(XPathUtil.formatElement(model.getClass()) + "/" + XPathUtil.formatElement(MiningSchema.class)), model); } Map<FieldName, DataType> targetDataTypes = new LinkedHashMap<>(); if(miningSchema.hasMiningFields()){ List<MiningField> miningFields = miningSchema.getMiningFields(); for(MiningField miningField : miningFields){ FieldName name = miningField.getName(); if(name == null){ throw new MissingAttributeException(miningField, PMMLAttributes.MININGFIELD_NAME); } MiningField.UsageType usageType = miningField.getUsageType(); switch(usageType){ case PREDICTED: case TARGET: DataType dataType = resolveTargetDataType(name); targetDataTypes.put(name, dataType); break; default: break; } } } this.targetDataTypes.push(targetDataTypes); this.dataType = getDataType(); }