Search in sources :

Example 6 with AssociationRule

use of org.knime.base.node.mine.subgroupminer.freqitemset.AssociationRule in project knime-core by knime.

the class SubgroupMinerModel method createAssociationRulesOutput.

/*
     * {@inheritDoc}
     *
    @Override
    protected void saveModelContent(final int index,
            final ModelContentWO predParams) throws InvalidSettingsException {
        assert index == 0;
        // check if the node is executed
        if (m_apriori != null) {
            if (m_associationRules.getBooleanValue()) {
                AssociationRuleModel model = new AssociationRuleModel();
                model.setNameMapping(m_nameMapping);
                model.setAssociationRules(m_apriori
                        .getAssociationRules(m_confidence.getDoubleValue()));
                model.saveToModelContent(predParams);

            } else {
                FrequentItemSetModel model = new FrequentItemSetModel();
                model.setNameMapping(m_nameMapping);
                model.setFrequentItemsets(m_apriori
                        .getFrequentItemSets(
                                FrequentItemSet.Type.valueOf(
                                        m_itemSetType.getStringValue())));
                model.setDBSize(m_nrOfRows);
                model.saveToModelContent(predParams);
            }
        }
    }

    /*
     * @return -
     */
private BufferedDataTable createAssociationRulesOutput(final ExecutionContext exec) {
    DataTableSpec outSpec = createAssociationRulesSpec();
    BufferedDataContainer ruleRows = exec.createDataContainer(outSpec);
    List<AssociationRule> associationRules = m_apriori.getAssociationRules(m_confidence.getDoubleValue());
    // for every association rule
    int rowKeyCounter = 0;
    for (AssociationRule r : associationRules) {
        // get the support
        double support = r.getSupport();
        // get the confidence
        double confidence = r.getConfidence();
        // get lift
        double lift = r.getLift();
        // get the antecedence (which is one item) -> cell
        FrequentItemSet antecedent = r.getAntecedent();
        // get the consequence
        FrequentItemSet consequent = r.getConsequent();
        DataCell[] allCells = new DataCell[m_maxItemSetLength.getIntValue() + 5];
        allCells[0] = new DoubleCell(support);
        allCells[1] = new DoubleCell(confidence);
        allCells[2] = new DoubleCell(lift);
        // consequent is always only one item -> access with get(0) ok
        if (m_nameMapping != null && m_nameMapping.size() > consequent.getItems().get(0)) {
            allCells[3] = new StringCell(m_nameMapping.get(consequent.getItems().get(0)));
        } else {
            allCells[3] = new StringCell("Item" + consequent.getItems().get(0));
        }
        allCells[4] = new StringCell("<---");
        for (int i = 0; i < antecedent.getItems().size() && i < m_maxItemSetLength.getIntValue() + 5; i++) {
            if (m_nameMapping != null && m_nameMapping.size() > antecedent.getItems().get(i)) {
                allCells[i + 5] = new StringCell(m_nameMapping.get(antecedent.getItems().get(i)));
            } else {
                allCells[i + 5] = new StringCell("Item" + antecedent.getItems().get(i));
            }
        }
        int start = Math.min(antecedent.getItems().size() + 5, m_maxItemSetLength.getIntValue() + 5);
        for (int i = start; i < m_maxItemSetLength.getIntValue() + 5; i++) {
            allCells[i] = DataType.getMissingCell();
        }
        if (antecedent.getItems().size() > 0) {
            DataRow row = new DefaultRow("rule" + rowKeyCounter++, allCells);
            ruleRows.addRowToTable(row);
        }
    }
    ruleRows.close();
    return ruleRows.getTable();
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) DoubleCell(org.knime.core.data.def.DoubleCell) FrequentItemSet(org.knime.base.node.mine.subgroupminer.freqitemset.FrequentItemSet) DataRow(org.knime.core.data.DataRow) AssociationRule(org.knime.base.node.mine.subgroupminer.freqitemset.AssociationRule) StringCell(org.knime.core.data.def.StringCell) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow)

Aggregations

AssociationRule (org.knime.base.node.mine.subgroupminer.freqitemset.AssociationRule)6 FrequentItemSet (org.knime.base.node.mine.subgroupminer.freqitemset.FrequentItemSet)5 ArrayList (java.util.ArrayList)2 DataCell (org.knime.core.data.DataCell)2 DataRow (org.knime.core.data.DataRow)2 DataTableSpec (org.knime.core.data.DataTableSpec)2 DefaultRow (org.knime.core.data.def.DefaultRow)2 DoubleCell (org.knime.core.data.def.DoubleCell)2 StringCell (org.knime.core.data.def.StringCell)2 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)2 HashSet (java.util.HashSet)1 TIDFrequentItemSet (org.knime.base.node.mine.subgroupminer.freqitemset.TIDFrequentItemSet)1 SAXException (org.xml.sax.SAXException)1 AttributesImpl (org.xml.sax.helpers.AttributesImpl)1