use of org.knime.core.node.port.pmml.PMMLPortObjectSpec in project knime-core by knime.
the class SVMPredictorNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
DataTableSpec testSpec = (DataTableSpec) inSpecs[1];
PMMLPortObjectSpec trainingSpec = (PMMLPortObjectSpec) inSpecs[0];
// try to find all columns (except the class column)
Vector<Integer> colindices = new Vector<Integer>();
for (DataColumnSpec colspec : trainingSpec.getLearningCols()) {
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);
ColumnRearranger colre = new ColumnRearranger(testSpec);
colre.append(svmpredict);
return new DataTableSpec[] { colre.createSpec() };
}
use of org.knime.core.node.port.pmml.PMMLPortObjectSpec 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.PMMLPortObjectSpec in project knime-core by knime.
the class NumberToStringNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
DataTableSpec dts = (DataTableSpec) inSpecs[0];
// find indices to work on
int[] indices = findColumnIndices(dts);
ConverterFactory converterFac = new ConverterFactory(indices, dts);
ColumnRearranger colre = new ColumnRearranger(dts);
colre.replace(converterFac, indices);
DataTableSpec outDataSpec = colre.createSpec();
// create the PMML spec based on the optional incoming PMML spec
PMMLPortObjectSpec pmmlSpec = m_pmmlInEnabled ? (PMMLPortObjectSpec) inSpecs[1] : null;
PMMLPortObjectSpecCreator pmmlSpecCreator = new PMMLPortObjectSpecCreator(pmmlSpec, dts);
return new PortObjectSpec[] { outDataSpec, pmmlSpecCreator.createSpec() };
}
use of org.knime.core.node.port.pmml.PMMLPortObjectSpec in project knime-core by knime.
the class LinReg2Learner method execute.
/**
* Compute linear regression model.
*
* @param portObjects The input objects.
* @param exec the execution context
* @return a {@link LinearRegressionContent} storing computed data
* @throws Exception if computation of the linear regression model is
* not successful or if given data is inconsistent with the settings
* defined in the constructor.
* @see LinReg2LearnerNodeModel#execute(PortObject[], ExecutionContext)
*/
public LinearRegressionContent execute(final PortObject[] portObjects, final ExecutionContext exec) throws Exception {
BufferedDataTable data = (BufferedDataTable) portObjects[0];
PMMLPortObject inPMMLPort = (PMMLPortObject) portObjects[1];
PMMLPortObjectSpec inPMMLSpec = inPMMLPort.getSpec();
init(data.getDataTableSpec(), inPMMLSpec, Collections.<String>emptySet());
double calcDomainTime = 0.2;
exec.setMessage("Analyzing categorical data");
BufferedDataTable dataTable = recalcDomainOfLearningFields(data, inPMMLSpec, exec.createSubExecutionContext(calcDomainTime));
exec.setMessage("Computing linear regression model");
return m_learner.perform(dataTable, exec.createSubExecutionContext(1.0 - calcDomainTime));
}
use of org.knime.core.node.port.pmml.PMMLPortObjectSpec in project knime-core by knime.
the class PolyRegLearnerNodeModel method createPMMLModel.
private PMMLPortObject createPMMLModel(final PMMLPortObject inPMMLPort, final DataTableSpec inSpec) throws InvalidSettingsException, SAXException {
NumericPredictor[] preds = new NumericPredictor[m_betas.length - 1];
int deg = m_settings.getDegree();
for (int i = 0; i < m_columnNames.length; i++) {
for (int k = 0; k < deg; k++) {
preds[i * deg + k] = new NumericPredictor(m_columnNames[i], k + 1, m_betas[i * deg + k + 1]);
}
}
RegressionTable tab = new RegressionTable(m_betas[0], preds);
PMMLPortObjectSpec pmmlSpec = null;
if (inPMMLPort != null) {
pmmlSpec = inPMMLPort.getSpec();
}
PMMLPortObjectSpec spec = createModelSpec(pmmlSpec, inSpec);
/* To maintain compatibility with the previous SAX-based implementation.
* */
String targetField = "Response";
List<String> targetFields = spec.getTargetFields();
if (!targetFields.isEmpty()) {
targetField = targetFields.get(0);
}
PMMLPortObject outPMMLPort = new PMMLPortObject(spec, inPMMLPort, inSpec);
PMMLRegressionTranslator trans = new PMMLRegressionTranslator("KNIME Polynomial Regression", "PolynomialRegression", tab, targetField);
outPMMLPort.addModelTranslater(trans);
return outPMMLPort;
}
Aggregations