use of org.knime.core.node.port.pmml.PMMLPortObjectSpec in project knime-core by knime.
the class FuzzyClusterNodeModel method configure.
/**
* Number of columns in the output table is not deterministic.
*
* {@inheritDoc}
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
DataTableSpec inspec = (DataTableSpec) inSpecs[0];
if (m_keepAll || m_list == null) {
m_list = new ArrayList<String>();
for (DataColumnSpec colspec : inspec) {
if (colspec.getType().isCompatible(DoubleValue.class)) {
m_list.add(colspec.getName());
}
}
if (!m_keepAll) {
setWarningMessage("List of columns to use has been set" + " automatically, please check it in the dialog.");
}
}
HashSet<String> listAsHash = new HashSet<String>(m_list);
List<String> learningCols = new LinkedList<String>();
for (int i = 0; i < inspec.getNumColumns(); i++) {
String colname = inspec.getColumnSpec(i).getName();
// if column is selected attribute
if (listAsHash.remove(colname)) {
learningCols.add(colname);
}
}
if (!listAsHash.isEmpty()) {
throw new InvalidSettingsException("Input table does not match " + "selected columns, unable to find column(s): " + listAsHash);
}
// number of clusters + winner cluster
int nrCols = m_nrClusters + 1;
if (m_noise) {
// one column for the noise cluster
nrCols++;
}
DataColumnSpec[] newSpec = new DataColumnSpec[nrCols];
int cluster = 0;
for (int j = 0; j < nrCols - 1; j++) {
if (m_noise && j == (nrCols - 2)) {
newSpec[j] = new DataColumnSpecCreator(FuzzyClusterNodeModel.NOISESPEC_KEY, DoubleCell.TYPE).createSpec();
break;
}
newSpec[j] = new DataColumnSpecCreator(FuzzyClusterNodeModel.CLUSTER_KEY + cluster, DoubleCell.TYPE).createSpec();
cluster++;
}
newSpec[newSpec.length - 1] = new DataColumnSpecCreator("Winner Cluster", StringCell.TYPE).createSpec();
DataTableSpec newspec = new DataTableSpec(newSpec);
DataTableSpec returnspec = new DataTableSpec(inspec, newspec);
PMMLPortObjectSpec inPmmlSpec = m_enablePMMLInput ? (PMMLPortObjectSpec) inSpecs[1] : null;
return new PortObjectSpec[] { returnspec, createPMMLPortObjectSpec(inPmmlSpec, inspec, learningCols) };
}
use of org.knime.core.node.port.pmml.PMMLPortObjectSpec in project knime-core by knime.
the class DecTreeToImageNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected final PortObjectSpec[] configure(final PortObjectSpec[] inPOSpecs) throws InvalidSettingsException {
// test if number of pixels will exceed Integer.MAX_VALUE
double imgSize = m_settings.getWidth() * (double) m_settings.getHeight();
if (imgSize > Integer.MAX_VALUE) {
throw new InvalidSettingsException("The maximum image size (width * heigth) of " + NumberFormat.getIntegerInstance().format(Integer.MAX_VALUE) + " pixel is exceeded.");
}
if (inPOSpecs[1] != null) {
PMMLPortObjectSpec treeSpec = (PMMLPortObjectSpec) inPOSpecs[0];
DataTableSpec inSpec = (DataTableSpec) inPOSpecs[1];
for (String learnColName : treeSpec.getLearningFields()) {
if (!inSpec.containsName(learnColName)) {
throw new InvalidSettingsException("Learning column \"" + learnColName + "\" not found in the data input (color information).");
}
}
}
return new PortObjectSpec[] { new ImagePortObjectSpec(PNGImageContent.TYPE) };
}
use of org.knime.core.node.port.pmml.PMMLPortObjectSpec in project knime-core by knime.
the class DecTreePredictorNodeModel method createOutTableSpec.
private DataTableSpec createOutTableSpec(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
List<DataCell> predValues = null;
if (m_showDistribution.getBooleanValue()) {
predValues = getPredictionValues((PMMLPortObjectSpec) inSpecs[INMODELPORT]);
if (predValues == null) {
// no out spec can be determined
return null;
}
}
int numCols = (predValues == null ? 0 : predValues.size()) + 1;
DataTableSpec inSpec = (DataTableSpec) inSpecs[INDATAPORT];
DataColumnSpec[] newCols = new DataColumnSpec[numCols];
/* Set bar renderer and domain [0,1] as default for the double cells
* containing the distribution */
// DataColumnProperties propsRendering = new DataColumnProperties(
// Collections.singletonMap(
// DataValueRenderer.PROPERTY_PREFERRED_RENDERER,
// DoubleBarRenderer.DESCRIPTION));
DataColumnDomain domain = new DataColumnDomainCreator(new DoubleCell(0.0), new DoubleCell(1.0)).createDomain();
PredictorHelper predictorHelper = PredictorHelper.getInstance();
String trainingColumnName = ((PMMLPortObjectSpec) inSpecs[INMODELPORT]).getTargetFields().iterator().next();
// add all distribution columns
for (int i = 0; i < numCols - 1; i++) {
assert predValues != null;
DataColumnSpecCreator colSpecCreator = new DataColumnSpecCreator(predictorHelper.probabilityColumnName(trainingColumnName, predValues.get(i).toString(), m_probabilitySuffix.getStringValue()), DoubleCell.TYPE);
// colSpecCreator.setProperties(propsRendering);
colSpecCreator.setDomain(domain);
newCols[i] = colSpecCreator.createSpec();
}
// add the prediction column
String predictionColumnName = predictorHelper.computePredictionColumnName(m_predictionColumn.getStringValue(), m_overridePrediction.getBooleanValue(), trainingColumnName);
newCols[numCols - 1] = new DataColumnSpecCreator(predictionColumnName, StringCell.TYPE).createSpec();
DataTableSpec newColSpec = new DataTableSpec(newCols);
return new DataTableSpec(inSpec, newColSpec);
}
use of org.knime.core.node.port.pmml.PMMLPortObjectSpec in project knime-core by knime.
the class PMMLReaderNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
// read the data dictionary and the mining schema and create a
// PMMLPortObjectSpec
String fileS = m_file.getStringValue();
String warning = CheckUtils.checkSourceFile(fileS);
if (warning != null) {
setWarningMessage(warning);
}
URL url = getURLFromSettings(fileS);
try {
PMMLImport pmmlImport = new PMMLImport(url, false);
m_pmmlPort = pmmlImport.getPortObject();
} catch (IllegalArgumentException e) {
String msg = "File \"" + url + "\" is not a valid PMML file:\n" + e.getMessage();
setWarningMessage(msg);
throw new InvalidSettingsException(msg);
} catch (XmlException e) {
throw new InvalidSettingsException(e);
} catch (IOException e) {
throw new InvalidSettingsException(e);
}
PMMLPortObjectSpec parsedSpec = m_pmmlPort.getSpec();
PMMLPortObjectSpec outSpec = createPMMLOutSpec(m_hasPMMLIn ? (PMMLPortObjectSpec) inSpecs[0] : null, parsedSpec);
return new PortObjectSpec[] { outSpec };
}
use of org.knime.core.node.port.pmml.PMMLPortObjectSpec in project knime-core by knime.
the class NaiveBayesLearnerNodeModel2 method createPMMLSpec.
private PMMLPortObjectSpec createPMMLSpec(final DataTableSpec tableSpec, final PMMLPortObjectSpec modelSpec, final List<String> learnCols, final String classColumn) {
final PMMLPortObjectSpecCreator pmmlSpecCreator = new PMMLPortObjectSpecCreator(modelSpec, tableSpec);
pmmlSpecCreator.setLearningColsNames(learnCols);
pmmlSpecCreator.setTargetColName(classColumn);
final PMMLPortObjectSpec pmmlSpec = pmmlSpecCreator.createSpec();
return pmmlSpec;
}
Aggregations