Search in sources :

Example 1 with ScoreProbabilityAndRecordCount

use of org.knime.base.node.rules.engine.pmml.PMMLRuleTranslator.ScoreProbabilityAndRecordCount in project knime-core by knime.

the class RuleSetToTable method createRow.

/**
 * Creates a row, {@link DataCell} values based on {@code rule} and the other parameters.
 *
 * @param rule A PMML {@link Rule}.
 * @param outcomeType The expected outcome.
 * @param types The types of the input column.
 * @return The cells for the {@code rule}.
 */
private DataCell[] createRow(final Rule rule, final DataType outcomeType, final Map<String, DataType> types, final List<String> scoreValues) {
    List<DataCell> ret = new ArrayList<>();
    boolean usePrecedence = !m_settings.getAdditionalParentheses().getBooleanValue();
    if (m_settings.getSplitRules().getBooleanValue()) {
        ret.add(new StringCell(convertToString(rule.getCondition(), usePrecedence, types)));
        ret.add(convertToExpectedType(rule.getOutcome(), outcomeType));
    } else {
        ret.add(new StringCell(convertToString(rule.getCondition(), usePrecedence, types) + " => " + toString(convertToExpectedType(rule.getOutcome(), outcomeType))));
    }
    if (m_settings.getConfidenceAndWeight().getBooleanValue()) {
        ret.add(toCell(rule.getConfidence()));
        ret.add(toCell(rule.getWeight()));
    }
    if (m_settings.getProvideStatistics().getBooleanValue()) {
        ret.add(toCell(rule.getRecordCount()));
        ret.add(toCell(rule.getNbCorrect()));
    }
    final Map<String, ScoreProbabilityAndRecordCount> scoreDistribution = rule.getScoreDistribution();
    if (m_settings.getScoreTableRecordCount().isEnabled() && m_settings.getScoreTableRecordCount().getBooleanValue()) {
        for (final String value : scoreValues) {
            if (scoreDistribution.containsKey(value)) {
                ret.add(new DoubleCell(scoreDistribution.get(value).getRecordCount()));
            } else {
                ret.add(DataType.getMissingCell());
            }
        }
    }
    if (m_settings.getScoreTableProbability().isEnabled() && m_settings.getScoreTableProbability().getBooleanValue()) {
        for (final String value : scoreValues) {
            if (scoreDistribution.containsKey(value)) {
                final BigDecimal probability = scoreDistribution.get(value).getProbability();
                ret.add(probability == null ? DataType.getMissingCell() : new DoubleCell(probability.doubleValue()));
            } else {
                ret.add(DataType.getMissingCell());
            }
        }
    }
    return ret.toArray(new DataCell[ret.size()]);
}
Also used : StringCell(org.knime.core.data.def.StringCell) ScoreProbabilityAndRecordCount(org.knime.base.node.rules.engine.pmml.PMMLRuleTranslator.ScoreProbabilityAndRecordCount) DoubleCell(org.knime.core.data.def.DoubleCell) ArrayList(java.util.ArrayList) DataCell(org.knime.core.data.DataCell) BigDecimal(java.math.BigDecimal)

Aggregations

BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 ScoreProbabilityAndRecordCount (org.knime.base.node.rules.engine.pmml.PMMLRuleTranslator.ScoreProbabilityAndRecordCount)1 DataCell (org.knime.core.data.DataCell)1 DoubleCell (org.knime.core.data.def.DoubleCell)1 StringCell (org.knime.core.data.def.StringCell)1