Search in sources :

Example 11 with TransformationDictionary

use of org.dmg.pmml.TransformationDictionaryDocument.TransformationDictionary in project knime-core by knime.

the class PMMLStringConversionTranslator method exportToTransDict.

/**
 * {@inheritDoc}
 */
@Override
public TransformationDictionary exportToTransDict() {
    TransformationDictionary dictionary = TransformationDictionary.Factory.newInstance();
    dictionary.setDerivedFieldArray(createDerivedFields());
    return dictionary;
}
Also used : TransformationDictionary(org.dmg.pmml.TransformationDictionaryDocument.TransformationDictionary)

Example 12 with TransformationDictionary

use of org.dmg.pmml.TransformationDictionaryDocument.TransformationDictionary in project knime-core by knime.

the class PMMLBinningTranslator method exportToTransDict.

/**
 * {@inheritDoc}
 */
@Override
public TransformationDictionary exportToTransDict() {
    TransformationDictionary dictionary = TransformationDictionary.Factory.newInstance();
    dictionary.setDerivedFieldArray(createDerivedFields());
    return dictionary;
}
Also used : TransformationDictionary(org.dmg.pmml.TransformationDictionaryDocument.TransformationDictionary)

Example 13 with TransformationDictionary

use of org.dmg.pmml.TransformationDictionaryDocument.TransformationDictionary in project knime-core by knime.

the class PMMLMany2OneTranslator method exportToTransDict.

/**
 * {@inheritDoc}
 */
@Override
public TransformationDictionary exportToTransDict() {
    final TransformationDictionary dictionary = TransformationDictionary.Factory.newInstance();
    dictionary.setDerivedFieldArray(new DerivedField[] { createDerivedField() });
    return dictionary;
}
Also used : TransformationDictionary(org.dmg.pmml.TransformationDictionaryDocument.TransformationDictionary)

Example 14 with TransformationDictionary

use of org.dmg.pmml.TransformationDictionaryDocument.TransformationDictionary in project knime-core by knime.

the class PMMLMapValuesTranslator method exportToTransDict.

/**
 * {@inheritDoc}
 */
@Override
public TransformationDictionary exportToTransDict() {
    TransformationDictionary dictionary = TransformationDictionary.Factory.newInstance();
    dictionary.setDerivedFieldArray(createDerivedFields());
    return dictionary;
}
Also used : TransformationDictionary(org.dmg.pmml.TransformationDictionaryDocument.TransformationDictionary)

Example 15 with TransformationDictionary

use of org.dmg.pmml.TransformationDictionaryDocument.TransformationDictionary in project knime-core by knime.

the class DBAutoBinner method translate.

/**
 * This method translates a {@link PMMLPreprocDiscretize} object into {@link PMMLPortObject}.
 *
 * @param pmmlDiscretize {@link PMMLPreprocDiscretize} object
 * @param dataTableSpec {@link DataTableSpec} if incoming {@link BufferedDataTable}
 * @return a {@link PMMLPortObject} containing required parameters for binning operation
 */
public static PMMLPortObject translate(final PMMLPreprocDiscretize pmmlDiscretize, final DataTableSpec dataTableSpec) {
    final Map<String, Bin[]> columnToBins = new HashMap<>();
    final Map<String, String> columnToAppend = new HashMap<>();
    List<String> replacedColumnNames = pmmlDiscretize.getConfiguration().getNames();
    for (String replacedColumnName : replacedColumnNames) {
        PMMLDiscretize discretize = pmmlDiscretize.getConfiguration().getDiscretize(replacedColumnName);
        List<PMMLDiscretizeBin> bins = discretize.getBins();
        String originalColumnName = discretize.getField();
        if (replacedColumnName.equals(originalColumnName)) {
            // wenn replaced, dann nicht anhängen
            columnToAppend.put(originalColumnName, null);
        } else {
            // nicht replaced -> anhängen
            columnToAppend.put(originalColumnName, replacedColumnName);
        }
        NumericBin[] numericBin = new NumericBin[bins.size()];
        int counter = 0;
        for (PMMLDiscretizeBin bin : bins) {
            String binName = bin.getBinValue();
            List<PMMLInterval> intervals = bin.getIntervals();
            boolean leftOpen = false;
            boolean rightOpen = false;
            double leftMargin = 0;
            double rightMargin = 0;
            // always returns only one interval
            for (PMMLInterval interval : intervals) {
                Closure closure = interval.getClosure();
                switch(closure) {
                    case openClosed:
                        leftOpen = true;
                        rightOpen = false;
                        break;
                    case openOpen:
                        leftOpen = true;
                        rightOpen = true;
                        break;
                    case closedOpen:
                        leftOpen = false;
                        rightOpen = true;
                    case closedClosed:
                        leftOpen = false;
                        rightOpen = false;
                        break;
                    default:
                        leftOpen = true;
                        rightOpen = false;
                        break;
                }
                leftMargin = interval.getLeftMargin();
                rightMargin = interval.getRightMargin();
            }
            numericBin[counter] = new NumericBin(binName, leftOpen, leftMargin, rightOpen, rightMargin);
            counter++;
        }
        columnToBins.put(originalColumnName, numericBin);
    }
    // ColumnRearranger createColReg = createColReg(dataTableSpec, columnToBins, columnToAppended);
    DataTableSpec newDataTableSpec = createNewDataTableSpec(dataTableSpec, columnToAppend);
    PMMLPortObjectSpecCreator pmmlSpecCreator = new PMMLPortObjectSpecCreator(newDataTableSpec);
    PMMLPortObject pmmlPortObject = new PMMLPortObject(pmmlSpecCreator.createSpec(), null, newDataTableSpec);
    PMMLBinningTranslator trans = new PMMLBinningTranslator(columnToBins, columnToAppend, new DerivedFieldMapper(pmmlPortObject));
    TransformationDictionary exportToTransDict = trans.exportToTransDict();
    pmmlPortObject.addGlobalTransformations(exportToTransDict);
    return pmmlPortObject;
}
Also used : NumericBin(org.knime.base.node.preproc.pmml.binner.NumericBin) DataTableSpec(org.knime.core.data.DataTableSpec) Closure(org.knime.base.node.preproc.autobinner.pmml.PMMLInterval.Closure) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TransformationDictionary(org.dmg.pmml.TransformationDictionaryDocument.TransformationDictionary) PMMLDiscretizeBin(org.knime.base.node.preproc.autobinner.pmml.PMMLDiscretizeBin) PMMLInterval(org.knime.base.node.preproc.autobinner.pmml.PMMLInterval) DerivedFieldMapper(org.knime.core.node.port.pmml.preproc.DerivedFieldMapper) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) PMMLBinningTranslator(org.knime.base.node.preproc.pmml.binner.PMMLBinningTranslator) PMMLDiscretize(org.knime.base.node.preproc.autobinner.pmml.PMMLDiscretize) PMMLPortObjectSpecCreator(org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator)

Aggregations

TransformationDictionary (org.dmg.pmml.TransformationDictionaryDocument.TransformationDictionary)19 DerivedField (org.dmg.pmml.DerivedFieldDocument.DerivedField)4 DerivedFieldMapper (org.knime.core.node.port.pmml.preproc.DerivedFieldMapper)4 LocalTransformations (org.dmg.pmml.LocalTransformationsDocument.LocalTransformations)3 PMML (org.dmg.pmml.PMMLDocument.PMML)3 PMMLPortObject (org.knime.core.node.port.pmml.PMMLPortObject)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 ClusteringModel (org.dmg.pmml.ClusteringModelDocument.ClusteringModel)2 GeneralRegressionModel (org.dmg.pmml.GeneralRegressionModelDocument.GeneralRegressionModel)2 NeuralNetwork (org.dmg.pmml.NeuralNetworkDocument.NeuralNetwork)2 RegressionModel (org.dmg.pmml.RegressionModelDocument.RegressionModel)2 RuleSetModel (org.dmg.pmml.RuleSetModelDocument.RuleSetModel)2 SupportVectorMachineModel (org.dmg.pmml.SupportVectorMachineModelDocument.SupportVectorMachineModel)2 TreeModel (org.dmg.pmml.TreeModelDocument.TreeModel)2 DataTableSpec (org.knime.core.data.DataTableSpec)2 PMMLPortObjectSpecCreator (org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator)2 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1