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;
}
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;
}
}
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;
}
Aggregations