use of org.knime.core.node.port.pmml.PMMLPortObjectSpec in project knime-core by knime.
the class GradientBoostingPMMLPredictorNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
PMMLPortObjectSpec pmmlSpec = (PMMLPortObjectSpec) inSpecs[0];
DataType targetType = extractTargetType(pmmlSpec);
if (m_isRegression && !targetType.isCompatible(DoubleValue.class)) {
throw new InvalidSettingsException("This node expects a regression model.");
} else if (!m_isRegression && !targetType.isCompatible(StringValue.class)) {
throw new InvalidSettingsException("This node expectes a classification model.");
}
try {
AbstractTreeModelPMMLTranslator.checkPMMLSpec(pmmlSpec);
} catch (IllegalArgumentException e) {
throw new InvalidSettingsException(e.getMessage());
}
TreeEnsembleModelPortObjectSpec modelSpec = translateSpec(pmmlSpec);
String targetColName = modelSpec.getTargetColumn().getName();
if (m_configuration == null) {
m_configuration = TreeEnsemblePredictorConfiguration.createDefault(m_isRegression, targetColName);
} else if (!m_configuration.isChangePredictionColumnName()) {
m_configuration.setPredictionColumnName(TreeEnsemblePredictorConfiguration.getPredictColumnName(targetColName));
}
modelSpec.assertTargetTypeMatches(m_isRegression);
DataTableSpec dataSpec = (DataTableSpec) inSpecs[1];
final GradientBoostingPredictor<GradientBoostedTreesModel> pred = new GradientBoostingPredictor<>(null, modelSpec, dataSpec, m_configuration);
return new PortObjectSpec[] { pred.getPredictionRearranger().createSpec() };
}
use of org.knime.core.node.port.pmml.PMMLPortObjectSpec in project knime-core by knime.
the class Many2OneColPMMLNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
DataTableSpec inDataSpec = (DataTableSpec) inSpecs[0];
if (m_includedColumns.getIncludeList().size() <= 0) {
setWarningMessage("No column selected. Node will have no effect!");
}
// if it is not a reg exp it must be double compatible
if (!m_includeMethod.getStringValue().equals(IncludeMethod.RegExpPattern.name())) {
for (String colName : m_includedColumns.getIncludeList()) {
if (!inDataSpec.getColumnSpec(colName).getType().isCompatible(DoubleValue.class)) {
throw new InvalidSettingsException("For selected include method '" + m_includeMethod.getStringValue() + "' only double compatible values are allowed." + " Column '" + colName + "' is not.");
}
}
}
ColumnRearranger rearranger = createRearranger(inDataSpec, getCellFactory(inDataSpec));
if (m_pmmlEnabled) {
PMMLPortObjectSpec pmmlSpec = (PMMLPortObjectSpec) inSpecs[1];
PMMLPortObjectSpecCreator pmmlSpecCreator = new PMMLPortObjectSpecCreator(pmmlSpec, inDataSpec);
return new PortObjectSpec[] { rearranger.createSpec(), pmmlSpecCreator.createSpec() };
} else {
return new DataTableSpec[] { rearranger.createSpec() };
}
}
use of org.knime.core.node.port.pmml.PMMLPortObjectSpec in project knime-core by knime.
the class LogRegLearnerNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
final BufferedDataTable data = (BufferedDataTable) inObjects[0];
DataTableSpec tableSpec = data.getDataTableSpec();
// handle the optional PMML input
PMMLPortObject inPMMLPort = m_pmmlInEnabled ? (PMMLPortObject) inObjects[1] : null;
PMMLPortObjectSpec inPMMLSpec = null;
if (inPMMLPort != null) {
inPMMLSpec = inPMMLPort.getSpec();
} else {
PMMLPortObjectSpecCreator creator = new PMMLPortObjectSpecCreator(tableSpec);
inPMMLSpec = creator.createSpec();
inPMMLPort = new PMMLPortObject(inPMMLSpec);
}
LogRegLearner learner = new LogRegLearner(new PortObjectSpec[] { tableSpec, inPMMLSpec }, m_pmmlInEnabled, m_settings);
m_content = learner.execute(new PortObject[] { data, inPMMLPort }, exec);
String warn = learner.getWarningMessage();
if (warn != null) {
setWarningMessage(warn);
}
// third argument is ignored since we provide a port
PMMLPortObject outPMMLPort = new PMMLPortObject((PMMLPortObjectSpec) learner.getOutputSpec()[0], inPMMLPort, null);
PMMLGeneralRegressionTranslator trans = new PMMLGeneralRegressionTranslator(m_content.createGeneralRegressionContent());
outPMMLPort.addModelTranslater(trans);
return new PortObject[] { outPMMLPort, m_content.createTablePortObject(exec) };
}
use of org.knime.core.node.port.pmml.PMMLPortObjectSpec in project knime-core by knime.
the class LogisticRegressionContent method load.
/**
* @param parContent the content that holds the internals
* @param spec the data table spec of the training data
* @return a instance with he loaded values
* @throws InvalidSettingsException when data are not well formed
*/
static LogisticRegressionContent load(final ModelContentRO parContent, final DataTableSpec spec) throws InvalidSettingsException {
String target = parContent.getString(CFG_TARGET);
String[] learningCols = parContent.getStringArray(CFG_LEARNING_COLS);
PMMLPortObjectSpec pmmlSpec = createSpec(spec, target, learningCols);
String[] factors = parContent.getStringArray(CFG_FACTORS);
String[] covariates = parContent.getStringArray(CFG_COVARIATES);
double[] coeff = parContent.getDoubleArray(CFG_COEFFICIENTS);
double likelihood = parContent.getDouble(CFG_LOG_LIKELIHOOD);
double[] covMat = parContent.getDoubleArray(CFG_COVARIANCE_MATRIX);
int iter = parContent.getInt(CFG_ITER);
// introduced in 2.9
DataCell targetReferenceCategory = parContent.getDataCell(CFG_TARGET_REFERENCE_CATEGORY, null);
boolean sortTargetCategories = parContent.getBoolean(CFG_SORT_TARGET_CATEGORIES, true);
boolean sortFactorsCategories = parContent.getBoolean(CFG_SORT_FACTORS_CATEGORIES, true);
return new LogisticRegressionContent(pmmlSpec, Arrays.asList(factors), Arrays.asList(covariates), targetReferenceCategory, sortTargetCategories, sortFactorsCategories, toMatrix(coeff, coeff.length), likelihood, toMatrix(covMat, coeff.length), iter);
}
use of org.knime.core.node.port.pmml.PMMLPortObjectSpec 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;
}
}
Aggregations