Search in sources :

Example 61 with PMMLPortObjectSpec

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

the class FuzzyClusterNodeModel method configure.

/**
 * Number of columns in the output table is not deterministic.
 *
 * {@inheritDoc}
 */
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    DataTableSpec inspec = (DataTableSpec) inSpecs[0];
    if (m_keepAll || m_list == null) {
        m_list = new ArrayList<String>();
        for (DataColumnSpec colspec : inspec) {
            if (colspec.getType().isCompatible(DoubleValue.class)) {
                m_list.add(colspec.getName());
            }
        }
        if (!m_keepAll) {
            setWarningMessage("List of columns to use has been set" + " automatically, please check it in the dialog.");
        }
    }
    HashSet<String> listAsHash = new HashSet<String>(m_list);
    List<String> learningCols = new LinkedList<String>();
    for (int i = 0; i < inspec.getNumColumns(); i++) {
        String colname = inspec.getColumnSpec(i).getName();
        // if column is selected attribute
        if (listAsHash.remove(colname)) {
            learningCols.add(colname);
        }
    }
    if (!listAsHash.isEmpty()) {
        throw new InvalidSettingsException("Input table does not match " + "selected columns, unable to find column(s): " + listAsHash);
    }
    // number of clusters + winner cluster
    int nrCols = m_nrClusters + 1;
    if (m_noise) {
        // one column for the noise cluster
        nrCols++;
    }
    DataColumnSpec[] newSpec = new DataColumnSpec[nrCols];
    int cluster = 0;
    for (int j = 0; j < nrCols - 1; j++) {
        if (m_noise && j == (nrCols - 2)) {
            newSpec[j] = new DataColumnSpecCreator(FuzzyClusterNodeModel.NOISESPEC_KEY, DoubleCell.TYPE).createSpec();
            break;
        }
        newSpec[j] = new DataColumnSpecCreator(FuzzyClusterNodeModel.CLUSTER_KEY + cluster, DoubleCell.TYPE).createSpec();
        cluster++;
    }
    newSpec[newSpec.length - 1] = new DataColumnSpecCreator("Winner Cluster", StringCell.TYPE).createSpec();
    DataTableSpec newspec = new DataTableSpec(newSpec);
    DataTableSpec returnspec = new DataTableSpec(inspec, newspec);
    PMMLPortObjectSpec inPmmlSpec = m_enablePMMLInput ? (PMMLPortObjectSpec) inSpecs[1] : null;
    return new PortObjectSpec[] { returnspec, createPMMLPortObjectSpec(inPmmlSpec, inspec, learningCols) };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) LinkedList(java.util.LinkedList) DataColumnSpec(org.knime.core.data.DataColumnSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 62 with PMMLPortObjectSpec

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

the class DecTreeToImageNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected final PortObjectSpec[] configure(final PortObjectSpec[] inPOSpecs) throws InvalidSettingsException {
    // test if number of pixels will exceed Integer.MAX_VALUE
    double imgSize = m_settings.getWidth() * (double) m_settings.getHeight();
    if (imgSize > Integer.MAX_VALUE) {
        throw new InvalidSettingsException("The maximum image size (width * heigth) of " + NumberFormat.getIntegerInstance().format(Integer.MAX_VALUE) + " pixel is exceeded.");
    }
    if (inPOSpecs[1] != null) {
        PMMLPortObjectSpec treeSpec = (PMMLPortObjectSpec) inPOSpecs[0];
        DataTableSpec inSpec = (DataTableSpec) inPOSpecs[1];
        for (String learnColName : treeSpec.getLearningFields()) {
            if (!inSpec.containsName(learnColName)) {
                throw new InvalidSettingsException("Learning column \"" + learnColName + "\" not found in the data input (color information).");
            }
        }
    }
    return new PortObjectSpec[] { new ImagePortObjectSpec(PNGImageContent.TYPE) };
}
Also used : PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) DataTableSpec(org.knime.core.data.DataTableSpec) ImagePortObjectSpec(org.knime.core.node.port.image.ImagePortObjectSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) ImagePortObjectSpec(org.knime.core.node.port.image.ImagePortObjectSpec) PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) PortObjectSpec(org.knime.core.node.port.PortObjectSpec)

Example 63 with PMMLPortObjectSpec

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

the class DecTreePredictorNodeModel method createOutTableSpec.

private DataTableSpec createOutTableSpec(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    List<DataCell> predValues = null;
    if (m_showDistribution.getBooleanValue()) {
        predValues = getPredictionValues((PMMLPortObjectSpec) inSpecs[INMODELPORT]);
        if (predValues == null) {
            // no out spec can be determined
            return null;
        }
    }
    int numCols = (predValues == null ? 0 : predValues.size()) + 1;
    DataTableSpec inSpec = (DataTableSpec) inSpecs[INDATAPORT];
    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();
    PredictorHelper predictorHelper = PredictorHelper.getInstance();
    String trainingColumnName = ((PMMLPortObjectSpec) inSpecs[INMODELPORT]).getTargetFields().iterator().next();
    // add all distribution columns
    for (int i = 0; i < numCols - 1; i++) {
        assert predValues != null;
        DataColumnSpecCreator colSpecCreator = new DataColumnSpecCreator(predictorHelper.probabilityColumnName(trainingColumnName, predValues.get(i).toString(), m_probabilitySuffix.getStringValue()), DoubleCell.TYPE);
        // colSpecCreator.setProperties(propsRendering);
        colSpecCreator.setDomain(domain);
        newCols[i] = colSpecCreator.createSpec();
    }
    // add the prediction column
    String predictionColumnName = predictorHelper.computePredictionColumnName(m_predictionColumn.getStringValue(), m_overridePrediction.getBooleanValue(), 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) PredictorHelper(org.knime.base.node.mine.util.PredictorHelper) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) DoubleCell(org.knime.core.data.def.DoubleCell) DataColumnDomainCreator(org.knime.core.data.DataColumnDomainCreator) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) DataColumnSpec(org.knime.core.data.DataColumnSpec) DataColumnDomain(org.knime.core.data.DataColumnDomain) DataCell(org.knime.core.data.DataCell)

Example 64 with PMMLPortObjectSpec

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

the class PMMLReaderNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    // read the data dictionary and the mining schema and create a
    // PMMLPortObjectSpec
    String fileS = m_file.getStringValue();
    String warning = CheckUtils.checkSourceFile(fileS);
    if (warning != null) {
        setWarningMessage(warning);
    }
    URL url = getURLFromSettings(fileS);
    try {
        PMMLImport pmmlImport = new PMMLImport(url, false);
        m_pmmlPort = pmmlImport.getPortObject();
    } catch (IllegalArgumentException e) {
        String msg = "File \"" + url + "\" is not a valid PMML file:\n" + e.getMessage();
        setWarningMessage(msg);
        throw new InvalidSettingsException(msg);
    } catch (XmlException e) {
        throw new InvalidSettingsException(e);
    } catch (IOException e) {
        throw new InvalidSettingsException(e);
    }
    PMMLPortObjectSpec parsedSpec = m_pmmlPort.getSpec();
    PMMLPortObjectSpec outSpec = createPMMLOutSpec(m_hasPMMLIn ? (PMMLPortObjectSpec) inSpecs[0] : null, parsedSpec);
    return new PortObjectSpec[] { outSpec };
}
Also used : PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) XmlException(org.apache.xmlbeans.XmlException) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) IOException(java.io.IOException) URL(java.net.URL)

Example 65 with PMMLPortObjectSpec

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

the class NaiveBayesLearnerNodeModel2 method createPMMLSpec.

private PMMLPortObjectSpec createPMMLSpec(final DataTableSpec tableSpec, final PMMLPortObjectSpec modelSpec, final List<String> learnCols, final String classColumn) {
    final PMMLPortObjectSpecCreator pmmlSpecCreator = new PMMLPortObjectSpecCreator(modelSpec, tableSpec);
    pmmlSpecCreator.setLearningColsNames(learnCols);
    pmmlSpecCreator.setTargetColName(classColumn);
    final PMMLPortObjectSpec pmmlSpec = pmmlSpecCreator.createSpec();
    return pmmlSpec;
}
Also used : PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) 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