use of org.dmg.pmml.RegressionModelDocument.RegressionModel in project knime-core by knime.
the class PMMLRegressionTranslator method exportTo.
/**
* {@inheritDoc}
*/
@Override
public SchemaType exportTo(final PMMLDocument pmmlDoc, final PMMLPortObjectSpec spec) {
m_nameMapper = new DerivedFieldMapper(pmmlDoc);
RegressionModel regressionModel = pmmlDoc.getPMML().addNewRegressionModel();
regressionModel.setFunctionName(MININGFUNCTION.REGRESSION);
if (m_algorithmName != null && !m_algorithmName.isEmpty()) {
regressionModel.setAlgorithmName(m_algorithmName);
}
regressionModel.setModelName(m_modelName);
regressionModel.setTargetFieldName(m_targetField);
PMMLMiningSchemaTranslator.writeMiningSchema(spec, regressionModel);
RegressionTableDocument.RegressionTable regressionTable = regressionModel.addNewRegressionTable();
regressionTable.setIntercept(m_regressionTable.getIntercept());
for (NumericPredictor p : m_regressionTable.getVariables()) {
NumericPredictorDocument.NumericPredictor np = regressionTable.addNewNumericPredictor();
np.setName(m_nameMapper.getDerivedFieldName(p.getName()));
if (p.getExponent() != 1) {
np.setExponent(BigInteger.valueOf(p.getExponent()));
}
np.setCoefficient(p.getCoefficient());
}
return RegressionModel.type;
}
use of org.dmg.pmml.RegressionModelDocument.RegressionModel in project knime-core by knime.
the class PMMLModelWrapper method getSegmentContent.
/**
* Returns the content of a segment as a model wrapper.
* @param s The segment
* @return Returns a wrapper around the model
*/
public static PMMLModelWrapper getSegmentContent(final Segment s) {
TreeModel treemodel = s.getTreeModel();
if (treemodel != null) {
return new PMMLTreeModelWrapper(treemodel);
}
RegressionModel regrmodel = s.getRegressionModel();
if (regrmodel != null) {
return new PMMLRegressionModelWrapper(regrmodel);
}
GeneralRegressionModel genregrmodel = s.getGeneralRegressionModel();
if (genregrmodel != null) {
return new PMMLGeneralRegressionModelWrapper(genregrmodel);
}
ClusteringModel clustmodel = s.getClusteringModel();
if (clustmodel != null) {
return new PMMLClusteringModelWrapper(clustmodel);
}
NaiveBayesModel nbmodel = s.getNaiveBayesModel();
if (nbmodel != null) {
return new PMMLNaiveBayesModelWrapper(nbmodel);
}
NeuralNetwork nn = s.getNeuralNetwork();
if (nn != null) {
return new PMMLNeuralNetworkWrapper(nn);
}
RuleSetModel rsmodel = s.getRuleSetModel();
if (rsmodel != null) {
return new PMMLRuleSetModelWrapper(rsmodel);
}
SupportVectorMachineModel svmmodel = s.getSupportVectorMachineModel();
if (svmmodel != null) {
return new PMMLSupportVectorMachineModelWrapper(svmmodel);
}
return null;
}
use of org.dmg.pmml.RegressionModelDocument.RegressionModel in project knime-core by knime.
the class PMMLPortObject method moveGlobalTransformationsToModel.
/**
* Moves the content of the transformation dictionary to local
* transformations of the model if a model exists.
*/
public void moveGlobalTransformationsToModel() {
PMML pmml = m_pmmlDoc.getPMML();
TransformationDictionary transDict = pmml.getTransformationDictionary();
if (transDict == null || transDict.getDerivedFieldArray() == null || transDict.getDerivedFieldArray().length == 0) {
// nothing to be moved
return;
}
DerivedField[] globalDerivedFields = transDict.getDerivedFieldArray();
LocalTransformations localTrans = null;
if (pmml.getTreeModelArray().length > 0) {
TreeModel model = pmml.getTreeModelArray(0);
localTrans = model.getLocalTransformations();
if (localTrans == null) {
localTrans = model.addNewLocalTransformations();
}
} else if (pmml.getClusteringModelArray().length > 0) {
ClusteringModel model = pmml.getClusteringModelArray(0);
localTrans = model.getLocalTransformations();
if (localTrans == null) {
localTrans = model.addNewLocalTransformations();
}
} else if (pmml.getNeuralNetworkArray().length > 0) {
NeuralNetwork model = pmml.getNeuralNetworkArray(0);
localTrans = model.getLocalTransformations();
if (localTrans == null) {
localTrans = model.addNewLocalTransformations();
}
} else if (pmml.getSupportVectorMachineModelArray().length > 0) {
SupportVectorMachineModel model = pmml.getSupportVectorMachineModelArray(0);
localTrans = model.getLocalTransformations();
if (localTrans == null) {
localTrans = model.addNewLocalTransformations();
}
} else if (pmml.getRegressionModelArray().length > 0) {
RegressionModel model = pmml.getRegressionModelArray(0);
localTrans = model.getLocalTransformations();
if (localTrans == null) {
localTrans = model.addNewLocalTransformations();
}
} else if (pmml.getGeneralRegressionModelArray().length > 0) {
GeneralRegressionModel model = pmml.getGeneralRegressionModelArray(0);
localTrans = model.getLocalTransformations();
if (localTrans == null) {
localTrans = model.addNewLocalTransformations();
}
} else if (pmml.sizeOfRuleSetModelArray() > 0) {
RuleSetModel model = pmml.getRuleSetModelArray(0);
localTrans = model.getLocalTransformations();
if (localTrans == null) {
localTrans = model.addNewLocalTransformations();
}
}
if (localTrans != null) {
DerivedField[] derivedFields = appendDerivedFields(localTrans.getDerivedFieldArray(), globalDerivedFields);
localTrans.setDerivedFieldArray(derivedFields);
// remove derived fields from TransformationDictionary
transDict.setDerivedFieldArray(new DerivedField[0]);
}
// else do nothing as no model exists yet
}
use of org.dmg.pmml.RegressionModelDocument.RegressionModel in project knime-core by knime.
the class ClassificationGBTModelExporter method addSoftmaxRegression.
private void addSoftmaxRegression(final Segment segment) {
RegressionModel reg = segment.addNewRegressionModel();
reg.setFunctionName(MININGFUNCTION.CLASSIFICATION);
reg.setNormalizationMethod(REGRESSIONNORMALIZATIONMETHOD.SOFTMAX);
addAggregationMiningScheme(reg);
addRegressionOutputs(reg);
addRegressionTables(reg);
}
use of org.dmg.pmml.RegressionModelDocument.RegressionModel in project knime-core by knime.
the class PMMLRegressionTranslator method initializeFrom.
/**
* {@inheritDoc}
*/
@Override
public void initializeFrom(final PMMLDocument pmmlDoc) {
m_nameMapper = new DerivedFieldMapper(pmmlDoc);
RegressionModel[] models = pmmlDoc.getPMML().getRegressionModelArray();
if (models.length == 0) {
throw new IllegalArgumentException("No regression model" + " provided.");
} else if (models.length > 1) {
LOGGER.warn("Multiple regression models found. " + "Only the first model is considered.");
}
RegressionModel regressionModel = models[0];
if (MININGFUNCTION.REGRESSION != regressionModel.getFunctionName()) {
LOGGER.error("Only regression is supported by KNIME.");
}
m_algorithmName = regressionModel.getAlgorithmName();
m_modelName = regressionModel.getModelName();
RegressionTableDocument.RegressionTable regressionTable = regressionModel.getRegressionTableArray(0);
List<NumericPredictor> knimePredictors = new ArrayList<NumericPredictor>();
for (NumericPredictorDocument.NumericPredictor pmmlPredictor : regressionTable.getNumericPredictorArray()) {
NumericPredictor knp = new NumericPredictor(m_nameMapper.getColumnName(pmmlPredictor.getName()), pmmlPredictor.getExponent().intValue(), pmmlPredictor.getCoefficient());
knimePredictors.add(knp);
}
m_regressionTable = new RegressionTable(regressionTable.getIntercept(), knimePredictors.toArray(new NumericPredictor[0]));
}
Aggregations