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