Search in sources :

Example 41 with PMMLPortObjectSpec

use of org.knime.core.node.port.pmml.PMMLPortObjectSpec in project knime-core by knime.

the class MLPPredictorNodeModel method configure.

/**
 * The additional columns are created based on the model which is loaded in
 * the execute-method. Therefore, new DataTableSpecs are not available until
 * execute has been called.
 *
 * {@inheritDoc}
 */
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    PMMLPortObjectSpec modelspec = (PMMLPortObjectSpec) inSpecs[0];
    DataTableSpec testSpec = (DataTableSpec) inSpecs[1];
    List<DataColumnSpec> targetCols = modelspec.getTargetCols();
    if (targetCols.isEmpty()) {
        throw new InvalidSettingsException("The PMML model" + " does not specify a target column for the prediction.");
    }
    DataColumnSpec targetCol = targetCols.iterator().next();
    /*
         * Check consistency between model and inputs, find columns to work on.
         */
    for (String incol : modelspec.getLearningFields()) {
        if (!testSpec.containsName(incol)) {
            throw new InvalidSettingsException("Could not find " + incol + " in inputspec");
        }
    }
    m_columns = getLearningColumnIndices(testSpec, modelspec);
    final String prediction = PredictorHelper.getInstance().checkedComputePredictionColumnName(m_predictionColumn.getStringValue(), m_overridePrediction.getBooleanValue(), targetCol.getName());
    MLPClassificationFactory mymlp;
    // Regression
    if (targetCol.getType().isCompatible(DoubleValue.class)) {
        mymlp = new MLPClassificationFactory(true, m_columns, targetCol, prediction, m_appendProbs.getBooleanValue(), m_suffix.getStringValue());
    } else {
        // Classification
        mymlp = new MLPClassificationFactory(false, m_columns, targetCol, prediction, m_appendProbs.getBooleanValue(), m_suffix.getStringValue());
    }
    ColumnRearranger colre = new ColumnRearranger(testSpec);
    colre.append(mymlp);
    return new DataTableSpec[] { colre.createSpec() };
}
Also used : PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpec(org.knime.core.data.DataColumnSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString)

Example 42 with PMMLPortObjectSpec

use of org.knime.core.node.port.pmml.PMMLPortObjectSpec in project knime-core by knime.

the class DataColumnSpecFilterPMMLNodeModel method configure.

/**
 * Excludes a number of columns from the input spec and generates a new output spec.
 *
 * @param inSpecs the input table spec
 * @return outSpecs the output table spec with some excluded columns
 *
 * @throws InvalidSettingsException if the selected column is not available
 *             in the table spec.
 */
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    final DataTableSpec inSpec = (DataTableSpec) inSpecs[0];
    final DataTableSpec outSpec = super.configure(new DataTableSpec[] { inSpec })[0];
    final FilterResult res = getFilterResult(inSpec);
    final PMMLPortObjectSpec pmmlSpec = createPMMLSpec((PMMLPortObjectSpec) inSpecs[1], inSpec, res);
    return new PortObjectSpec[] { outSpec, pmmlSpec };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) FilterResult(org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult)

Example 43 with PMMLPortObjectSpec

use of org.knime.core.node.port.pmml.PMMLPortObjectSpec in project knime-core by knime.

the class BinnerNodeModel method configure.

/**
 * Passes the input spec to the output.
 *
 * @param inSpecs The input spec.
 * @return The generated output specs.
 * @throws InvalidSettingsException If column to bin cannot be identified.
 */
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    DataTableSpec inDataSpec = (DataTableSpec) inSpecs[DATA_INPORT];
    PMMLPortObjectSpec inModelSpec = m_pmmlInEnabled ? (PMMLPortObjectSpec) inSpecs[MODEL_INPORT] : null;
    for (String columnKey : m_columnToBins.keySet()) {
        assert m_columnToAppended.containsKey(columnKey) : columnKey;
        if (!inDataSpec.containsName(columnKey)) {
            throw new InvalidSettingsException("Binner: column \"" + columnKey + "\" not found in spec.");
        }
        if (!inDataSpec.getColumnSpec(columnKey).getType().isCompatible(DoubleValue.class)) {
            throw new InvalidSettingsException("Binner: column \"" + columnKey + "\" not compatible with double-type.");
        }
        String appended = m_columnToAppended.get(columnKey);
        if (appended != null) {
            if (inDataSpec.containsName(appended)) {
                throw new InvalidSettingsException("Binner: duplicate " + "appended column \"" + appended + "\" in spec.");
            }
        }
    }
    // set warning when no binning is defined
    if (m_columnToBins.isEmpty()) {
        super.setWarningMessage("No column select for binning.");
    }
    // generate numeric binned table spec
    DataTableSpec outDataSpec = createColumnRearranger(inDataSpec).createSpec();
    if (!m_pmmlOutEnabled) {
        return new PortObjectSpec[] { outDataSpec };
    }
    PMMLPortObjectSpecCreator pmmlSpecCreator = new PMMLPortObjectSpecCreator(inModelSpec, outDataSpec);
    return new PortObjectSpec[] { outDataSpec, pmmlSpecCreator.createSpec() };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) DoubleValue(org.knime.core.data.DoubleValue) PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) PMMLPortObjectSpecCreator(org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator)

Example 44 with PMMLPortObjectSpec

use of org.knime.core.node.port.pmml.PMMLPortObjectSpec in project knime-core by knime.

the class Many2OneCol2PMMLNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    DataTableSpec inDataSpec = (DataTableSpec) inSpecs[0];
    String[] includes = m_includedColumns.applyTo(inDataSpec).getIncludes();
    if (includes.length <= 0) {
        setWarningMessage("No column selected. Node will have no effect!");
    }
    // if it is not a reg exp it must be double compatible
    if (!m_includeMethod.getStringValue().equals(IncludeMethod.RegExpPattern.name())) {
        for (String colName : includes) {
            if (!inDataSpec.getColumnSpec(colName).getType().isCompatible(DoubleValue.class)) {
                throw new InvalidSettingsException("For selected include method '" + m_includeMethod.getStringValue() + "' only double compatible values are allowed." + " Column '" + colName + "' is not.");
            }
        }
    }
    ColumnRearranger rearranger = createRearranger(inDataSpec, getCellFactory(inDataSpec));
    if (m_pmmlOutEnabled) {
        PMMLPortObjectSpec pmmlSpec = m_pmmlInEnabled ? (PMMLPortObjectSpec) inSpecs[1] : null;
        PMMLPortObjectSpecCreator pmmlSpecCreator = new PMMLPortObjectSpecCreator(pmmlSpec, inDataSpec);
        return new PortObjectSpec[] { rearranger.createSpec(), pmmlSpecCreator.createSpec() };
    } else {
        return new DataTableSpec[] { rearranger.createSpec() };
    }
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) DoubleValue(org.knime.core.data.DoubleValue) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) PMMLPortObjectSpecCreator(org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator)

Example 45 with PMMLPortObjectSpec

use of org.knime.core.node.port.pmml.PMMLPortObjectSpec in project knime-core by knime.

the class StringToNumberNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    // find indices to work on
    DataTableSpec dts = (DataTableSpec) inSpecs[0];
    int[] indices = findColumnIndices(dts);
    ConverterFactory converterFac = new ConverterFactory(indices, dts, m_parseType);
    ColumnRearranger colre = new ColumnRearranger(dts);
    colre.replace(converterFac, indices);
    DataTableSpec newspec = colre.createSpec();
    // create the PMML spec based on the optional incoming PMML spec
    PMMLPortObjectSpec pmmlSpec = m_pmmlInEnabled ? (PMMLPortObjectSpec) inSpecs[1] : null;
    PMMLPortObjectSpecCreator pmmlSpecCreator = new PMMLPortObjectSpecCreator(pmmlSpec, dts);
    return new PortObjectSpec[] { newspec, pmmlSpecCreator.createSpec() };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) PMMLPortObjectSpecCreator(org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator)

Aggregations

PMMLPortObjectSpec (org.knime.core.node.port.pmml.PMMLPortObjectSpec)77 DataTableSpec (org.knime.core.data.DataTableSpec)57 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)40 DataColumnSpec (org.knime.core.data.DataColumnSpec)31 PortObjectSpec (org.knime.core.node.port.PortObjectSpec)30 PMMLPortObject (org.knime.core.node.port.pmml.PMMLPortObject)23 PMMLPortObjectSpecCreator (org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator)23 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)22 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)20 BufferedDataTable (org.knime.core.node.BufferedDataTable)15 PortObject (org.knime.core.node.port.PortObject)12 DataCell (org.knime.core.data.DataCell)10 DoubleValue (org.knime.core.data.DoubleValue)10 DataRow (org.knime.core.data.DataRow)8 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)7 ArrayList (java.util.ArrayList)6 LinkedList (java.util.LinkedList)6 DataColumnDomain (org.knime.core.data.DataColumnDomain)6 DoubleCell (org.knime.core.data.def.DoubleCell)6 IOException (java.io.IOException)4