本文整理匯總了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;
}