org.dmg.pmml.VerificationField Java Examples

The following examples show how to use org.dmg.pmml.VerificationField. 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: ModelConverter.java    From jpmml-r with GNU Affero General Public License v3.0 5 votes vote down vote up
public void putResultData(Map<VerificationField, List<?>> map){
	Double precision = getPrecision();
	Double zeroThreshold = getZeroThreshold();

	Collection<VerificationField> verificationFields = map.keySet();
	for(VerificationField verificationField : verificationFields){
		verificationField
			.setPrecision(precision)
			.setZeroThreshold(zeroThreshold);
	}

	putAll(map);
}
 
Example #2
Source File: ModelConverter.java    From jpmml-r with GNU Affero General Public License v3.0 4 votes vote down vote up
protected Map<VerificationField, List<?>> encodeActiveValues(RGenericVector dataFrame){
	return encodeVerificationData(dataFrame);
}
 
Example #3
Source File: ModelConverter.java    From jpmml-r with GNU Affero General Public License v3.0 4 votes vote down vote up
protected Map<VerificationField, List<?>> encodeTargetValues(RGenericVector dataFrame, Label label){
	List<RExp> columns = dataFrame.getValues();
	FieldName name = label.getName();

	return encodeVerificationData(columns, Collections.singletonList(name));
}
 
Example #4
Source File: ModelConverter.java    From jpmml-r with GNU Affero General Public License v3.0 4 votes vote down vote up
protected Map<VerificationField, List<?>> encodeOutputValues(RGenericVector dataFrame){
	return encodeVerificationData(dataFrame);
}
 
Example #5
Source File: ModelConverter.java    From jpmml-r with GNU Affero General Public License v3.0 4 votes vote down vote up
static
protected Map<VerificationField, List<?>> encodeVerificationData(List<? extends RExp> columns, List<FieldName> names){
	Map<VerificationField, List<?>> result = new LinkedHashMap<>();

	for(int i = 0; i < columns.size(); i++){
		FieldName name = names.get(i);
		RVector<?> column = (RVector<?>)columns.get(i);

		List<?> values;

		if(column instanceof RDoubleVector){
			Function<Double, Double> function = new Function<Double, Double>(){

				@Override
				public Double apply(Double value){

					if(value.isNaN()){
						return null;
					}

					return value;
				}
			};

			values = Lists.transform((List)column.getValues(), function);
		} else

		if(column instanceof RIntegerVector && RExpUtil.isFactor(column)){
			RIntegerVector factor = (RIntegerVector)column;

			values = factor.getFactorValues();
		} else

		{
			values = column.getValues();
		}

		VerificationField verificationField = ModelUtil.createVerificationField(name);

		result.put(verificationField, values);
	}

	return result;
}
 
Example #6
Source File: ModelConverter.java    From jpmml-r with GNU Affero General Public License v3.0 4 votes vote down vote up
public void putInputData(Map<VerificationField, List<?>> map){
	putAll(map);
}
 
Example #7
Source File: XGBoostConverter.java    From jpmml-r with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
protected Map<VerificationField, List<?>> encodeActiveValues(RGenericVector dataFrame){
	FeatureMap featureMap = ensureFeatureMap();

	checkFeatureMap(featureMap, dataFrame);

	List<FeatureMap.Entry> entries = featureMap.getEntries();

	Map<FieldName, RVector<?>> data = new LinkedHashMap<>();

	for(int i = 0; i < dataFrame.size(); i++){
		FeatureMap.Entry entry = entries.get(i);
		RVector<?> column = (RVector<?>)dataFrame.getValue(i);

		FieldName name = FieldName.create(entry.getName());
		String value = entry.getValue();

		FeatureMap.Entry.Type type = entry.getType();
		switch(type){
			case BINARY_INDICATOR:
				{
					RIntegerVector factorColumn = (RIntegerVector)data.get(name);
					if(factorColumn == null){
						factorColumn = new RIntegerVector(null, null){

							private List<String> factorValues = new ArrayList<>();

							{
								for(int i = 0; i < column.size(); i++){
									this.factorValues.add(null);
								}
							}

							@Override
							public boolean isFactor(){
								return true;
							}

							@Override
							public List<String> getFactorValues(){
								return this.factorValues;
							}
						};

						data.put(name, factorColumn);
					}

					List<String> factorValues = factorColumn.getFactorValues();

					List<? extends Number> mask = (List)column.getValues();

					for(int row = 0; row < mask.size(); row++){
						Number rowMask = mask.get(row);

						if(rowMask != null && rowMask.doubleValue() == 1d){
							factorValues.set(row, value);
						}
					}
				}
				break;
			case FLOAT:
			case INTEGER:
				{
					data.put(name, column);
				}
				break;
			default:
				throw new IllegalArgumentException(String.valueOf(type));
		}
	}

	List<RVector<?>> columns = new ArrayList<>(data.values());
	List<FieldName> names = new ArrayList<>(data.keySet());

	return encodeVerificationData(columns, names);
}