Search in sources :

Example 1 with LogRegPredictor

use of org.knime.base.node.mine.regression.predict2.LogRegPredictor 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

PMMLPredictor (org.knime.base.node.mine.regression.pmmlgreg.PMMLPredictor)1 LogRegPredictor (org.knime.base.node.mine.regression.predict2.LogRegPredictor)1 RegressionPredictorSettings (org.knime.base.node.mine.regression.predict2.RegressionPredictorSettings)1 DataColumnSpec (org.knime.core.data.DataColumnSpec)1 DoubleValue (org.knime.core.data.DoubleValue)1 NominalValue (org.knime.core.data.NominalValue)1 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)1 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)1