Search in sources :

Example 81 with DataColumnSpecCreator

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);
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpec(org.knime.core.data.DataColumnSpec) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) DataType(org.knime.core.data.DataType)

Example 82 with DataColumnSpecCreator

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() };
}
Also used : DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) DataColumnSpec(org.knime.core.data.DataColumnSpec) PredictorHelper(org.knime.base.node.mine.util.PredictorHelper) DoubleCell(org.knime.core.data.def.DoubleCell) DataColumnDomainCreator(org.knime.core.data.DataColumnDomainCreator)

Example 83 with DataColumnSpecCreator

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);
}
Also used : PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpec(org.knime.core.data.DataColumnSpec) DataColumnDomain(org.knime.core.data.DataColumnDomain) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) DoubleCell(org.knime.core.data.def.DoubleCell) DataCell(org.knime.core.data.DataCell) DataColumnDomainCreator(org.knime.core.data.DataColumnDomainCreator) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) DialogComponentString(org.knime.core.node.defaultnodesettings.DialogComponentString)

Example 84 with DataColumnSpecCreator

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);
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpec(org.knime.core.data.DataColumnSpec) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) DataType(org.knime.core.data.DataType)

Example 85 with DataColumnSpecCreator

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());
            }
        }
    };
}
Also used : DataColumnSpec(org.knime.core.data.DataColumnSpec) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) SotaPortObjectSpec(org.knime.base.node.mine.sota.SotaPortObjectSpec) PredictorNodeDialog(org.knime.base.node.mine.util.PredictorNodeDialog)

Aggregations

DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)267 DataColumnSpec (org.knime.core.data.DataColumnSpec)210 DataTableSpec (org.knime.core.data.DataTableSpec)132 DataCell (org.knime.core.data.DataCell)92 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)77 DataType (org.knime.core.data.DataType)74 DataRow (org.knime.core.data.DataRow)73 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)57 DataColumnDomainCreator (org.knime.core.data.DataColumnDomainCreator)51 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)48 ArrayList (java.util.ArrayList)46 DoubleCell (org.knime.core.data.def.DoubleCell)45 SingleCellFactory (org.knime.core.data.container.SingleCellFactory)44 StringCell (org.knime.core.data.def.StringCell)29 BufferedDataTable (org.knime.core.node.BufferedDataTable)23 DoubleValue (org.knime.core.data.DoubleValue)22 HashSet (java.util.HashSet)19 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)17 DataColumnDomain (org.knime.core.data.DataColumnDomain)16 DefaultRow (org.knime.core.data.def.DefaultRow)16