Search in sources :

Example 1 with RegressionPredictorSettings

use of org.knime.base.node.mine.regression.predict2.RegressionPredictorSettings in project knime-core by knime.

the class GeneralRegressionPredictorNodeModel method createRegressionPredictorSettings.

/**
 * Create RegressionPredictorSettings to achieve a backward compatible behavior.
 */
private RegressionPredictorSettings createRegressionPredictorSettings(final PMMLPortObjectSpec portSpec, final DataTableSpec tableSpec) {
    RegressionPredictorSettings s = new RegressionPredictorSettings();
    s.setIncludeProbabilities(m_settings.getIncludeProbabilities());
    s.setHasCustomPredictionName(true);
    String targetName = portSpec.getTargetFields().get(0);
    if (tableSpec.containsName(targetName) && !targetName.toLowerCase().endsWith("(prediction)")) {
        targetName = targetName + " (prediction)";
    }
    s.setCustomPredictionName(targetName);
    return s;
}
Also used : RegressionPredictorSettings(org.knime.base.node.mine.regression.predict2.RegressionPredictorSettings)

Example 2 with RegressionPredictorSettings

use of org.knime.base.node.mine.regression.predict2.RegressionPredictorSettings in project knime-core by knime.

the class GeneralRegressionPredictorNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    PMMLPortObjectSpec regModelSpec = (PMMLPortObjectSpec) inSpecs[0];
    DataTableSpec dataSpec = (DataTableSpec) inSpecs[1];
    if (dataSpec == null || regModelSpec == null) {
        throw new InvalidSettingsException("No input specification available");
    }
    RegressionPredictorSettings s = createRegressionPredictorSettings(regModelSpec, dataSpec);
    if (null != RegressionPredictorCellFactory.createColumnSpec(regModelSpec, dataSpec, s)) {
        ColumnRearranger c = new ColumnRearranger(dataSpec);
        c.append(new RegressionPredictorCellFactory(regModelSpec, dataSpec, s) {

            @Override
            public DataCell[] getCells(final DataRow row) {
                // not called during configure.
                return null;
            }
        });
        DataTableSpec outSpec = c.createSpec();
        return new DataTableSpec[] { outSpec };
    } else {
        return null;
    }
}
Also used : RegressionPredictorSettings(org.knime.base.node.mine.regression.predict2.RegressionPredictorSettings) PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) DataTableSpec(org.knime.core.data.DataTableSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) DataRow(org.knime.core.data.DataRow) RegressionPredictorCellFactory(org.knime.base.node.mine.regression.predict2.RegressionPredictorCellFactory)

Example 3 with RegressionPredictorSettings

use of org.knime.base.node.mine.regression.predict2.RegressionPredictorSettings in project knime-core by knime.

the class GeneralRegressionPredictorNodeModel method createRearranger.

private ColumnRearranger createRearranger(final PMMLGeneralRegressionContent content, final PMMLPortObjectSpec pmmlSpec, final DataTableSpec inDataSpec) throws InvalidSettingsException {
    if (content == null) {
        throw new InvalidSettingsException("No input");
    }
    // the predictor can only predict logistic regression models
    if (!content.getModelType().equals(ModelType.multinomialLogistic)) {
        throw new InvalidSettingsException("Model Type: " + content.getModelType() + " is not supported.");
    }
    if (!content.getFunctionName().equals(FunctionName.classification)) {
        throw new InvalidSettingsException("Function Name: " + content.getFunctionName() + " is not supported.");
    }
    // are nominal values
    for (PMMLPredictor factor : content.getFactorList()) {
        DataColumnSpec columnSpec = inDataSpec.getColumnSpec(factor.getName());
        if (null == columnSpec) {
            throw new InvalidSettingsException("The column \"" + factor.getName() + "\" is in the model but not in given table.");
        }
        if (!columnSpec.getType().isCompatible(NominalValue.class)) {
            throw new InvalidSettingsException("The column \"" + factor.getName() + "\" is supposed to be nominal.");
        }
    }
    // are numeric values
    for (PMMLPredictor covariate : content.getCovariateList()) {
        DataColumnSpec columnSpec = inDataSpec.getColumnSpec(covariate.getName());
        if (null == columnSpec) {
            throw new InvalidSettingsException("The column \"" + covariate.getName() + "\" is in the model but not in given table.");
        }
        if (!columnSpec.getType().isCompatible(DoubleValue.class)) {
            throw new InvalidSettingsException("The column \"" + covariate.getName() + "\" is supposed to be numeric.");
        }
    }
    ColumnRearranger c = new ColumnRearranger(inDataSpec);
    RegressionPredictorSettings s = createRegressionPredictorSettings(pmmlSpec, inDataSpec);
    c.append(new LogRegPredictor(content, inDataSpec, pmmlSpec, pmmlSpec.getTargetFields().get(0), s));
    return c;
}
Also used : RegressionPredictorSettings(org.knime.base.node.mine.regression.predict2.RegressionPredictorSettings) LogRegPredictor(org.knime.base.node.mine.regression.predict2.LogRegPredictor) PMMLPredictor(org.knime.base.node.mine.regression.pmmlgreg.PMMLPredictor) DataColumnSpec(org.knime.core.data.DataColumnSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) DoubleValue(org.knime.core.data.DoubleValue) NominalValue(org.knime.core.data.NominalValue)

Aggregations

RegressionPredictorSettings (org.knime.base.node.mine.regression.predict2.RegressionPredictorSettings)3 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)2 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)2 PMMLPredictor (org.knime.base.node.mine.regression.pmmlgreg.PMMLPredictor)1 LogRegPredictor (org.knime.base.node.mine.regression.predict2.LogRegPredictor)1 RegressionPredictorCellFactory (org.knime.base.node.mine.regression.predict2.RegressionPredictorCellFactory)1 DataColumnSpec (org.knime.core.data.DataColumnSpec)1 DataRow (org.knime.core.data.DataRow)1 DataTableSpec (org.knime.core.data.DataTableSpec)1 DoubleValue (org.knime.core.data.DoubleValue)1 NominalValue (org.knime.core.data.NominalValue)1 PMMLPortObjectSpec (org.knime.core.node.port.pmml.PMMLPortObjectSpec)1