use of org.knime.core.node.port.pmml.PMMLPortObjectSpec in project knime-core by knime.
the class RegressionPredictorNodeDialogPane method loadSettingsFrom.
/**
* {@inheritDoc}
*/
@Override
protected void loadSettingsFrom(final NodeSettingsRO settings, final PortObjectSpec[] specs) throws NotConfigurableException {
RegressionPredictorSettings s = new RegressionPredictorSettings();
s.loadSettingsForDialog(settings);
m_hasCustomPredictionName.setSelected(s.getHasCustomPredictionName());
PMMLPortObjectSpec portSpec = (PMMLPortObjectSpec) specs[0];
DataTableSpec tableSpec = (DataTableSpec) specs[1];
if (s.getCustomPredictionName() != null) {
m_customPredictionName.setText(s.getCustomPredictionName());
} else {
try {
DataColumnSpec[] outSpec = RegressionPredictorCellFactory.createColumnSpec(portSpec, tableSpec, new RegressionPredictorSettings());
m_customPredictionName.setText(outSpec[outSpec.length - 1].getName());
} catch (InvalidSettingsException e) {
// Open dialog and give a chance define settings
}
}
m_includeProbs.setSelected(s.getIncludeProbabilities());
m_probColumnSuffix.setText(s.getPropColumnSuffix());
updateEnableState();
}
use of org.knime.core.node.port.pmml.PMMLPortObjectSpec in project knime-core by knime.
the class RegressionPredictorNodeModel 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");
}
if (regModelSpec.getTargetCols().get(0).getType().isCompatible(DoubleValue.class) && m_settings.getIncludeProbabilities()) {
setWarningMessage("The option \"Append columns with predicted probabilities\"" + " has only an effect for nominal targets");
}
if (null != RegressionPredictorCellFactory.createColumnSpec(regModelSpec, dataSpec, m_settings)) {
ColumnRearranger c = new ColumnRearranger(dataSpec);
c.append(new RegressionPredictorCellFactory(regModelSpec, dataSpec, m_settings) {
@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.core.node.port.pmml.PMMLPortObjectSpec in project knime-core by knime.
the class CategoryToNumberNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
DataTableSpec inSpec = (DataTableSpec) inSpecs[0];
List<String> inputCols = new ArrayList<String>();
for (DataColumnSpec column : inSpec) {
if (column.getType().isCompatible(StringValue.class)) {
inputCols.add(column.getName());
}
}
// Auto configuration when included columns are not set
if (null == m_settings.getIncludedColumns()) {
// when there is no column with nominal data
if (inputCols.isEmpty()) {
throw new InvalidSettingsException("No column in " + "the input compatible to \"StringValue\".");
} else {
// auto-configure
m_settings.setIncludedColumns(inputCols.toArray(new String[inputCols.size()]));
}
} else {
if (!m_settings.getIncludeAll()) {
if (m_settings.getIncludedColumns().length == 0) {
setWarningMessage("No columns selected.");
}
List<String> included = new ArrayList<String>();
included.addAll(Arrays.asList(m_settings.getIncludedColumns()));
included.removeAll(inputCols);
if (!included.isEmpty()) {
// output first missing column
throw new InvalidSettingsException("Missing column: " + included.get(0).toString());
}
} else {
if (inputCols.isEmpty()) {
throw new InvalidSettingsException("No column in " + "the input compatible to \"StringValue\".");
} else {
// automatically add all columns
m_settings.setIncludedColumns(inputCols.toArray(new String[inputCols.size()]));
}
}
}
ColumnRearranger rearranger = createRearranger(inSpec);
PMMLPortObjectSpec pmmlSpec = (PMMLPortObjectSpec) inSpecs[1];
PMMLPortObjectSpecCreator pmmlSpecCreator = new PMMLPortObjectSpecCreator(pmmlSpec, inSpec);
pmmlSpecCreator.addPreprocColNames(inputCols);
return new PortObjectSpec[] { rearranger.createSpec(), pmmlSpecCreator.createSpec() };
}
use of org.knime.core.node.port.pmml.PMMLPortObjectSpec in project knime-core by knime.
the class RegressionTreePMMLTranslatorNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
final RegressionTreeModelPortObject treePO = (RegressionTreeModelPortObject) inObjects[0];
final RegressionTreeModel model = treePO.getModel();
final RegressionTreeModelPortObjectSpec treeSpec = treePO.getSpec();
PMMLPortObjectSpec pmmlSpec = createPMMLSpec(treeSpec, model);
PMMLPortObject portObject = new PMMLPortObject(pmmlSpec);
final TreeModelRegression tree = model.getTreeModel();
final RegressionTreeModelPMMLTranslator translator = new RegressionTreeModelPMMLTranslator(tree, model.getMetaData(), treeSpec.getLearnTableSpec());
portObject.addModelTranslater(translator);
if (translator.hasWarning()) {
setWarningMessage(translator.getWarning());
}
return new PortObject[] { portObject };
}
use of org.knime.core.node.port.pmml.PMMLPortObjectSpec in project knime-core by knime.
the class GBTPMMLExporterNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
GradientBoostingModelPortObject gbtPO = (GradientBoostingModelPortObject) inObjects[0];
AbstractGBTModelPMMLTranslator<?> translator;
AbstractGradientBoostingModel gbtModel = gbtPO.getEnsembleModel();
if (gbtModel instanceof GradientBoostedTreesModel) {
translator = new RegressionGBTModelPMMLTranslator((GradientBoostedTreesModel) gbtModel, gbtPO.getSpec().getLearnTableSpec());
} else if (gbtModel instanceof MultiClassGradientBoostedTreesModel) {
translator = new ClassificationGBTModelPMMLTranslator((MultiClassGradientBoostedTreesModel) gbtModel, gbtPO.getSpec().getLearnTableSpec());
} else {
throw new IllegalArgumentException("Unknown gradient boosted trees model type '" + gbtModel.getClass().getSimpleName() + "'.");
}
PMMLPortObjectSpec pmmlSpec = createPMMLSpec(gbtPO.getSpec(), gbtModel);
PMMLPortObject pmmlPO = new PMMLPortObject(pmmlSpec);
pmmlPO.addModelTranslater(translator);
return new PortObject[] { pmmlPO };
}
Aggregations