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;
}
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);
}
}
}
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;
}
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();
}
Aggregations