use of org.knime.base.node.mine.regression.PMMLRegressionTranslator 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;
}
use of org.knime.base.node.mine.regression.PMMLRegressionTranslator 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 regModel = (PMMLPortObject) inData[0];
List<Node> models = regModel.getPMMLValue().getModels(PMMLModelType.RegressionModel);
if (models.isEmpty()) {
String msg = "No Regression Model found.";
LOGGER.error(msg);
throw new RuntimeException(msg);
}
PMMLRegressionTranslator trans = new PMMLRegressionTranslator();
regModel.initializeModelTranslator(trans);
BufferedDataTable data = (BufferedDataTable) inData[1];
DataTableSpec spec = data.getDataTableSpec();
ColumnRearranger c = createRearranger(spec, regModel.getSpec(), trans);
BufferedDataTable out = exec.createColumnRearrangeTable(data, c, exec);
return new BufferedDataTable[] { out };
}
use of org.knime.base.node.mine.regression.PMMLRegressionTranslator 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;
}
use of org.knime.base.node.mine.regression.PMMLRegressionTranslator in project knime-core by knime.
the class LinearRegressionContent method createPortObject.
/**
* Creates a new PMML regression port object from this linear regression
* model.
* @param inPMMLPort the incoming PMMLPort object (can be null)
* @param dts the full data table spec with which the regression
* model was created.
* @param learningSpec a data table spec containing only learning columns
* @return a port object
* @throws InvalidSettingsException if the settings are invalid
*/
public PMMLPortObject createPortObject(final PMMLPortObject inPMMLPort, final DataTableSpec dts, final DataTableSpec learningSpec) throws InvalidSettingsException {
PMMLPortObjectSpec inPMMLSpec = null;
if (inPMMLPort != null) {
inPMMLSpec = inPMMLPort.getSpec();
}
PMMLPortObjectSpec spec = createPortObjectSpec(inPMMLSpec, dts, learningSpec);
PMMLPortObject outPMMLPort = new PMMLPortObject(spec, inPMMLPort);
NumericPredictor[] nps = new NumericPredictor[m_multipliers.length];
for (int i = 0; i < nps.length; i++) {
nps[i] = new NumericPredictor(m_spec.getColumnSpec(i).getName(), 1, m_multipliers[i]);
}
RegressionTable regressionTable = new RegressionTable(m_offset, nps);
/* To maintain compatibility with the previous SAX-based implementation.
* */
String targetField = "Response";
List<String> targetFields = spec.getTargetFields();
if (!targetFields.isEmpty()) {
targetField = targetFields.get(0);
}
PMMLRegressionTranslator trans = new PMMLRegressionTranslator(MODEL_NAME, ALGORITHM_NAME, regressionTable, targetField);
outPMMLPort.addModelTranslater(trans);
return outPMMLPort;
}
Aggregations