use of org.knime.core.data.DataColumnSpecCreator in project knime-core by knime.
the class SubgroupMinerModel2 method createAssociationRulesSpec.
private DataTableSpec createAssociationRulesSpec(final DataTableSpec spec) {
DataType transType = spec.getColumnSpec(m_transactionColumn.getStringValue()).getType();
// now create the table spec
DataColumnSpec[] colSpecs = new DataColumnSpec[6];
DataColumnSpecCreator creator = new DataColumnSpecCreator("Support", DoubleCell.TYPE);
colSpecs[0] = creator.createSpec();
creator = new DataColumnSpecCreator("Confidence", DoubleCell.TYPE);
colSpecs[1] = creator.createSpec();
creator = new DataColumnSpecCreator("Lift", DoubleCell.TYPE);
colSpecs[2] = creator.createSpec();
DataType transCollType = transType.getCollectionElementType();
creator = new DataColumnSpecCreator("Consequent", transCollType == null ? StringCell.TYPE : transCollType);
colSpecs[3] = creator.createSpec();
creator = new DataColumnSpecCreator("implies", StringCell.TYPE);
colSpecs[4] = creator.createSpec();
creator = new DataColumnSpecCreator("Items", transCollType == null ? SetCell.getCollectionType(StringCell.TYPE) : SetCell.getCollectionType(transCollType));
colSpecs[5] = creator.createSpec();
return new DataTableSpec(colSpecs);
}
use of org.knime.core.data.DataColumnSpecCreator in project knime-core by knime.
the class SVMPredictor method getColumnSpecs.
/**
* {@inheritDoc}
*/
@Override
public DataColumnSpec[] getColumnSpecs() {
DataColumnSpecCreator colspeccreator = new DataColumnSpecCreator(m_predictionColumnName, StringCell.TYPE);
if (m_appendProbabilities) {
final DataColumnSpec[] ret = new DataColumnSpec[m_svms.length + 1];
PredictorHelper ph = PredictorHelper.getInstance();
final DataColumnSpecCreator creator = new DataColumnSpecCreator("Dummy", DoubleCell.TYPE);
creator.setDomain(new DataColumnDomainCreator(new DoubleCell(0), new DoubleCell(1)).createDomain());
for (int i = m_svms.length; i-- > 0; ) {
String name = ph.probabilityColumnName(m_trainingColumn, m_svms[i].getPositive(), m_suffix);
creator.setName(name);
ret[i] = creator.createSpec();
}
ret[m_svms.length] = colspeccreator.createSpec();
return ret;
}
return new DataColumnSpec[] { colspeccreator.createSpec() };
}
use of org.knime.core.data.DataColumnSpecCreator in project knime-core by knime.
the class PredictorHelper method createOutTableSpec.
/**
* Computes the output table's specifaction based on common node settings.
*
* @param dataSpec The input table {@link DataColumnSpec}.
* @param modelSpec The model {@link PMMLPortObjectSpec}.
* @param addProbs Add the probability columns?
* @param predictionCol Custom name of the prediction column.
* @param shouldOverride Should we use that name?
* @param suffix Suffix for probability columns.
* @return The output table {@link DataTableSpec}.
* @throws InvalidSettingsException Invalid settings for the prediction column name.
*/
public DataTableSpec createOutTableSpec(final PortObjectSpec dataSpec, final PortObjectSpec modelSpec, final boolean addProbs, final String predictionCol, final boolean shouldOverride, final String suffix) throws InvalidSettingsException {
CheckUtils.checkSettingNotNull(predictionCol, "Prediction column name cannot be null");
CheckUtils.checkSetting(!predictionCol.trim().isEmpty(), "Prediction column name cannot be empty");
List<DataCell> predValues = null;
if (addProbs) {
predValues = getPredictionValues((PMMLPortObjectSpec) modelSpec);
if (predValues == null) {
// no out spec can be determined
return null;
}
}
int numCols = (predValues == null ? 0 : predValues.size()) + 1;
DataTableSpec inSpec = (DataTableSpec) dataSpec;
DataColumnSpec[] newCols = new DataColumnSpec[numCols];
/* Set bar renderer and domain [0,1] as default for the double cells
* containing the distribution */
// DataColumnProperties propsRendering = new DataColumnProperties(
// Collections.singletonMap(
// DataValueRenderer.PROPERTY_PREFERRED_RENDERER,
// DoubleBarRenderer.DESCRIPTION));
DataColumnDomain domain = new DataColumnDomainCreator(new DoubleCell(0.0), new DoubleCell(1.0)).createDomain();
String trainingColumnName = ((PMMLPortObjectSpec) modelSpec).getTargetFields().iterator().next();
// add all distribution columns
for (int i = 0; i < numCols - 1; i++) {
assert predValues != null;
DataColumnSpecCreator colSpecCreator = new DataColumnSpecCreator(probabilityColumnName(trainingColumnName, predValues.get(i).toString(), suffix), DoubleCell.TYPE);
// colSpecCreator.setProperties(propsRendering);
colSpecCreator.setDomain(domain);
newCols[i] = colSpecCreator.createSpec();
}
// add the prediction column
String predictionColumnName = computePredictionColumnName(predictionCol, shouldOverride, trainingColumnName);
newCols[numCols - 1] = new DataColumnSpecCreator(predictionColumnName, StringCell.TYPE).createSpec();
DataTableSpec newColSpec = new DataTableSpec(newCols);
return new DataTableSpec(inSpec, newColSpec);
}
use of org.knime.core.data.DataColumnSpecCreator in project knime-core by knime.
the class Smoter method createFinalSpec.
/**
* Creates the out spec when <i>smoting</i> the table with
* <code>inSpec</code>. It replaces the data types of all
* {@link DoubleValue}-compatible columns by {@link DoubleCell#TYPE}.
*
* @param inSpec the table spec of the input table
* @return the output table spec
*/
static DataTableSpec createFinalSpec(final DataTableSpec inSpec) {
final int colCount = inSpec.getNumColumns();
DataColumnSpec[] colSpecs = new DataColumnSpec[colCount];
for (int i = 0; i < colSpecs.length; i++) {
DataColumnSpec cur = inSpec.getColumnSpec(i);
// column really once the Smoter adds new records
if (cur.getType().isCompatible(DoubleValue.class)) {
DataColumnSpecCreator colspeccreator = new DataColumnSpecCreator(cur);
DataType oldType = cur.getType();
// may be there was some strange double value type in the
// column, use supertype of old type and DoubleCell.TYPE
DataType newType = DataType.getCommonSuperType(oldType, DoubleCell.TYPE);
colspeccreator.setType(newType);
// domain isn't change becaust it's a convex operation
// (may be I should validate this statement - min and
// max depends on the comparator being used)
colSpecs[i] = colspeccreator.createSpec();
} else {
colSpecs[i] = cur;
}
}
return new DataTableSpec(colSpecs);
}
use of org.knime.core.data.DataColumnSpecCreator in project knime-core by knime.
the class SotaPredictorNodeFactory method createNodeDialogPane.
/**
* {@inheritDoc}
*/
@Override
protected NodeDialogPane createNodeDialogPane() {
return new PredictorNodeDialog(SotaPredictorNodeModel.createAppendProbabilities()) {
/**
* {@inheritDoc}
*/
@Override
protected void extractTargetColumn(final PortObjectSpec[] specs) {
if (specs[0] instanceof SotaPortObjectSpec) {
final SotaPortObjectSpec sotaSpec = (SotaPortObjectSpec) specs[0];
final DataColumnSpec classColumnSpec = sotaSpec.getClassColumnSpec();
setLastTargetColumn(classColumnSpec == null ? new DataColumnSpecCreator("No class", StringCell.TYPE).createSpec() : classColumnSpec);
} else {
throw new IllegalArgumentException("Wrong input: " + specs[0].getClass());
}
}
};
}
Aggregations