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;
}
Aggregations