use of org.knime.core.data.DataTableSpec in project knime-core by knime.
the class MLPPredictorNodeModel method configure.
/**
* The additional columns are created based on the model which is loaded in
* the execute-method. Therefore, new DataTableSpecs are not available until
* execute has been called.
*
* {@inheritDoc}
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
PMMLPortObjectSpec modelspec = (PMMLPortObjectSpec) inSpecs[0];
DataTableSpec testSpec = (DataTableSpec) inSpecs[1];
List<DataColumnSpec> targetCols = modelspec.getTargetCols();
if (targetCols.isEmpty()) {
throw new InvalidSettingsException("The PMML model" + " does not specify a target column for the prediction.");
}
DataColumnSpec targetCol = targetCols.iterator().next();
/*
* Check consistency between model and inputs, find columns to work on.
*/
for (String incol : modelspec.getLearningFields()) {
if (!testSpec.containsName(incol)) {
throw new InvalidSettingsException("Could not find " + incol + " in inputspec");
}
}
m_columns = getLearningColumnIndices(testSpec, modelspec);
MLPClassificationFactory mymlp;
// Regression
if (targetCol.getType().isCompatible(DoubleValue.class)) {
mymlp = new MLPClassificationFactory(true, m_columns, targetCol);
} else {
// Classification
mymlp = new MLPClassificationFactory(false, m_columns, targetCol);
}
ColumnRearranger colre = new ColumnRearranger(testSpec);
colre.append(mymlp);
return new DataTableSpec[] { colre.createSpec() };
}
use of org.knime.core.data.DataTableSpec in project knime-core by knime.
the class LinRegLearnerNodeDialogPane method loadSettingsFrom.
/**
* {@inheritDoc}
*/
@Override
protected void loadSettingsFrom(final NodeSettingsRO settings, final PortObjectSpec[] specs) throws NotConfigurableException {
// must check if there are at least two numeric columns
int numColsCount = 0;
DataTableSpec dts = (DataTableSpec) specs[0];
for (DataColumnSpec c : dts) {
if (c.getType().isCompatible(DoubleValue.class)) {
numColsCount++;
if (numColsCount >= 2) {
break;
}
}
}
if (numColsCount < 2) {
throw new NotConfigurableException("Too few numeric columns " + "(need at least 2): " + numColsCount);
}
boolean includeAll = settings.getBoolean(LinRegLearnerNodeModel.CFG_VARIATES_USE_ALL, false);
String[] includes = settings.getStringArray(LinRegLearnerNodeModel.CFG_VARIATES, new String[0]);
String target = settings.getString(LinRegLearnerNodeModel.CFG_TARGET, null);
boolean isCalcError = settings.getBoolean(LinRegLearnerNodeModel.CFG_CALC_ERROR, true);
int first = settings.getInt(LinRegLearnerNodeModel.CFG_FROMROW, 1);
int count = settings.getInt(LinRegLearnerNodeModel.CFG_ROWCNT, 10000);
m_selectionPanel.update(dts, target);
m_filterPanel.setKeepAllSelected(includeAll);
// if includes list is empty, put everything into the include list
m_filterPanel.update(dts, includes.length == 0, includes);
// must hide the target from filter panel
// updating m_filterPanel first does not work as the first
// element in the spec will always be in the exclude list.
String selected = m_selectionPanel.getSelectedColumn();
if (selected != null) {
DataColumnSpec colSpec = dts.getColumnSpec(selected);
m_filterPanel.hideColumns(colSpec);
}
m_isCalcErrorChecker.setSelected(isCalcError);
m_firstSpinner.setValue(first);
m_countSpinner.setValue(count);
}
use of org.knime.core.data.DataTableSpec 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.data.DataTableSpec in project knime-core by knime.
the class RegressionPredictorNodeModel method adjustSpecOfRegressionPredictorTable.
private BufferedDataTable adjustSpecOfRegressionPredictorTable(final BufferedDataTable table, final PortObject[] inData, final ExecutionContext exec) throws InvalidSettingsException {
String predColumn = determinPredictedColumName(inData);
if (predColumn != null) {
DataColumnSpec[] colSpecs = getColumnSpecs(table.getSpec());
colSpecs[colSpecs.length - 1] = replaceNameOf(colSpecs[colSpecs.length - 1], predColumn);
return exec.createSpecReplacerTable(table, new DataTableSpec(colSpecs));
} else {
return table;
}
}
use of org.knime.core.data.DataTableSpec in project knime-core by knime.
the class RegressionPredictorNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
public PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
PMMLPortObject port = (PMMLPortObject) inData[0];
List<Node> models = port.getPMMLValue().getModels(PMMLModelType.GeneralRegressionModel);
if (models.isEmpty()) {
LOGGER.warn("No regression models in the input PMML.");
@SuppressWarnings("deprecation") org.knime.base.node.mine.regression.predict.RegressionPredictorNodeModel regrPredictor = new org.knime.base.node.mine.regression.predict.RegressionPredictorNodeModel();
@SuppressWarnings("deprecation") PortObject[] regrPredOut = regrPredictor.execute(inData, exec);
if (regrPredOut.length > 0 && regrPredOut[0] instanceof BufferedDataTable) {
BufferedDataTable regrPredOutTable = (BufferedDataTable) regrPredOut[0];
// replace name of prediction column (the last column of regrPredOutTable)
return new PortObject[] { adjustSpecOfRegressionPredictorTable(regrPredOutTable, inData, exec) };
} else {
return regrPredOut;
}
}
PMMLGeneralRegressionTranslator trans = new PMMLGeneralRegressionTranslator();
port.initializeModelTranslator(trans);
BufferedDataTable data = (BufferedDataTable) inData[1];
DataTableSpec spec = data.getDataTableSpec();
ColumnRearranger c = createRearranger(trans.getContent(), port.getSpec(), spec);
BufferedDataTable out = exec.createColumnRearrangeTable(data, c, exec);
return new BufferedDataTable[] { out };
}
Aggregations