Search in sources :

Example 11 with FrequentItemSet

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

the class ArrayApriori method getFrequentItemSets.

/**
 * {@inheritDoc}
 */
@Override
public List<FrequentItemSet> getFrequentItemSets(final Type type) {
    List<FrequentItemSet> list = new ArrayList<FrequentItemSet>();
    for (Integer i : m_alwaysFrequentItems) {
        List<Integer> id = new ArrayList<Integer>();
        id.add(i);
        FrequentItemSet set = new FrequentItemSet(Integer.toString(m_idCounter++), id, 1);
        list.add(set);
    }
    FrequentItemSet initialSet = new FrequentItemSet(Integer.toString(m_idCounter++));
    getFrequentItemSets(m_root, list, initialSet, 0);
    if (type.equals(FrequentItemSet.Type.CLOSED)) {
        List<FrequentItemSet> resultList = filterClosedItemsets(list);
        return resultList;
    }
    /*
         * nothing else then check for every set in the closed itemsets whether
         * it is a superset or not -> delete the subsets
         */
    if (type.equals(FrequentItemSet.Type.MAXIMAL)) {
        List<FrequentItemSet> resultList = filterClosedItemsets(list);
        return filterMaximalItemsets(resultList);
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) FrequentItemSet(org.knime.base.node.mine.subgroupminer.freqitemset.FrequentItemSet)

Example 12 with FrequentItemSet

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

the class ArrayApriori method getFrequentItemSets.

private void getFrequentItemSets(final ArrayPrefixTreeNode root, final List<FrequentItemSet> list, final FrequentItemSet currSet, final int item) {
    if (root == null) {
        return;
    }
    for (int i = item; i < root.getLength(); i++) {
        if (((double) root.getCounterFor(i) / (double) m_dbsize) >= m_minSupport) {
            FrequentItemSet newSet = new FrequentItemSet("" + m_idCounter++, currSet.getItems(), ((double) root.getCounterFor(i) / (double) m_dbsize));
            newSet.add(m_backwardMapping[i]);
            list.add(newSet);
            getFrequentItemSets(root.getChild(i), list, newSet, i + 1);
        }
    }
}
Also used : FrequentItemSet(org.knime.base.node.mine.subgroupminer.freqitemset.FrequentItemSet)

Example 13 with FrequentItemSet

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

the class TIDApriori method getMaximalItemSets.

private List<FrequentItemSet> getMaximalItemSets() {
    List<FrequentItemSet> maximalItemsets = new ArrayList<FrequentItemSet>();
    List<FrequentItemSet> closedItemsets = getClosedItemSets();
    for (FrequentItemSet outer : closedItemsets) {
        boolean isMaximal = true;
        for (FrequentItemSet inner : closedItemsets) {
            if (!outer.equals(inner) && outer.isSubsetOf(inner)) {
                isMaximal = false;
                break;
            }
        }
        if (isMaximal) {
            maximalItemsets.add(outer);
        }
    }
    return maximalItemsets;
}
Also used : ArrayList(java.util.ArrayList) FrequentItemSet(org.knime.base.node.mine.subgroupminer.freqitemset.FrequentItemSet) TIDFrequentItemSet(org.knime.base.node.mine.subgroupminer.freqitemset.TIDFrequentItemSet)

Example 14 with FrequentItemSet

use of org.knime.base.node.mine.subgroupminer.freqitemset.FrequentItemSet 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

FrequentItemSet (org.knime.base.node.mine.subgroupminer.freqitemset.FrequentItemSet)14 ArrayList (java.util.ArrayList)7 AssociationRule (org.knime.base.node.mine.subgroupminer.freqitemset.AssociationRule)5 TIDFrequentItemSet (org.knime.base.node.mine.subgroupminer.freqitemset.TIDFrequentItemSet)4 DataTableSpec (org.knime.core.data.DataTableSpec)4 DataCell (org.knime.core.data.DataCell)3 DataRow (org.knime.core.data.DataRow)3 DefaultRow (org.knime.core.data.def.DefaultRow)3 DoubleCell (org.knime.core.data.def.DoubleCell)3 StringCell (org.knime.core.data.def.StringCell)3 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)3 HashSet (java.util.HashSet)2 LinkedList (java.util.LinkedList)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 FrequentItemSetRow (org.knime.base.node.mine.subgroupminer.freqitemset.FrequentItemSetRow)1 FrequentItemSetTable (org.knime.base.node.mine.subgroupminer.freqitemset.FrequentItemSetTable)1 RowKey (org.knime.core.data.RowKey)1 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)1 SAXException (org.xml.sax.SAXException)1 AttributesImpl (org.xml.sax.helpers.AttributesImpl)1