本文整理汇总了Java中org.dmg.pmml.clustering.Cluster类的典型用法代码示例。如果您正苦于以下问题:Java Cluster类的具体用法?Java Cluster怎么用?Java Cluster使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Cluster类属于org.dmg.pmml.clustering包,在下文中一共展示了Cluster类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: encodeModel
import org.dmg.pmml.clustering.Cluster; //导入依赖的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: pmmlClusteringModel
import org.dmg.pmml.clustering.Cluster; //导入依赖的package包/类
private ClusteringModel pmmlClusteringModel(KMeansModel model,
Map<Integer,Long> clusterSizesMap) {
Vector[] clusterCenters = model.clusterCenters();
List<ClusteringField> clusteringFields = new ArrayList<>();
for (int i = 0; i < inputSchema.getNumFeatures(); i++) {
if (inputSchema.isActive(i)) {
FieldName fieldName = FieldName.create(inputSchema.getFeatureNames().get(i));
ClusteringField clusteringField =
new ClusteringField(fieldName).setCenterField(ClusteringField.CenterField.TRUE);
clusteringFields.add(clusteringField);
}
}
List<Cluster> clusters = new ArrayList<>(clusterCenters.length);
for (int i = 0; i < clusterCenters.length; i++) {
clusters.add(new Cluster().setId(Integer.toString(i))
.setSize(clusterSizesMap.get(i).intValue())
.setArray(AppPMMLUtils.toArray(clusterCenters[i].toArray())));
}
return new ClusteringModel(
MiningFunction.CLUSTERING,
ClusteringModel.ModelClass.CENTER_BASED,
clusters.size(),
AppPMMLUtils.buildMiningSchema(inputSchema),
new ComparisonMeasure(ComparisonMeasure.Kind.DISTANCE).setMeasure(new SquaredEuclidean()),
clusteringFields,
clusters);
}
开发者ID:oncewang,项目名称:oryx2,代码行数:31,代码来源:KMeansUpdate.java
示例3: createOutput
import org.dmg.pmml.clustering.Cluster; //导入依赖的package包/类
static
public Output createOutput(FieldName name, DataType dataType, List<Cluster> clusters){
List<OutputField> outputFields = new ArrayList<>();
outputFields.add(ModelUtil.createPredictedField(name, DataType.STRING, OpType.CATEGORICAL));
outputFields.addAll(ModelUtil.createAffinityFields(dataType, clusters));
Output output = new Output(outputFields);
return output;
}
开发者ID:jpmml,项目名称:jpmml-converter,代码行数:11,代码来源:ClusteringModelUtil.java
示例4: encodeModel
import org.dmg.pmml.clustering.Cluster; //导入依赖的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
示例5: encodeModel
import org.dmg.pmml.clustering.Cluster; //导入依赖的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
示例6: getEntityRegistry
import org.dmg.pmml.clustering.Cluster; //导入依赖的package包/类
@Override
public BiMap<String, Cluster> getEntityRegistry(){
if(this.entityRegistry == null){
this.entityRegistry = getValue(ClusteringModelEvaluator.entityCache);
}
return this.entityRegistry;
}
开发者ID:jpmml,项目名称:jpmml-evaluator,代码行数:10,代码来源:ClusteringModelEvaluator.java
示例7: evaluateDistance
import org.dmg.pmml.clustering.Cluster; //导入依赖的package包/类
private <V extends Number> ClusterAffinityDistribution<V> evaluateDistance(ValueFactory<V> valueFactory, ComparisonMeasure comparisonMeasure, List<ClusteringField> clusteringFields, List<FieldValue> values){
ClusteringModel clusteringModel = getModel();
List<Cluster> clusters = clusteringModel.getClusters();
Value<V> adjustment;
MissingValueWeights missingValueWeights = clusteringModel.getMissingValueWeights();
if(missingValueWeights != null){
Array array = missingValueWeights.getArray();
List<? extends Number> adjustmentValues = ArrayUtil.asNumberList(array);
if(values.size() != adjustmentValues.size()){
throw new InvalidElementException(missingValueWeights);
}
adjustment = MeasureUtil.calculateAdjustment(valueFactory, values, adjustmentValues);
} else
{
adjustment = MeasureUtil.calculateAdjustment(valueFactory, values);
}
ClusterAffinityDistribution<V> result = createClusterAffinityDistribution(Classification.Type.DISTANCE, clusters);
for(Cluster cluster : clusters){
List<FieldValue> clusterValues = CacheUtil.getValue(cluster, ClusteringModelEvaluator.clusterValueCache);
if(values.size() != clusterValues.size()){
throw new InvalidElementException(cluster);
}
Value<V> distance = MeasureUtil.evaluateDistance(valueFactory, comparisonMeasure, clusteringFields, values, clusterValues, adjustment);
result.put(cluster, distance);
}
return result;
}
开发者ID:jpmml,项目名称:jpmml-evaluator,代码行数:40,代码来源:ClusteringModelEvaluator.java
示例8: createClusterAffinityDistribution
import org.dmg.pmml.clustering.Cluster; //导入依赖的package包/类
private <V extends Number> ClusterAffinityDistribution<V> createClusterAffinityDistribution(Classification.Type type, List<Cluster> clusters){
ClusterAffinityDistribution<V> result = new ClusterAffinityDistribution<V>(type, new ValueMap<String, V>(2 * clusters.size())){
@Override
public BiMap<String, Cluster> getEntityRegistry(){
return ClusteringModelEvaluator.this.getEntityRegistry();
}
};
return result;
}
开发者ID:jpmml,项目名称:jpmml-evaluator,代码行数:12,代码来源:ClusteringModelEvaluator.java
示例9: load
import org.dmg.pmml.clustering.Cluster; //导入依赖的package包/类
@Override
public List<FieldValue> load(Cluster cluster){
Array array = cluster.getArray();
List<? extends Number> values = ArrayUtil.asNumberList(array);
return ImmutableList.copyOf(FieldValueUtil.createAll(null, OpType.CONTINUOUS, values));
}
开发者ID:jpmml,项目名称:jpmml-evaluator,代码行数:9,代码来源:ClusteringModelEvaluator.java
示例10: buildDummyClusteringModel
import org.dmg.pmml.clustering.Cluster; //导入依赖的package包/类
public static PMML buildDummyClusteringModel() {
PMML pmml = PMMLUtils.buildSkeletonPMML();
List<DataField> dataFields = new ArrayList<>();
dataFields.add(new DataField(FieldName.create("x"), OpType.CONTINUOUS, DataType.DOUBLE));
dataFields.add(new DataField(FieldName.create("y"), OpType.CONTINUOUS, DataType.DOUBLE));
DataDictionary dataDictionary =
new DataDictionary(dataFields).setNumberOfFields(dataFields.size());
pmml.setDataDictionary(dataDictionary);
List<MiningField> miningFields = new ArrayList<>();
MiningField xMF = new MiningField(FieldName.create("x"))
.setOpType(OpType.CONTINUOUS).setUsageType(MiningField.UsageType.ACTIVE);
miningFields.add(xMF);
MiningField yMF = new MiningField(FieldName.create("y"))
.setOpType(OpType.CONTINUOUS).setUsageType(MiningField.UsageType.ACTIVE);
miningFields.add(yMF);
MiningSchema miningSchema = new MiningSchema(miningFields);
List<ClusteringField> clusteringFields = new ArrayList<>();
clusteringFields.add(new ClusteringField(
FieldName.create("x")).setCenterField(ClusteringField.CenterField.TRUE));
clusteringFields.add(new ClusteringField(
FieldName.create("y")).setCenterField(ClusteringField.CenterField.TRUE));
List<Cluster> clusters = new ArrayList<>();
clusters.add(new Cluster().setId("0").setSize(1).setArray(AppPMMLUtils.toArray(1.0, 0.0)));
clusters.add(new Cluster().setId("1").setSize(2).setArray(AppPMMLUtils.toArray(2.0, -1.0)));
clusters.add(new Cluster().setId("2").setSize(3).setArray(AppPMMLUtils.toArray(-1.0, 0.0)));
pmml.addModels(new ClusteringModel(
MiningFunction.CLUSTERING,
ClusteringModel.ModelClass.CENTER_BASED,
clusters.size(),
miningSchema,
new ComparisonMeasure(ComparisonMeasure.Kind.DISTANCE).setMeasure(new SquaredEuclidean()),
clusteringFields,
clusters));
return pmml;
}
开发者ID:oncewang,项目名称:oryx2,代码行数:42,代码来源:KMeansPMMLUtilsTest.java
示例11: testKMeans
import org.dmg.pmml.clustering.Cluster; //导入依赖的package包/类
@Test
public void testKMeans() throws Exception {
Path tempDir = getTempDir();
Path dataDir = tempDir.resolve("data");
Path modelDir = tempDir.resolve("model");
Map<String,Object> overlayConfig = new HashMap<>();
overlayConfig.put("oryx.batch.update-class", KMeansUpdate.class.getName());
ConfigUtils.set(overlayConfig, "oryx.batch.storage.data-dir", dataDir);
ConfigUtils.set(overlayConfig, "oryx.batch.storage.model-dir", modelDir);
overlayConfig.put("oryx.batch.streaming.generation-interval-sec", GEN_INTERVAL_SEC);
overlayConfig.put("oryx.kmeans.hyperparams.k", NUM_CLUSTERS);
overlayConfig.put("oryx.kmeans.iterations", 5);
overlayConfig.put("oryx.input-schema.num-features", NUM_FEATURES);
overlayConfig.put("oryx.input-schema.categorical-features", "[]");
overlayConfig.put("oryx.kmeans.evaluation-strategy", EVALUATION_STRATEGY);
Config config = ConfigUtils.overlayOn(overlayConfig, getConfig());
startMessaging();
List<KeyMessage<String, String>> updates = startServerProduceConsumeTopics(
config,
new RandomKMeansDataGenerator(NUM_FEATURES),
DATA_TO_WRITE,
WRITE_INTERVAL_MSEC);
List<Path> modelInstanceDirs = IOUtils.listFiles(modelDir, "*");
int generations = modelInstanceDirs.size();
checkIntervals(generations, DATA_TO_WRITE, WRITE_INTERVAL_MSEC, GEN_INTERVAL_SEC);
for (Path modelInstanceDir : modelInstanceDirs) {
Path modelFile = modelInstanceDir.resolve(MLUpdate.MODEL_FILE_NAME);
assertNonEmpty(modelFile);
PMMLUtils.read(modelFile); // Shouldn't throw exception
}
InputSchema schema = new InputSchema(config);
for (KeyMessage<String,String> km : updates) {
String type = km.getKey();
String value = km.getMessage();
assertContains(Arrays.asList("MODEL", "MODEL-REF"), type);
PMML pmml = AppPMMLUtils.readPMMLFromUpdateKeyMessage(type, value, null);
checkHeader(pmml.getHeader());
checkDataDictionary(schema, pmml.getDataDictionary());
Model rootModel = pmml.getModels().get(0);
ClusteringModel clusteringModel = (ClusteringModel) rootModel;
// Check if Basic hyperparameters match
assertEquals(NUM_CLUSTERS, clusteringModel.getNumberOfClusters());
assertEquals(NUM_CLUSTERS, clusteringModel.getClusters().size());
assertEquals(NUM_FEATURES, clusteringModel.getClusteringFields().size());
assertEquals(ComparisonMeasure.Kind.DISTANCE,
clusteringModel.getComparisonMeasure().getKind());
assertEquals(NUM_FEATURES, clusteringModel.getClusters().get(0).getArray().getN().intValue());
for (Cluster cluster : clusteringModel.getClusters()) {
assertGreater(cluster.getSize(), 0);
}
}
}
开发者ID:oncewang,项目名称:oryx2,代码行数:69,代码来源:KMeansUpdateIT.java
示例12: getDisplayValue
import org.dmg.pmml.clustering.Cluster; //导入依赖的package包/类
@Override
public String getDisplayValue(){
Cluster cluster = getEntity();
return cluster.getName();
}
开发者ID:jpmml,项目名称:jpmml-evaluator,代码行数:7,代码来源:ClusterAffinityDistribution.java
示例13: evaluateSimilarity
import org.dmg.pmml.clustering.Cluster; //导入依赖的package包/类
private <V extends Number> ClusterAffinityDistribution<V> evaluateSimilarity(ValueFactory<V> valueFactory, ComparisonMeasure comparisonMeasure, List<ClusteringField> clusteringFields, List<FieldValue> values){
ClusteringModel clusteringModel = getModel();
List<Cluster> clusters = clusteringModel.getClusters();
ClusterAffinityDistribution<V> result = createClusterAffinityDistribution(Classification.Type.SIMILARITY, clusters);
BitSet flags = MeasureUtil.toBitSet(values);
for(Cluster cluster : clusters){
BitSet clusterFlags = CacheUtil.getValue(cluster, ClusteringModelEvaluator.clusterFlagCache);
if(flags.size() != clusterFlags.size()){
throw new InvalidElementException(cluster);
}
Value<V> similarity = MeasureUtil.evaluateSimilarity(valueFactory, comparisonMeasure, clusteringFields, flags, clusterFlags);
result.put(cluster, similarity);
}
return result;
}
开发者ID:jpmml,项目名称:jpmml-evaluator,代码行数:24,代码来源:ClusteringModelEvaluator.java
注:本文中的org.dmg.pmml.clustering.Cluster类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论