use of org.knime.core.node.ModelContentWO in project knime-core by knime.
the class LinReg2LearnerNodeModel method saveInternals.
/**
* {@inheritDoc}
*/
@Override
protected void saveInternals(final File internDir, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
ModelContent content = new ModelContent(CFG_SETTINGS);
ModelContentWO specContent = content.addModelContent(CFG_SPEC);
m_content.getSpec().getDataTableSpec().save(specContent);
ModelContentWO parContent = content.addModelContent(CFG_LinReg2_CONTENT);
m_content.save(parContent);
File outFile = new File(internDir, FILE_SAVE);
content.saveToXML(new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(outFile))));
File dataFile = new File(internDir, FILE_DATA);
DataContainer.writeToZip(m_rowContainer, dataFile, exec);
}
use of org.knime.core.node.ModelContentWO in project knime-core by knime.
the class AssociationRuleModel method saveToModelContent.
/**
* @param model the model the association rules are saved to
*/
public void saveToModelContent(final ModelContentWO model) {
ModelContentWO associationRulesModel = model.addModelContent(ASSOCIATION_RULES);
associationRulesModel.addString(TYPE, ASSOCIATION_RULES);
if (m_nameMapping != null) {
String[] mappingArray = new String[m_nameMapping.size()];
m_nameMapping.toArray(mappingArray);
associationRulesModel.addStringArray(NAME_MAPPING, mappingArray);
}
int counter = 0;
associationRulesModel.addInt(NR_RULES, m_rules.size());
for (AssociationRule rule : m_rules) {
ModelContentWO ruleModel = associationRulesModel.addModelContent(ASSOCIATION_RULE + counter++);
ruleModel.addDouble(SUPPORT, rule.getSupport());
ruleModel.addDouble(CONFIDENCE, rule.getConfidence());
ruleModel.addDouble(LIFT, rule.getLift());
String name;
/*
if (m_nameMapping != null
&& m_nameMapping.size() > rule.getConsequent()) {
name = m_nameMapping.get(rule.getConsequent());
} else {
name = "item" + rule.getConsequent();
}
*/
// ruleModel.addString(CONSEQUENT, name);
// int antecedentSize = rule.getAntecedent().size();
ModelContentWO antecedentModel = ruleModel.addModelContent(ANTECEDENT);
// antecedentModel.addInt(ANTECEDENT_SIZE, antecedentSize);
int itemCounter = 0;
for (Integer item : rule.getAntecedent()) {
if (m_nameMapping != null && m_nameMapping.size() > item) {
name = m_nameMapping.get(item);
} else {
name = "item" + item;
}
antecedentModel.addString(ITEM + itemCounter++, name);
}
}
}
use of org.knime.core.node.ModelContentWO in project knime-core by knime.
the class DecisionTree method saveToPredictorParams.
// ///////////////////
// Save & Load
// ///////////////////
/**
* Save decision tree to a ModelContent object.
*
* @param pConf configuration object to attach decision tree to
* @param saveKeysAndPatterns whether to save the keys and patterns
*/
public void saveToPredictorParams(final ModelContentWO pConf, final boolean saveKeysAndPatterns) {
pConf.addString("type", "DecisionTree");
pConf.addString("version", "0.0");
pConf.addString("color_column", m_colorColumn);
ModelContentWO newNodeConf = pConf.addModelContent("rootNode");
m_rootNode.saveToPredictorParams(newNodeConf, saveKeysAndPatterns);
}
use of org.knime.core.node.ModelContentWO in project knime-core by knime.
the class DecisionTreeNodeSplit method saveNodeInternalsToPredParams.
/**
* {@inheritDoc}
*/
@Override
public final void saveNodeInternalsToPredParams(final ModelContentWO pConf, final boolean saveKeysAndPatterns) {
saveNodeSplitInternalsToPredParams(pConf);
pConf.addString("splitAttribute", m_splitAttr);
pConf.addInt("nrChildren", m_child.length);
for (int i = 0; i < m_child.length; i++) {
ModelContentWO newChildConf = pConf.addModelContent("child" + i);
newChildConf.addInt("index", m_childIndex[i]);
m_child[i].saveToPredictorParams(newChildConf, saveKeysAndPatterns);
}
}
use of org.knime.core.node.ModelContentWO in project knime-core by knime.
the class BasisFunctionModelContent method save.
/**
* Save the given rule model and model spec into this model content object.
* @param modelCont save spec and rule to
*/
public void save(final ModelContentWO modelCont) {
// save rules
ModelContentWO ruleSpec = modelCont.addModelContent("rules");
for (DataCell key : m_bfs.keySet()) {
for (BasisFunctionPredictorRow bf : m_bfs.get(key)) {
ModelContentWO bfParam = ruleSpec.addModelContent(bf.getId().toString());
bf.save(bfParam);
}
}
// save spec
ModelContentWO modelSpec = modelCont.addModelContent("model_spec");
for (int i = 0; i < m_spec.getNumColumns(); i++) {
DataColumnSpec cspec = m_spec.getColumnSpec(i);
cspec.save(modelSpec.addConfig(cspec.getName()));
}
}
Aggregations