use of org.dmg.pmml.PairCountsDocument.PairCounts in project knime-core by knime.
the class AttributeModel method loadModel.
/**
* @param bayesInput the <code>BayesInput</code> object to read from
* @return the attribute model for the given <code>Config</code> object
* @throws InvalidSettingsException if the settings are invalid
*/
static AttributeModel loadModel(final BayesInput bayesInput) throws InvalidSettingsException {
final String attrName = bayesInput.getFieldName();
final Map<String, String> extensionMap = PMMLNaiveBayesModelTranslator.convertToMap(bayesInput.getExtensionList());
boolean skipMissing = true;
int noOfMissingVals = 0;
if (extensionMap.containsKey(NO_OF_MISSING_VALUES)) {
skipMissing = false;
noOfMissingVals = PMMLNaiveBayesModelTranslator.getIntExtension(extensionMap, NO_OF_MISSING_VALUES);
}
final List<PairCounts> pairCounts = bayesInput.getPairCountsList();
final AttributeModel model;
if (pairCounts != null && !pairCounts.isEmpty()) {
model = new NominalAttributeModel(attrName, noOfMissingVals, skipMissing, bayesInput);
} else {
final TargetValueStats stats = bayesInput.getTargetValueStats();
if (stats != null) {
model = new NumericalAttributeModel(attrName, skipMissing, noOfMissingVals, bayesInput);
} else {
throw new InvalidSettingsException("Invalid model type for field " + bayesInput.getFieldName());
}
}
return model;
}
use of org.dmg.pmml.PairCountsDocument.PairCounts in project knime-core by knime.
the class NominalAttributeModel method exportToPMMLInternal.
/**
* {@inheritDoc}
*/
@Override
void exportToPMMLInternal(final BayesInput bayesInput) {
for (final String attributeValue : m_attributeVals) {
PairCounts pairCounts = bayesInput.addNewPairCounts();
pairCounts.setValue(attributeValue);
final TargetValueCounts targetValueCounts = pairCounts.addNewTargetValueCounts();
for (final NominalClassValue classVal : m_classValues.values()) {
final TargetValueCount targetValueCount = targetValueCounts.addNewTargetValueCount();
if (!ignoreMissingVals()) {
PMMLNaiveBayesModelTranslator.setIntExtension(targetValueCount.addNewExtension(), NominalClassValue.MISSING_VALUE_COUNTER, classVal.getNoOfMissingValueRecs());
}
targetValueCount.setValue(classVal.getClassValue());
final MutableInteger attrCount = classVal.m_recsByAttrValue.get(attributeValue);
final int count;
if (attrCount != null) {
count = attrCount.intValue();
} else {
count = 0;
}
targetValueCount.setCount(count);
}
}
}
Aggregations