当前位置: 首页>>代码示例>>Java>>正文


Java ClusteringModelUtil类代码示例

本文整理汇总了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);
}
 
开发者ID:jpmml,项目名称:jpmml-sparkml,代码行数:22,代码来源:KMeansModelConverter.java

示例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;
}
 
开发者ID:jpmml,项目名称:jpmml-sklearn,代码行数:37,代码来源:KMeans.java

示例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;
}
 
开发者ID:jpmml,项目名称:jpmml-r,代码行数:35,代码来源:KMeansConverter.java


注:本文中的org.jpmml.converter.clustering.ClusteringModelUtil类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。