Search in sources :

Example 1 with ComparisonMeasure

use of org.knime.base.node.mine.cluster.PMMLClusterTranslator.ComparisonMeasure in project knime-core by knime.

the class ClusterAssignerNodeModel method createColumnRearranger.

private ColumnRearranger createColumnRearranger(final PMMLPortObject port, final DataTableSpec inSpec) throws InvalidSettingsException {
    List<Node> models = port.getPMMLValue().getModels(PMMLModelType.ClusteringModel);
    if (models.isEmpty()) {
        String msg = "No Clustering Model found.";
        LOGGER.error(msg);
        throw new RuntimeException(msg);
    }
    PMMLClusterTranslator trans = new PMMLClusterTranslator();
    port.initializeModelTranslator(trans);
    ComparisonMeasure measure = trans.getComparisonMeasure();
    List<Prototype> prototypes = new ArrayList<Prototype>();
    String[] labels = trans.getLabels();
    double[][] protos = trans.getPrototypes();
    for (int i = 0; i < protos.length; i++) {
        double[] prototype = protos[i];
        prototypes.add(new Prototype(prototype, new StringCell(labels[i])));
    }
    ColumnRearranger colre = new ColumnRearranger(inSpec);
    colre.append(new ClusterAssignFactory(measure, prototypes, createNewOutSpec(inSpec), findLearnedColumnIndices(inSpec, trans.getUsedColumns())));
    return colre;
}
Also used : Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) PMMLClusterTranslator(org.knime.base.node.mine.cluster.PMMLClusterTranslator) StringCell(org.knime.core.data.def.StringCell) ComparisonMeasure(org.knime.base.node.mine.cluster.PMMLClusterTranslator.ComparisonMeasure)

Aggregations

ArrayList (java.util.ArrayList)1 PMMLClusterTranslator (org.knime.base.node.mine.cluster.PMMLClusterTranslator)1 ComparisonMeasure (org.knime.base.node.mine.cluster.PMMLClusterTranslator.ComparisonMeasure)1 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)1 StringCell (org.knime.core.data.def.StringCell)1 Node (org.w3c.dom.Node)1