Search in sources :

Example 51 with PMMLPortObjectSpecCreator

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

the class AbstractNormalizerPMMLNodeModel method prepareConfigure.

/**
 * @param inSpecs An array of DataTableSpecs (as many as this model has
 *            inputs).
 * @return An array of DataTableSpecs (as many as this model has outputs)
 *
 * @throws InvalidSettingsException if the <code>#configure()</code> failed,
 *             that is, the settings are inconsistent with given
 *             DataTableSpec elements.
 */
@Override
protected PortObjectSpec[] prepareConfigure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    DataTableSpec spec = (DataTableSpec) inSpecs[0];
    PMMLPortObjectSpecCreator pmmlSpecCreator;
    if (m_hasModelIn) {
        PMMLPortObjectSpec pmmlSpec = (PMMLPortObjectSpec) inSpecs[1];
        // extract selected numeric columns
        updateNumericColumnSelection(spec);
        if (getMode() == NONORM_MODE) {
            return new PortObjectSpec[] { spec, pmmlSpec };
        }
        pmmlSpecCreator = new PMMLPortObjectSpecCreator(pmmlSpec, spec);
    } else {
        // extract selected numeric columns
        updateNumericColumnSelection(spec);
        if (getMode() == NONORM_MODE) {
            return new PortObjectSpec[] { spec };
        }
        pmmlSpecCreator = new PMMLPortObjectSpecCreator(spec);
    }
    return new PortObjectSpec[] { Normalizer2.generateNewSpec(spec, getColumns()), pmmlSpecCreator.createSpec() };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) PMMLPortObjectSpecCreator(org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator)

Example 52 with PMMLPortObjectSpecCreator

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

the class AbstractNormalizerPMMLNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
    CalculationResult result = calculate(inObjects, exec);
    BufferedDataTable outTable = result.getDataTable();
    // the optional PMML in port (can be null)
    PMMLPortObject inPMMLPort = m_hasModelIn ? (PMMLPortObject) inObjects[1] : null;
    PMMLNormalizeTranslator trans = new PMMLNormalizeTranslator(result.getConfig(), new DerivedFieldMapper(inPMMLPort));
    DataTableSpec dataTableSpec = (DataTableSpec) inObjects[0].getSpec();
    PMMLPortObjectSpecCreator creator = new PMMLPortObjectSpecCreator(inPMMLPort, dataTableSpec);
    PMMLPortObject outPMMLPort = new PMMLPortObject(creator.createSpec(), inPMMLPort);
    outPMMLPort.addGlobalTransformations(trans.exportToTransDict());
    return new PortObject[] { outTable, outPMMLPort };
}
Also used : DerivedFieldMapper(org.knime.core.node.port.pmml.preproc.DerivedFieldMapper) DataTableSpec(org.knime.core.data.DataTableSpec) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) BufferedDataTable(org.knime.core.node.BufferedDataTable) PMMLNormalizeTranslator(org.knime.base.data.normalize.PMMLNormalizeTranslator) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) PortObject(org.knime.core.node.port.PortObject) PMMLPortObjectSpecCreator(org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator)

Example 53 with PMMLPortObjectSpecCreator

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

the class CategoryToNumberNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    DataTableSpec inSpec = (DataTableSpec) inSpecs[0];
    List<String> inputCols = new ArrayList<String>();
    for (DataColumnSpec column : inSpec) {
        if (column.getType().isCompatible(StringValue.class)) {
            inputCols.add(column.getName());
        }
    }
    FilterResult filter = m_settings.getFilterConfiguration().applyTo(inSpec);
    String[] rmFromIncl = filter.getRemovedFromIncludes();
    if (m_settings.getFilterConfiguration().isEnforceInclusion() && rmFromIncl.length != 0) {
        throw new InvalidSettingsException("Input table does not contain the following selected column(s): " + ConvenienceMethods.getShortStringFrom(new HashSet<String>(Arrays.asList(rmFromIncl)), 3));
    }
    m_included = filter.getIncludes();
    if (m_included.length == 0) {
        setWarningMessage("No columns selected.");
    }
    ColumnRearranger rearranger = createRearranger(inSpec);
    PMMLPortObjectSpec pmmlSpec = m_pmmlInEnabled ? (PMMLPortObjectSpec) inSpecs[1] : null;
    PMMLPortObjectSpecCreator pmmlSpecCreator = new PMMLPortObjectSpecCreator(pmmlSpec, inSpec);
    pmmlSpecCreator.addPreprocColNames(inputCols);
    return new PortObjectSpec[] { rearranger.createSpec(), pmmlSpecCreator.createSpec() };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) ArrayList(java.util.ArrayList) DataColumnSpec(org.knime.core.data.DataColumnSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) FilterResult(org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult) PMMLPortObjectSpecCreator(org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator)

Example 54 with PMMLPortObjectSpecCreator

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

the class LinearRegressionContent method createPortObjectSpec.

/**
 * Creates a PMML port object spec based on all columns in the given data
 * table spec. <b>The target column must be the last column in the table
 * spec!</b>
 *
 * @param pmmlSpec the optional {@link PMMLPortObjectSpec} which can be null
 * @param tableSpec the full data table spec with which the regression
 *      model was created.
 * @param learningSpec a data table spec containing only columns used for
 *      learning the model
 * @return a PMML port object spec
 * @throws InvalidSettingsException if PMML incompatible type was found
 */
public static PMMLPortObjectSpec createPortObjectSpec(final PMMLPortObjectSpec pmmlSpec, final DataTableSpec tableSpec, final DataTableSpec learningSpec) throws InvalidSettingsException {
    PMMLPortObjectSpecCreator c = new PMMLPortObjectSpecCreator(pmmlSpec, tableSpec);
    int numColumns = learningSpec.getNumColumns();
    String[] learningCols = new String[numColumns - 1];
    for (int i = 0; i < learningCols.length; i++) {
        learningCols[i] = learningSpec.getColumnSpec(i).getName();
    }
    c.setLearningCols(FilterColumnTable.createFilterTableSpec(learningSpec, learningCols));
    c.setTargetCols(Arrays.asList(learningSpec.getColumnSpec(numColumns - 1)));
    return c.createSpec();
}
Also used : PMMLPortObjectSpecCreator(org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator)

Example 55 with PMMLPortObjectSpecCreator

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

the class GBTPMMLExporterNodeModel method createPMMLSpec.

private PMMLPortObjectSpec createPMMLSpec(final TreeEnsembleModelPortObjectSpec spec, final AbstractGradientBoostingModel model) {
    DataColumnSpec targetSpec = spec.getTargetColumn();
    DataTableSpec learnFeatureSpec = spec.getLearnTableSpec();
    if (containsVector(learnFeatureSpec)) {
        setWarningMessage("The model was learned on a vector column. It's possible to export the model " + "to PMML but it won't be possible to import it from the exported PMML.");
    }
    if (model == null && containsVector(learnFeatureSpec)) {
        // at this point we don't know how long the vector column is
        return null;
    } else if (model != null) {
        // possibly expand vectors with model
        learnFeatureSpec = model.getLearnAttributeSpec(learnFeatureSpec);
    }
    DataTableSpec completeLearnSpec = new DataTableSpec(learnFeatureSpec, new DataTableSpec(targetSpec));
    PMMLPortObjectSpecCreator pmmlSpecCreator = new PMMLPortObjectSpecCreator(completeLearnSpec);
    try {
        pmmlSpecCreator.setLearningCols(learnFeatureSpec);
    } catch (InvalidSettingsException e) {
        // (as of KNIME v2.5.1)
        throw new IllegalStateException(e);
    }
    pmmlSpecCreator.setTargetCol(targetSpec);
    return pmmlSpecCreator.createSpec();
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpec(org.knime.core.data.DataColumnSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) 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