Search in sources :

Example 1 with PairCounts

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;
}
Also used : PairCounts(org.dmg.pmml.PairCountsDocument.PairCounts) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) TargetValueStats(org.dmg.pmml.TargetValueStatsDocument.TargetValueStats)

Example 2 with PairCounts

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);
        }
    }
}
Also used : PairCounts(org.dmg.pmml.PairCountsDocument.PairCounts) TargetValueCounts(org.dmg.pmml.TargetValueCountsDocument.TargetValueCounts) MutableInteger(org.knime.core.util.MutableInteger) TargetValueCount(org.dmg.pmml.TargetValueCountDocument.TargetValueCount)

Aggregations

PairCounts (org.dmg.pmml.PairCountsDocument.PairCounts)2 TargetValueCount (org.dmg.pmml.TargetValueCountDocument.TargetValueCount)1 TargetValueCounts (org.dmg.pmml.TargetValueCountsDocument.TargetValueCounts)1 TargetValueStats (org.dmg.pmml.TargetValueStatsDocument.TargetValueStats)1 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)1 MutableInteger (org.knime.core.util.MutableInteger)1