Search in sources :

Example 51 with PMMLPortObjectSpec

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

the class SVMPredictorNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    DataTableSpec testSpec = (DataTableSpec) inSpecs[1];
    PMMLPortObjectSpec trainingSpec = (PMMLPortObjectSpec) inSpecs[0];
    // try to find all columns (except the class column)
    Vector<Integer> colindices = new Vector<Integer>();
    for (DataColumnSpec colspec : trainingSpec.getLearningCols()) {
        if (colspec.getType().isCompatible(DoubleValue.class)) {
            int colindex = testSpec.findColumnIndex(colspec.getName());
            if (colindex < 0) {
                throw new InvalidSettingsException("Column " + "\'" + colspec.getName() + "\' not found" + " in test data");
            }
            colindices.add(colindex);
        }
    }
    m_colindices = new int[colindices.size()];
    for (int i = 0; i < m_colindices.length; i++) {
        m_colindices[i] = colindices.get(i);
    }
    SVMPredictor svmpredict = new SVMPredictor(m_svms, m_colindices);
    ColumnRearranger colre = new ColumnRearranger(testSpec);
    colre.append(svmpredict);
    return new DataTableSpec[] { colre.createSpec() };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) DataColumnSpec(org.knime.core.data.DataColumnSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) Vector(java.util.Vector)

Example 52 with PMMLPortObjectSpec

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

the class TreeEnsembleModelPortObject method createDecisionTreePMMLPortObject.

public PMMLPortObject createDecisionTreePMMLPortObject(final int modelIndex) {
    DataTableSpec attributeLearnSpec = m_ensembleModel.getLearnAttributeSpec(m_spec.getLearnTableSpec());
    DataColumnSpec targetSpec = m_spec.getTargetColumn();
    PMMLPortObjectSpecCreator pmmlSpecCreator = new PMMLPortObjectSpecCreator(new DataTableSpec(attributeLearnSpec, new DataTableSpec(targetSpec)));
    try {
        pmmlSpecCreator.setLearningCols(attributeLearnSpec);
    } catch (InvalidSettingsException e) {
        // (as of KNIME v2.5.1)
        throw new IllegalStateException(e);
    }
    pmmlSpecCreator.setTargetCol(targetSpec);
    PMMLPortObjectSpec pmmlSpec = pmmlSpecCreator.createSpec();
    PMMLPortObject portObject = new PMMLPortObject(pmmlSpec);
    TreeModelClassification model = m_ensembleModel.getTreeModelClassification(modelIndex);
    portObject.addModelTranslater(new TreeModelPMMLTranslator(model));
    return portObject;
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) DataColumnSpec(org.knime.core.data.DataColumnSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) PMMLPortObjectSpecCreator(org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator)

Example 53 with PMMLPortObjectSpec

use of org.knime.core.node.port.pmml.PMMLPortObjectSpec 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 54 with PMMLPortObjectSpec

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

the class LinReg2Learner method execute.

/**
 * Compute linear regression model.
 *
 * @param portObjects The input objects.
 * @param exec the execution context
 * @return a {@link LinearRegressionContent} storing computed data
 * @throws Exception if computation of the linear regression model is
 * not successful or if given data is inconsistent with the settings
 * defined in the constructor.
 * @see LinReg2LearnerNodeModel#execute(PortObject[], ExecutionContext)
 */
public LinearRegressionContent execute(final PortObject[] portObjects, final ExecutionContext exec) throws Exception {
    BufferedDataTable data = (BufferedDataTable) portObjects[0];
    PMMLPortObject inPMMLPort = (PMMLPortObject) portObjects[1];
    PMMLPortObjectSpec inPMMLSpec = inPMMLPort.getSpec();
    init(data.getDataTableSpec(), inPMMLSpec, Collections.<String>emptySet());
    double calcDomainTime = 0.2;
    exec.setMessage("Analyzing categorical data");
    BufferedDataTable dataTable = recalcDomainOfLearningFields(data, inPMMLSpec, exec.createSubExecutionContext(calcDomainTime));
    exec.setMessage("Computing linear regression model");
    return m_learner.perform(dataTable, exec.createSubExecutionContext(1.0 - calcDomainTime));
}
Also used : PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) BufferedDataTable(org.knime.core.node.BufferedDataTable)

Example 55 with PMMLPortObjectSpec

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

the class PolyRegLearnerNodeModel method createPMMLModel.

private PMMLPortObject createPMMLModel(final PMMLPortObject inPMMLPort, final DataTableSpec inSpec) throws InvalidSettingsException, SAXException {
    NumericPredictor[] preds = new NumericPredictor[m_betas.length - 1];
    int deg = m_settings.getDegree();
    for (int i = 0; i < m_columnNames.length; i++) {
        for (int k = 0; k < deg; k++) {
            preds[i * deg + k] = new NumericPredictor(m_columnNames[i], k + 1, m_betas[i * deg + k + 1]);
        }
    }
    RegressionTable tab = new RegressionTable(m_betas[0], preds);
    PMMLPortObjectSpec pmmlSpec = null;
    if (inPMMLPort != null) {
        pmmlSpec = inPMMLPort.getSpec();
    }
    PMMLPortObjectSpec spec = createModelSpec(pmmlSpec, inSpec);
    /* To maintain compatibility with the previous SAX-based implementation.
         * */
    String targetField = "Response";
    List<String> targetFields = spec.getTargetFields();
    if (!targetFields.isEmpty()) {
        targetField = targetFields.get(0);
    }
    PMMLPortObject outPMMLPort = new PMMLPortObject(spec, inPMMLPort, inSpec);
    PMMLRegressionTranslator trans = new PMMLRegressionTranslator("KNIME Polynomial Regression", "PolynomialRegression", tab, targetField);
    outPMMLPort.addModelTranslater(trans);
    return outPMMLPort;
}
Also used : PMMLRegressionTranslator(org.knime.base.node.mine.regression.PMMLRegressionTranslator) PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) NumericPredictor(org.knime.base.node.mine.regression.PMMLRegressionTranslator.NumericPredictor) RegressionTable(org.knime.base.node.mine.regression.PMMLRegressionTranslator.RegressionTable)

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