Search in sources :

Example 41 with PMMLPortObjectSpecCreator

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

the class NumberToStringNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    DataTableSpec dts = (DataTableSpec) inSpecs[0];
    // find indices to work on
    int[] indices = findColumnIndices(dts);
    ConverterFactory converterFac = new ConverterFactory(indices, dts);
    ColumnRearranger colre = new ColumnRearranger(dts);
    colre.replace(converterFac, indices);
    DataTableSpec outDataSpec = 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[] { outDataSpec, 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)

Example 42 with PMMLPortObjectSpecCreator

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

the class RegressionContent method createSpec.

/**
 * @param spec The input table spec.
 * @param target The target column name.
 * @param learningCols The columns used for learning.
 * @return The {@link PMMLPortObjectSpec} to corresponding to the generated {@link PMMLPortObject}.
 */
protected static PMMLPortObjectSpec createSpec(final DataTableSpec spec, final String target, final String[] learningCols) {
    PMMLPortObjectSpecCreator c = new PMMLPortObjectSpecCreator(spec);
    c.setTargetColName(target);
    c.setLearningColsNames(Arrays.asList(learningCols));
    return c.createSpec();
}
Also used : PMMLPortObjectSpecCreator(org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator)

Example 43 with PMMLPortObjectSpecCreator

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

the class SVMLearnerNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    DataTableSpec inSpec = (DataTableSpec) inSpecs[0];
    PMMLPortObjectSpec portSpec = m_pmmlInEnabled ? (PMMLPortObjectSpec) inSpecs[1] : null;
    LearnColumnsAndColumnRearrangerTuple tuple = createTrainTableColumnRearranger(inSpec);
    DataTableSpec trainSpec = tuple.getTrainingRearranger().createSpec();
    PMMLPortObjectSpecCreator pmmlcreate = new PMMLPortObjectSpecCreator(portSpec, trainSpec);
    pmmlcreate.setTargetCol(tuple.getTargetColumn());
    pmmlcreate.setLearningCols(tuple.getLearningColumns());
    return new PortObjectSpec[] { pmmlcreate.createSpec() };
}
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) PMMLPortObjectSpecCreator(org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator)

Example 44 with PMMLPortObjectSpecCreator

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

the class RPropNodeModel method createPMMLPortObjectSpec.

private PMMLPortObjectSpec createPMMLPortObjectSpec(final PMMLPortObjectSpec pmmlSpec, final DataTableSpec spec, final List<String> learningCols, final List<String> targetCols) {
    PMMLPortObjectSpecCreator pmmlSpecCreator = new PMMLPortObjectSpecCreator(pmmlSpec, spec);
    pmmlSpecCreator.setLearningColsNames(learningCols);
    pmmlSpecCreator.setTargetColsNames(targetCols);
    return pmmlSpecCreator.createSpec();
}
Also used : PMMLPortObjectSpecCreator(org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator)

Example 45 with PMMLPortObjectSpecCreator

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

the class PMMLKNNNodeModel method createSpec.

/**
 * @param dataTableSpec
 * @return
 * @throws InvalidSettingsException when the input table contains invalid columns
 */
private PMMLPortObjectSpec createSpec(final DataTableSpec dataTableSpec) throws InvalidSettingsException {
    List<DataColumnSpec> learningColumns = new ArrayList<DataColumnSpec>();
    DataTableSpecCreator dataDictCreator = new DataTableSpecCreator();
    String[] selectedColumns = m_learningColumns.applyTo(dataTableSpec).getIncludes();
    if (selectedColumns.length == 0) {
        throw new InvalidSettingsException("No learning columns are selected.");
    }
    for (String lc : selectedColumns) {
        DataColumnSpec cs = dataTableSpec.getColumnSpec(lc);
        dataDictCreator.addColumns(cs);
        learningColumns.add(cs);
    }
    if (m_predColumnName.getStringValue() == null || !dataTableSpec.containsName(m_predColumnName.getStringValue())) {
        for (int i = 0; i < dataTableSpec.getNumColumns(); i++) {
            DataColumnSpec cspec = dataTableSpec.getColumnSpec(i);
            if (cspec.getType().isCompatible(StringValue.class)) {
                m_predColumnName.setStringValue(cspec.getName());
                setWarningMessage("No target column selected. Using \"" + cspec.getName() + "\".");
                break;
            }
        }
    }
    if (m_predColumnName.getStringValue() == null) {
        throw new InvalidSettingsException("The table does not contain a suitable target column.");
    }
    dataDictCreator.addColumns(dataTableSpec.getColumnSpec(m_predColumnName.getStringValue()));
    PMMLPortObjectSpecCreator specCreator = new PMMLPortObjectSpecCreator(dataDictCreator.createSpec());
    specCreator.setTargetCol(dataTableSpec.getColumnSpec(m_predColumnName.getStringValue()));
    specCreator.setLearningCols(learningColumns);
    return specCreator.createSpec();
}
Also used : DataColumnSpec(org.knime.core.data.DataColumnSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) DataTableSpecCreator(org.knime.core.data.DataTableSpecCreator) ArrayList(java.util.ArrayList) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) PMMLPortObjectSpecCreator(org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator)

Aggregations

PMMLPortObjectSpecCreator (org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator)62 DataTableSpec (org.knime.core.data.DataTableSpec)35 PMMLPortObjectSpec (org.knime.core.node.port.pmml.PMMLPortObjectSpec)24 DataColumnSpec (org.knime.core.data.DataColumnSpec)21 PMMLPortObject (org.knime.core.node.port.pmml.PMMLPortObject)21 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)19 BufferedDataTable (org.knime.core.node.BufferedDataTable)15 PortObjectSpec (org.knime.core.node.port.PortObjectSpec)14 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)13 PortObject (org.knime.core.node.port.PortObject)13 DerivedFieldMapper (org.knime.core.node.port.pmml.preproc.DerivedFieldMapper)11 ArrayList (java.util.ArrayList)10 DoubleValue (org.knime.core.data.DoubleValue)10 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)9 LinkedList (java.util.LinkedList)6 SettingsModelFilterString (org.knime.core.node.defaultnodesettings.SettingsModelFilterString)6 HashSet (java.util.HashSet)4 LinkedHashSet (java.util.LinkedHashSet)4 DataCell (org.knime.core.data.DataCell)3 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)3