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


Java ComparisonMeasure类代码示例

本文整理汇总了Java中org.dmg.pmml.ComparisonMeasure的典型用法代码示例。如果您正苦于以下问题:Java ComparisonMeasure类的具体用法?Java ComparisonMeasure怎么用?Java ComparisonMeasure使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ComparisonMeasure类属于org.dmg.pmml包,在下文中一共展示了ComparisonMeasure类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: encodeModel

import org.dmg.pmml.ComparisonMeasure; //导入依赖的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: createAffinityDistribution

import org.dmg.pmml.ComparisonMeasure; //导入依赖的package包/类
private <V extends Number> AffinityDistribution<V> createAffinityDistribution(List<InstanceResult<V>> instanceResults, Function<Integer, String> function, Object result){
	NearestNeighborModel nearestNeighborModel = getModel();

	ComparisonMeasure comparisonMeasure = nearestNeighborModel.getComparisonMeasure();

	ValueMap<String, V> values = new ValueMap<>(2 * instanceResults.size());

	for(InstanceResult<V> instanceResult : instanceResults){
		values.put(function.apply(instanceResult.getId()), instanceResult.getValue());
	}

	Measure measure = MeasureUtil.ensureMeasure(comparisonMeasure);

	if(measure instanceof Similarity){
		return new AffinityDistribution<>(Classification.Type.SIMILARITY, values, result);
	} else

	if(measure instanceof Distance){
		return new AffinityDistribution<>(Classification.Type.DISTANCE, values, result);
	} else

	{
		throw new UnsupportedElementException(measure);
	}
}
 
开发者ID:jpmml,项目名称:jpmml-evaluator,代码行数:26,代码来源:NearestNeighborModelEvaluator.java

示例3: build

import org.dmg.pmml.ComparisonMeasure; //导入依赖的package包/类
public ClusteringModel build(String modelName, Centers centers) {
  ClusteringModel model = new ClusteringModel(
      miningSchema,
      new ComparisonMeasure(ComparisonMeasure.Kind.DISTANCE).withMeasure(new SquaredEuclidean()),
      MiningFunctionType.CLUSTERING,
      ClusteringModel.ModelClass.CENTER_BASED,
      centers.size());
  model.setModelName(modelName);
  model.setAlgorithmName("K-Means||");
  model.setLocalTransformations(transforms);
  model.getClusteringFields().addAll(clusteringFields);
  for (int i = 0; i < centers.size(); i++) {
    model.getClusters().add(toCluster(centers.get(i), i));
  }
  return model;
}
 
开发者ID:apsaltis,项目名称:oryx,代码行数:17,代码来源:ClusteringModelBuilder.java

示例4: pmmlClusteringModel

import org.dmg.pmml.ComparisonMeasure; //导入依赖的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

示例5: encodeModel

import org.dmg.pmml.ComparisonMeasure; //导入依赖的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

示例6: encodeComparisonMeasure

import org.dmg.pmml.ComparisonMeasure; //导入依赖的package包/类
static
private ComparisonMeasure encodeComparisonMeasure(String metric, int p){

	switch(metric){
		case "minkowski":
			{
				Measure measure;

				switch(p){
					case 1:
						measure = new CityBlock();
						break;
					case 2:
						measure = new Euclidean();
						break;
					default:
						measure = new Minkowski(p);
						break;
				}

				ComparisonMeasure comparisonMeasure = new ComparisonMeasure(ComparisonMeasure.Kind.DISTANCE)
					.setCompareFunction(CompareFunction.ABS_DIFF)
					.setMeasure(measure);

				return comparisonMeasure;
			}
		default:
			throw new IllegalArgumentException(metric);
	}
}
 
开发者ID:jpmml,项目名称:jpmml-sklearn,代码行数:31,代码来源:KNeighborsUtil.java

示例7: encodeModel

import org.dmg.pmml.ComparisonMeasure; //导入依赖的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

示例8: ClusteringModelEvaluator

import org.dmg.pmml.ComparisonMeasure; //导入依赖的package包/类
public ClusteringModelEvaluator(PMML pmml, ClusteringModel clusteringModel){
	super(pmml, clusteringModel);

	ComparisonMeasure comparisonMeasure = clusteringModel.getComparisonMeasure();
	if(comparisonMeasure == null){
		throw new MissingElementException(clusteringModel, PMMLElements.CLUSTERINGMODEL_COMPARISONMEASURE);
	}

	ClusteringModel.ModelClass modelClass = clusteringModel.getModelClass();
	switch(modelClass){
		case CENTER_BASED:
			break;
		default:
			throw new UnsupportedAttributeException(clusteringModel, modelClass);
	}

	CenterFields centerFields = clusteringModel.getCenterFields();
	if(centerFields != null){
		throw new UnsupportedElementException(centerFields);
	}

	if(!clusteringModel.hasClusteringFields()){
		throw new MissingElementException(clusteringModel, PMMLElements.CLUSTERINGMODEL_CLUSTERINGFIELDS);
	} // End if

	if(!clusteringModel.hasClusters()){
		throw new MissingElementException(clusteringModel, PMMLElements.CLUSTERINGMODEL_CLUSTERS);
	}

	Targets targets = clusteringModel.getTargets();
	if(targets != null){
		throw new MisplacedElementException(targets);
	}
}
 
开发者ID:jpmml,项目名称:jpmml-evaluator,代码行数:35,代码来源:ClusteringModelEvaluator.java

示例9: evaluateDistance

import org.dmg.pmml.ComparisonMeasure; //导入依赖的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

示例10: ensureMeasure

import org.dmg.pmml.ComparisonMeasure; //导入依赖的package包/类
static
public Measure ensureMeasure(ComparisonMeasure comparisonMeasure){
	Measure measure = comparisonMeasure.getMeasure();
	if(measure == null){
		throw new MissingElementException(MissingElementException.formatMessage(XPathUtil.formatElement(comparisonMeasure.getClass()) + "/<Measure>"), comparisonMeasure);
	}

	return measure;
}
 
开发者ID:jpmml,项目名称:jpmml-evaluator,代码行数:10,代码来源:MeasureUtil.java

示例11: NearestNeighborModelEvaluator

import org.dmg.pmml.ComparisonMeasure; //导入依赖的package包/类
public NearestNeighborModelEvaluator(PMML pmml, NearestNeighborModel nearestNeighborModel){
	super(pmml, nearestNeighborModel);

	ComparisonMeasure comparisoonMeasure = nearestNeighborModel.getComparisonMeasure();
	if(comparisoonMeasure == null){
		throw new MissingElementException(nearestNeighborModel, PMMLElements.NEARESTNEIGHBORMODEL_COMPARISONMEASURE);
	}

	TrainingInstances trainingInstances = nearestNeighborModel.getTrainingInstances();
	if(trainingInstances == null){
		throw new MissingElementException(nearestNeighborModel, PMMLElements.NEARESTNEIGHBORMODEL_TRAININGINSTANCES);
	}

	InstanceFields instanceFields = trainingInstances.getInstanceFields();
	if(instanceFields == null){
		throw new MissingElementException(trainingInstances, PMMLElements.TRAININGINSTANCES_INSTANCEFIELDS);
	} // End if

	if(!instanceFields.hasInstanceFields()){
		throw new MissingElementException(instanceFields, PMMLElements.INSTANCEFIELDS_INSTANCEFIELDS);
	}

	KNNInputs knnInputs = nearestNeighborModel.getKNNInputs();
	if(knnInputs == null){
		throw new MissingElementException(nearestNeighborModel, PMMLElements.NEARESTNEIGHBORMODEL_KNNINPUTS);
	} // End if

	if(!knnInputs.hasKNNInputs()){
		throw new MissingElementException(knnInputs, PMMLElements.KNNINPUTS_KNNINPUTS);
	}
}
 
开发者ID:jpmml,项目名称:jpmml-evaluator,代码行数:32,代码来源:NearestNeighborModelEvaluator.java

示例12: evaluateInstanceRows

import org.dmg.pmml.ComparisonMeasure; //导入依赖的package包/类
private <V extends Number> List<InstanceResult<V>> evaluateInstanceRows(ValueFactory<V> valueFactory, EvaluationContext context){
	NearestNeighborModel nearestNeighborModel = getModel();

	ComparisonMeasure comparisonMeasure = nearestNeighborModel.getComparisonMeasure();

	List<FieldValue> values = new ArrayList<>();

	KNNInputs knnInputs = nearestNeighborModel.getKNNInputs();
	for(KNNInput knnInput : knnInputs){
		FieldName name = knnInput.getField();
		if(name == null){
			throw new MissingAttributeException(knnInput, PMMLAttributes.KNNINPUT_FIELD);
		}

		FieldValue value = context.evaluate(name);

		values.add(value);
	}

	Measure measure = MeasureUtil.ensureMeasure(comparisonMeasure);

	if(measure instanceof Similarity){
		return evaluateSimilarity(valueFactory, comparisonMeasure, knnInputs.getKNNInputs(), values);
	} else

	if(measure instanceof Distance){
		return evaluateDistance(valueFactory, comparisonMeasure, knnInputs.getKNNInputs(), values);
	} else

	{
		throw new UnsupportedElementException(measure);
	}
}
 
开发者ID:jpmml,项目名称:jpmml-evaluator,代码行数:34,代码来源:NearestNeighborModelEvaluator.java

示例13: buildDummyClusteringModel

import org.dmg.pmml.ComparisonMeasure; //导入依赖的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

示例14: testKMeans

import org.dmg.pmml.ComparisonMeasure; //导入依赖的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

示例15: evaluateSimilarity

import org.dmg.pmml.ComparisonMeasure; //导入依赖的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.ComparisonMeasure类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。