use of org.knime.core.node.port.pmml.PMMLPortObject in project knime-core by knime.
the class DBNumericBinnerNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
final DatabasePortObjectSpec inDatabasePortObjectSpec = (DatabasePortObjectSpec) inSpecs[0];
DatabaseQueryConnectionSettings connectionSettings = inDatabasePortObjectSpec.getConnectionSettings(getCredentialsProvider());
boolean suppCase = connectionSettings.getUtility().supportsCase();
if (!suppCase) {
if (m_columnToBins.size() > 1) {
throw new InvalidSettingsException("Database does not support \"CASE\". Please choose only one column.");
}
}
if (m_columnToBins.isEmpty()) {
setWarningMessage("No columns selected for binning");
} else {
checkDuplicateBinNames();
}
DataTableSpec outDataTableSpec = DBAutoBinner.createNewDataTableSpec(inDatabasePortObjectSpec.getDataTableSpec(), m_columnToAppended);
PMMLPortObject outPMMLPortObject = createPMMLPortObject(inDatabasePortObjectSpec.getDataTableSpec(), outDataTableSpec);
DBBinnerMaps binnerMaps = DBAutoBinner.intoBinnerMaps(outPMMLPortObject, inDatabasePortObjectSpec.getDataTableSpec());
DatabasePortObjectSpec outDatabasePortObjectSpec = null;
try {
outDatabasePortObjectSpec = createDatabasePortObjectSpec(connectionSettings, inDatabasePortObjectSpec, binnerMaps);
} catch (InvalidKeyException | BadPaddingException | IllegalBlockSizeException | SQLException | IOException e) {
// TODO Auto-generated catch block
}
return new PortObjectSpec[] { outDatabasePortObjectSpec, outPMMLPortObject.getSpec() };
}
use of org.knime.core.node.port.pmml.PMMLPortObject in project knime-core by knime.
the class One2ManyColPMMLNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
BufferedDataTable inData = (BufferedDataTable) inObjects[0];
DataTableSpec dts = inData.getDataTableSpec();
checkColumnsSpecs(dts);
One2ManyCellFactory cellFactory = new One2ManyCellFactory(dts, m_includedColumns.getIncludeList(), m_appendOrgColName);
BufferedDataTable outData = exec.createColumnRearrangeTable(inData, createRearranger(dts, cellFactory), exec);
if (m_pmmlEnabled) {
// the optional PMML in port (can be null)
PMMLPortObject inPMMLPort = (PMMLPortObject) inObjects[1];
PMMLOne2ManyTranslator trans = new PMMLOne2ManyTranslator(cellFactory.getColumnMapping(), new DerivedFieldMapper(inPMMLPort));
PMMLPortObjectSpecCreator creator = new PMMLPortObjectSpecCreator(inPMMLPort, outData.getDataTableSpec());
PMMLPortObject outPMMLPort = new PMMLPortObject(creator.createSpec(), inPMMLPort);
outPMMLPort.addGlobalTransformations(trans.exportToTransDict());
return new PortObject[] { outData, outPMMLPort };
} else {
return new PortObject[] { outData };
}
}
use of org.knime.core.node.port.pmml.PMMLPortObject in project knime-core by knime.
the class SVMPredictorNodeModel 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.SupportVectorMachineModel);
if (models.isEmpty()) {
String msg = "SVM evaluation failed: " + "No support vector machine model found.";
LOGGER.error(msg);
throw new RuntimeException(msg);
}
PMMLSVMTranslator trans = new PMMLSVMTranslator();
port.initializeModelTranslator(trans);
List<Svm> svms = trans.getSVMs();
m_svms = svms.toArray(new Svm[svms.size()]);
DataTableSpec testSpec = ((BufferedDataTable) inData[1]).getDataTableSpec();
DataTableSpec trainingSpec = ((PMMLPortObject) inData[0]).getSpec().getDataTableSpec();
// try to find all columns (except the class column)
Vector<Integer> colindices = new Vector<Integer>();
for (DataColumnSpec colspec : trainingSpec) {
if (colspec.getType().isCompatible(DoubleValue.class)) {
int colindex = testSpec.findColumnIndex(colspec.getName());
if (colindex < 0) {
throw new InvalidSettingsException("Column " + "\'" + colspec.getName() + "\' not found" + " in test data");
}
colindices.add(colindex);
}
}
m_colindices = new int[colindices.size()];
for (int i = 0; i < m_colindices.length; i++) {
m_colindices[i] = colindices.get(i);
}
SVMPredictor svmpredict = new SVMPredictor(m_svms, m_colindices);
BufferedDataTable testData = (BufferedDataTable) inData[1];
ColumnRearranger colre = new ColumnRearranger(testData.getDataTableSpec());
colre.append(svmpredict);
BufferedDataTable result = exec.createColumnRearrangeTable(testData, colre, exec);
return new BufferedDataTable[] { result };
}
use of org.knime.core.node.port.pmml.PMMLPortObject in project knime-core by knime.
the class TreeEnsembleModelPortObject method createDecisionTreePMMLPortObject.
public PMMLPortObject createDecisionTreePMMLPortObject(final int modelIndex) {
DataTableSpec attributeLearnSpec = m_ensembleModel.getLearnAttributeSpec(m_spec.getLearnTableSpec());
DataColumnSpec targetSpec = m_spec.getTargetColumn();
PMMLPortObjectSpecCreator pmmlSpecCreator = new PMMLPortObjectSpecCreator(new DataTableSpec(attributeLearnSpec, new DataTableSpec(targetSpec)));
try {
pmmlSpecCreator.setLearningCols(attributeLearnSpec);
} catch (InvalidSettingsException e) {
// (as of KNIME v2.5.1)
throw new IllegalStateException(e);
}
pmmlSpecCreator.setTargetCol(targetSpec);
PMMLPortObjectSpec pmmlSpec = pmmlSpecCreator.createSpec();
PMMLPortObject portObject = new PMMLPortObject(pmmlSpec);
TreeModelClassification model = m_ensembleModel.getTreeModelClassification(modelIndex);
portObject.addModelTranslater(new TreeModelPMMLTranslator(model));
return portObject;
}
use of org.knime.core.node.port.pmml.PMMLPortObject in project knime-core by knime.
the class NumberToStringNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
StringBuilder warnings = new StringBuilder();
BufferedDataTable inData = (BufferedDataTable) inObjects[0];
DataTableSpec inSpec = inData.getDataTableSpec();
// find indices to work on.
List<String> inclcols = m_inclCols.getIncludeList();
BufferedDataTable resultTable = null;
if (inclcols.size() == 0) {
// nothing to convert, let's return the input table.
resultTable = inData;
setWarningMessage("No columns selected," + " returning input DataTable.");
} else {
int[] indices = findColumnIndices(inData.getSpec());
ConverterFactory converterFac = new ConverterFactory(indices, inSpec);
ColumnRearranger colre = new ColumnRearranger(inSpec);
colre.replace(converterFac, indices);
resultTable = exec.createColumnRearrangeTable(inData, colre, exec);
String errorMessage = converterFac.getErrorMessage();
if (errorMessage.length() > 0) {
warnings.append("Problems occurred, see Console messages.\n");
}
if (warnings.length() > 0) {
getLogger().warn(errorMessage);
setWarningMessage(warnings.toString());
}
}
// the optional PMML in port (can be null)
PMMLPortObject inPMMLPort = m_pmmlInEnabled ? (PMMLPortObject) inObjects[1] : null;
PMMLStringConversionTranslator trans = new PMMLStringConversionTranslator(m_inclCols.getIncludeList(), StringCell.TYPE, new DerivedFieldMapper(inPMMLPort));
PMMLPortObjectSpecCreator creator = new PMMLPortObjectSpecCreator(inPMMLPort, inSpec);
PMMLPortObject outPMMLPort = new PMMLPortObject(creator.createSpec(), inPMMLPort, inSpec);
outPMMLPort.addGlobalTransformations(trans.exportToTransDict());
return new PortObject[] { resultTable, outPMMLPort };
}
Aggregations