本文整理汇总了Java中org.jpmml.converter.clustering.ClusteringModelUtil类的典型用法代码示例。如果您正苦于以下问题:Java ClusteringModelUtil类的具体用法?Java ClusteringModelUtil怎么用?Java ClusteringModelUtil使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ClusteringModelUtil类属于org.jpmml.converter.clustering包,在下文中一共展示了ClusteringModelUtil类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: encodeModel
import org.jpmml.converter.clustering.ClusteringModelUtil; //导入依赖的package包/类
@Override
public ClusteringModel encodeModel(Schema schema){
KMeansModel model = getTransformer();
List<Cluster> clusters = new ArrayList<>();
Vector[] clusterCenters = model.clusterCenters();
for(int i = 0; i < clusterCenters.length; i++){
Cluster cluster = new Cluster()
.setId(String.valueOf(i))
.setArray(PMMLUtil.createRealArray(VectorUtil.toList(clusterCenters[i])));
clusters.add(cluster);
}
ComparisonMeasure comparisonMeasure = new ComparisonMeasure(ComparisonMeasure.Kind.DISTANCE)
.setCompareFunction(CompareFunction.ABS_DIFF)
.setMeasure(new SquaredEuclidean());
return new ClusteringModel(MiningFunction.CLUSTERING, ClusteringModel.ModelClass.CENTER_BASED, clusters.size(), ModelUtil.createMiningSchema(schema.getLabel()), comparisonMeasure, ClusteringModelUtil.createClusteringFields(schema.getFeatures()), clusters);
}
示例2: encodeModel
import org.jpmml.converter.clustering.ClusteringModelUtil; //导入依赖的package包/类
@Override
public ClusteringModel encodeModel(Schema schema){
int[] shape = getClusterCentersShape();
int numberOfClusters = shape[0];
int numberOfFeatures = shape[1];
List<? extends Number> clusterCenters = getClusterCenters();
List<Integer> labels = getLabels();
Multiset<Integer> labelCounts = HashMultiset.create();
if(labels != null){
labelCounts.addAll(labels);
}
List<Cluster> clusters = new ArrayList<>();
for(int i = 0; i < numberOfClusters; i++){
Cluster cluster = new Cluster()
.setId(String.valueOf(i))
.setSize((labelCounts.size () > 0 ? labelCounts.count(i) : null))
.setArray(PMMLUtil.createRealArray(CMatrixUtil.getRow(clusterCenters, numberOfClusters, numberOfFeatures, i)));
clusters.add(cluster);
}
ComparisonMeasure comparisonMeasure = new ComparisonMeasure(ComparisonMeasure.Kind.DISTANCE)
.setCompareFunction(CompareFunction.ABS_DIFF)
.setMeasure(new SquaredEuclidean());
ClusteringModel clusteringModel = new ClusteringModel(MiningFunction.CLUSTERING, ClusteringModel.ModelClass.CENTER_BASED, numberOfClusters, ModelUtil.createMiningSchema(schema.getLabel()), comparisonMeasure, ClusteringModelUtil.createClusteringFields(schema.getFeatures()), clusters)
.setOutput(ClusteringModelUtil.createOutput(FieldName.create("Cluster"), DataType.DOUBLE, clusters));
return clusteringModel;
}
示例3: encodeModel
import org.jpmml.converter.clustering.ClusteringModelUtil; //导入依赖的package包/类
@Override
public Model encodeModel(Schema schema){
RGenericVector kmeans = getObject();
RDoubleVector centers = (RDoubleVector)kmeans.getValue("centers");
RIntegerVector size = (RIntegerVector)kmeans.getValue("size");
RIntegerVector centersDim = centers.dim();
int rows = centersDim.getValue(0);
int columns = centersDim.getValue(1);
List<Cluster> clusters = new ArrayList<>();
RStringVector rowNames = centers.dimnames(0);
for(int i = 0; i < rowNames.size(); i++){
Cluster cluster = new Cluster()
.setId(String.valueOf(i + 1))
.setName(rowNames.getValue(i))
.setSize(size.getValue(i))
.setArray(PMMLUtil.createRealArray(FortranMatrixUtil.getRow(centers.getValues(), rows, columns, i)));
clusters.add(cluster);
}
ComparisonMeasure comparisonMeasure = new ComparisonMeasure(ComparisonMeasure.Kind.DISTANCE)
.setCompareFunction(CompareFunction.ABS_DIFF)
.setMeasure(new SquaredEuclidean());
ClusteringModel clusteringModel = new ClusteringModel(MiningFunction.CLUSTERING, ClusteringModel.ModelClass.CENTER_BASED, rows, ModelUtil.createMiningSchema(schema.getLabel()), comparisonMeasure, ClusteringModelUtil.createClusteringFields(schema.getFeatures()), clusters)
.setOutput(ClusteringModelUtil.createOutput(FieldName.create("cluster"), DataType.DOUBLE, clusters));
return clusteringModel;
}