本文整理汇总了Java中com.rapidminer.example.Tools.checkAndCreateIds方法的典型用法代码示例。如果您正苦于以下问题:Java Tools.checkAndCreateIds方法的具体用法?Java Tools.checkAndCreateIds怎么用?Java Tools.checkAndCreateIds使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.rapidminer.example.Tools
的用法示例。
在下文中一共展示了Tools.checkAndCreateIds方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doWork
import com.rapidminer.example.Tools; //导入方法依赖的package包/类
@Override
public void doWork() throws OperatorException {
ExampleSet es = exampleSetInput.getData(ExampleSet.class);
int dimensions = getParameterAsInt(PARAMETER_DIMENSIONS);
Tools.onlyNumericalAttributes(es, "dimensionality reduction");
Tools.isNonEmpty(es);
Tools.checkAndCreateIds(es);
double[][] p = dimensionalityReduction(es, dimensions);
DimensionalityReducerModel model = new DimensionalityReducerModel(es, p, dimensions);
if (exampleSetOutput.isConnected()) {
exampleSetOutput.deliver(model.apply((ExampleSet) es.clone()));
}
originalOutput.deliver(es);
modelOutput.deliver(model);
}
示例2: generateInternalClusterModel
import com.rapidminer.example.Tools; //导入方法依赖的package包/类
@Override
protected ClusterModel generateInternalClusterModel(ExampleSet exampleSet) throws OperatorException {
// get parameters
int k = getParameterAsInt(PARAMETER_K);
// perform checks
Tools.isNonEmpty(exampleSet);
Tools.onlyNonMissingValues(exampleSet, getOperatorClassName(), this, new String[0]);
Tools.checkAndCreateIds(exampleSet);
if (exampleSet.size() < k) {
logWarning("number of clusters (k) = " + k + " > number of objects =" + exampleSet.size());
throw new UserError(this, 142, k);
}
ClusterModel model = createClusterModel(exampleSet);
return model;
}
示例3: doWork
import com.rapidminer.example.Tools; //导入方法依赖的package包/类
@Override
public void doWork() throws OperatorException {
ExampleSet es = exampleSetInput.getData(ExampleSet.class);
int dimensions = getParameterAsInt(PARAMETER_DIMENSIONS);
Tools.onlyNumericalAttributes(es, "dimensionality reduction");
Tools.isNonEmpty(es);
Tools.checkAndCreateIds(es);
double[][] p = dimensionalityReduction(es, dimensions);
DimensionalityReducerModel model = new DimensionalityReducerModel(es, p, dimensions);
if (exampleSetOutput.isConnected())
exampleSetOutput.deliver(model.apply((ExampleSet)es.clone()));
originalOutput.deliver(es);
modelOutput.deliver(model);
}
示例4: doWork
import com.rapidminer.example.Tools; //导入方法依赖的package包/类
@Override
public void doWork() throws OperatorException {
ExampleSet exampleSet = exampleSetInput.getData(ExampleSet.class);
Tools.checkAndCreateIds(exampleSet);
DistanceMeasure measure = measureHelper.getInitializedMeasure(exampleSet);
exampleSetOutput.deliver(new SimilarityExampleSet(exampleSet, measure));
}
示例5: doWork
import com.rapidminer.example.Tools; //导入方法依赖的package包/类
@Override
public void doWork() throws OperatorException {
ExampleSet exampleSet = exampleSetInput.getData(ExampleSet.class);
// needed for some measures
Tools.checkAndCreateIds(exampleSet);
DistanceMeasure measure = measureHelper.getInitializedMeasure(exampleSet);
SimilarityMeasureObject measureObject = new SimilarityMeasureObject(measure, exampleSet);
ObjectVisualizerService.addObjectVisualizer(measureObject, new ExampleVisualizer(exampleSet));
similarityOutput.deliver(measureObject);
exampleSetOutput.deliver(exampleSet);
}
示例6: doWork
import com.rapidminer.example.Tools; //导入方法依赖的package包/类
@Override
public void doWork() throws OperatorException {
ExampleSet exampleSet = exampleSetInput.getData(ExampleSet.class);
// checking and creating ids if necessary
Tools.checkAndCreateIds(exampleSet);
Attribute attribute = exampleSet.getAttributes().get(getParameterAsString(PARAMETER_ATTRIBUTE));
if (attribute != null) {
if (attribute.isNominal()) {
// search all possible values
HashMap<Double, Integer> valueMap = new HashMap<>();
int[] clusterAssignments = new int[exampleSet.size()];
int i = 0;
for (Example example : exampleSet) {
double value = example.getValue(attribute);
if (valueMap.containsKey(value)) {
clusterAssignments[i] = valueMap.get(value).intValue();
} else {
clusterAssignments[i] = valueMap.size();
valueMap.put(value, valueMap.size());
}
i++;
}
ClusterModel model = new ClusterModel(exampleSet, valueMap.size(),
getParameterAsBoolean(RMAbstractClusterer.PARAMETER_ADD_AS_LABEL),
getParameterAsBoolean(RMAbstractClusterer.PARAMETER_REMOVE_UNLABELED));
// assign examples to clusters
model.setClusterAssignments(clusterAssignments, exampleSet);
modelOutput.deliver(model);
exampleSetOutput.deliver(exampleSet);
} else {
throw new UserError(this, 119, getParameterAsString(PARAMETER_ATTRIBUTE), "ExampleSet2ClusterModel");
}
} else {
throw new AttributeNotFoundError(this, PARAMETER_ATTRIBUTE, getParameterAsString(PARAMETER_ATTRIBUTE));
}
}
示例7: doWork
import com.rapidminer.example.Tools; //导入方法依赖的package包/类
@Override
public void doWork() throws OperatorException {
ExampleSet exampleSet = exampleSetInput.getData(ExampleSet.class);
int maxLeafSize = getParameterAsInt(PARAMETER_MAX_LEAF_SIZE);
// additional checks
Tools.checkAndCreateIds(exampleSet);
Tools.onlyNonMissingValues(exampleSet, getOperatorClassName(), this, new String[0]);
// recursively descend until leaf_size smaller than max_leaf_size
HierarchicalClusterNode root = new HierarchicalClusterNode("root");
HierarchicalClusterModel model = new HierarchicalClusterModel(root);
int createdLeafs = descend(exampleSet, root, 0, maxLeafSize, getParameterAsInt(PARAMETER_MAX_DEPTH) - 1);
if (getParameterAsBoolean(PARAMETER_CREATE_CLUSTER_LABEL) && exampleSetOutput.isConnected()) {
try {
FlattenClusterModel flattener = OperatorService.createOperator(FlattenClusterModel.class);
flattener.setParameter(FlattenClusterModel.PARAMETER_NUMBER_OF_CLUSTER, createdLeafs + "");
ClusterModel flatModel = flattener.flatten(model, exampleSet);
ClusterModel2ExampleSet applier = OperatorService.createOperator(ClusterModel2ExampleSet.class);
ExampleSet labelledExampleSet = applier.addClusterAttribute(exampleSet, flatModel);
exampleSetOutput.deliver(labelledExampleSet);
modelOutput.deliver(model);
} catch (OperatorCreationException e) {
throw new OperatorException("Could not create FlattenClusterModel Operator: " + e, e);
}
} else {
Attribute clusterAttribute = exampleSet.getAttributes().getCluster();
if (clusterAttribute != null) {
exampleSet.getAttributes().remove(clusterAttribute);
}
exampleSetOutput.deliver(exampleSet);
modelOutput.deliver(model);
}
}
示例8: generateInternalClusterModel
import com.rapidminer.example.Tools; //导入方法依赖的package包/类
@Override
protected ClusterModel generateInternalClusterModel(ExampleSet exampleSet) throws OperatorException {
// checking and creating ids if necessary
Tools.checkAndCreateIds(exampleSet);
boolean addsClusterAttribute = addsClusterAttribute();
// init operator progress
getProgress().setTotal(exampleSet.size());
// generating assignment
RandomGenerator random = RandomGenerator.getRandomGenerator(this);
int clusterAssignments[] = new int[exampleSet.size()];
int k = getParameterAsInt(PARAMETER_NUMBER_OF_CLUSTERS);
ClusterModel model = new ClusterModel(exampleSet, k, addsLabelAttribute(),
getParameterAsBoolean(RMAbstractClusterer.PARAMETER_REMOVE_UNLABELED));
Attribute targetAttribute = null;
Iterator<Example> exIter = null;
if (addsClusterAttribute) {
// generating cluster attribute
targetAttribute = addClusterAttribute(exampleSet);
exIter = exampleSet.iterator();
}
for (int i = 0; i < exampleSet.size(); i++) {
clusterAssignments[i] = random.nextInt(k);
if (addsClusterAttribute) {
exIter.next().setValue(targetAttribute, "cluster_" + clusterAssignments[i]);
}
if (i % OPERATOR_PROGRESS_STEPS == 0) {
getProgress().setCompleted(i);
}
}
model.setClusterAssignments(clusterAssignments, exampleSet);
getProgress().complete();
return model;
}
示例9: doWork
import com.rapidminer.example.Tools; //导入方法依赖的package包/类
@Override
public void doWork() throws OperatorException {
ExampleSet exampleSet = exampleSetInput.getData(ExampleSet.class);
int maxLeafSize = getParameterAsInt(PARAMETER_MAX_LEAF_SIZE);
// additional checks
Tools.checkAndCreateIds(exampleSet);
Tools.onlyNonMissingValues(exampleSet, getOperatorClassName(), this, new String[0]);
// recursively descend until leaf_size smaller than max_leaf_size
HierarchicalClusterNode root = new HierarchicalClusterNode("root");
HierarchicalClusterModel model = new HierarchicalClusterModel(root);
int createdLeafs = descend(exampleSet, root, 0, maxLeafSize, getParameterAsInt(PARAMETER_MAX_DEPTH) - 1,
getProgress());
if (getParameterAsBoolean(PARAMETER_CREATE_CLUSTER_LABEL) && exampleSetOutput.isConnected()) {
try {
FlattenClusterModel flattener = OperatorService.createOperator(FlattenClusterModel.class);
flattener.setParameter(FlattenClusterModel.PARAMETER_NUMBER_OF_CLUSTER, createdLeafs + "");
ClusterModel flatModel = flattener.flatten(model, exampleSet);
ClusterModel2ExampleSet applier = OperatorService.createOperator(ClusterModel2ExampleSet.class);
ExampleSet labelledExampleSet = applier.addClusterAttribute(exampleSet, flatModel);
exampleSetOutput.deliver(labelledExampleSet);
modelOutput.deliver(model);
} catch (OperatorCreationException e) {
throw new OperatorException("Could not create FlattenClusterModel Operator: " + e, e);
}
} else {
Attribute clusterAttribute = exampleSet.getAttributes().getCluster();
if (clusterAttribute != null) {
exampleSet.getAttributes().remove(clusterAttribute);
}
exampleSetOutput.deliver(exampleSet);
modelOutput.deliver(model);
}
}
示例10: doWork
import com.rapidminer.example.Tools; //导入方法依赖的package包/类
@Override
public void doWork() throws OperatorException {
ExampleSet exampleSet = exampleSetInput.getData(ExampleSet.class);
Tools.checkAndCreateIds(exampleSet);
DistanceMeasure measure = measureHelper.getInitializedMeasure(exampleSet);
exampleSetOutput.deliver(new SimilarityExampleSet(exampleSet, measure));
}
示例11: doWork
import com.rapidminer.example.Tools; //导入方法依赖的package包/类
@Override
public void doWork() throws OperatorException {
ExampleSet exampleSet = exampleSetInput.getData(ExampleSet.class);
// needed for some measures
Tools.checkAndCreateIds(exampleSet);
DistanceMeasure measure = measureHelper.getInitializedMeasure(exampleSet);
SimilarityMeasureObject measureObject = new SimilarityMeasureObject(measure, exampleSet);
ObjectVisualizerService.addObjectVisualizer(measureObject, new ExampleVisualizer(exampleSet));
similarityOutput.deliver(measureObject);
exampleSetOutput.deliver(exampleSet);
}
示例12: doWork
import com.rapidminer.example.Tools; //导入方法依赖的package包/类
@Override
public void doWork() throws OperatorException {
ExampleSet exampleSet = exampleSetInput.getData(ExampleSet.class);
// checking and creating ids if necessary
Tools.checkAndCreateIds(exampleSet);
Attribute attribute = exampleSet.getAttributes().get(getParameterAsString(PARAMETER_ATTRIBUTE));
if (attribute != null) {
if (attribute.isNominal()) {
// search all possible values
HashMap<Double, Integer> valueMap = new HashMap<Double, Integer>();
int[] clusterAssignments = new int[exampleSet.size()];
int i = 0;
for (Example example: exampleSet) {
double value = example.getValue(attribute);
if (valueMap.containsKey(value)) {
clusterAssignments[i] = valueMap.get(value).intValue();
} else {
clusterAssignments[i] = valueMap.size();
valueMap.put(value, valueMap.size());
}
i++;
}
ClusterModel model = new ClusterModel(exampleSet, valueMap.size(), getParameterAsBoolean(RMAbstractClusterer.PARAMETER_ADD_AS_LABEL), getParameterAsBoolean(RMAbstractClusterer.PARAMETER_REMOVE_UNLABELED));
// assign examples to clusters
model.setClusterAssignments(clusterAssignments, exampleSet);
modelOutput.deliver(model);
exampleSetOutput.deliver(exampleSet);
} else {
throw new UserError(this, 119, getParameterAsString(PARAMETER_ATTRIBUTE), "ExampleSet2ClusterModel");
}
} else {
throw new UserError(this, 111, getParameterAsString(PARAMETER_ATTRIBUTE));
}
}
示例13: doWork
import com.rapidminer.example.Tools; //导入方法依赖的package包/类
@Override
public void doWork() throws OperatorException {
ExampleSet exampleSet = exampleSetInput.getData(ExampleSet.class);
int maxLeafSize = getParameterAsInt(PARAMETER_MAX_LEAF_SIZE);
// additional checks
Tools.checkAndCreateIds(exampleSet);
Tools.onlyNonMissingValues(exampleSet, "AgglomerativeClustering");
// recursively descend until leaf_size smaller than max_leaf_size
HierarchicalClusterNode root = new HierarchicalClusterNode("root");
HierarchicalClusterModel model = new HierarchicalClusterModel(root);
int createdLeafs = descend(exampleSet, root, 0, maxLeafSize, getParameterAsInt(PARAMETER_MAX_DEPTH) - 1);
if (getParameterAsBoolean(PARAMETER_CREATE_CLUSTER_LABEL) && exampleSetOutput.isConnected()) {
try {
FlattenClusterModel flattener = OperatorService.createOperator(FlattenClusterModel.class);
flattener.setParameter(FlattenClusterModel.PARAMETER_NUMBER_OF_CLUSTER, createdLeafs + "");
ClusterModel flatModel = flattener.flatten(model, exampleSet);
ClusterModel2ExampleSet applier = OperatorService.createOperator(ClusterModel2ExampleSet.class);
ExampleSet labelledExampleSet = applier.addClusterAttribute(exampleSet, flatModel);
exampleSetOutput.deliver(labelledExampleSet);
modelOutput.deliver(model);
} catch (OperatorCreationException e) {
throw new OperatorException("Could not create FlattenClusterModel Operator: "+e, e);
}
} else {
Attribute clusterAttribute = exampleSet.getAttributes().getCluster();
if (clusterAttribute != null) {
exampleSet.getAttributes().remove(clusterAttribute);
}
exampleSetOutput.deliver(exampleSet);
modelOutput.deliver(model);
}
}
示例14: doWork
import com.rapidminer.example.Tools; //导入方法依赖的package包/类
@Override
public void doWork() throws OperatorException {
ExampleSet requestSet = requestSetInput.getData(ExampleSet.class);
ExampleSet documentSet = referenceSetInput.getData(ExampleSet.class);
Tools.checkAndCreateIds(requestSet);
Tools.checkAndCreateIds(documentSet);
DistanceMeasure measure = DistanceMeasures.createMeasure(this);
measure.init(requestSet.getAttributes(), documentSet.getAttributes());
Attribute oldRequestId = requestSet.getAttributes().getId();
Attribute oldDocumentId = documentSet.getAttributes().getId();
// creating new exampleSet
Attribute requestId = AttributeFactory.createAttribute("request", oldRequestId.getValueType());
Attribute documentId = AttributeFactory.createAttribute("document", oldDocumentId.getValueType());
Attribute distance = AttributeFactory.createAttribute("distance", Ontology.REAL);
List<Attribute> newAttributes = new LinkedList<Attribute>();
Collections.addAll(newAttributes, requestId, documentId, distance);
MemoryExampleTable table = new MemoryExampleTable(newAttributes);
double searchModeFactor = getParameterAsInt(PARAMETER_SEARCH_MODE) == MODE_FARTHEST ? -1d : 1d;
boolean computeSimilarity = getParameterAsBoolean(PARAMETER_COMPUTE_SIMILARITIES);
for (Example request : requestSet) {
Collection<Tupel<Double, Double>> distances;
if (getParameterAsBoolean(PARAMETER_USE_K)) {
distances = new BoundedPriorityQueue<Tupel<Double, Double>>(getParameterAsInt(PARAMETER_K));
} else {
distances = new ArrayList<Tupel<Double, Double>>();
}
// calculating distance
for (Example document : documentSet) {
if (computeSimilarity) {
distances.add(new Tupel<Double, Double>(measure.calculateSimilarity(request, document)
* searchModeFactor, document.getValue(oldDocumentId)));
} else {
distances.add(new Tupel<Double, Double>(measure.calculateDistance(request, document) * searchModeFactor,
document.getValue(oldDocumentId)));
}
checkForStop();
}
// writing into table
DataRowFactory factory = new DataRowFactory(DataRowFactory.TYPE_DOUBLE_ARRAY, '.');
double requestIdValue = request.getValue(oldRequestId);
if (oldRequestId.isNominal()) {
requestIdValue = requestId.getMapping().mapString(request.getValueAsString(oldRequestId));
}
for (Tupel<Double, Double> tupel : distances) {
double documentIdValue = tupel.getSecond();
if (oldDocumentId.isNominal()) {
documentIdValue = documentId.getMapping().mapString(
oldDocumentId.getMapping().mapIndex((int) documentIdValue));
}
DataRow row = factory.create(3);
row.set(distance, tupel.getFirst() * searchModeFactor);
row.set(requestId, requestIdValue);
row.set(documentId, documentIdValue);
table.addDataRow(row);
checkForStop();
}
}
// sorting set
ExampleSet result = new SortedExampleSet(table.createExampleSet(), distance,
searchModeFactor == -1d ? SortedExampleSet.DECREASING : SortedExampleSet.INCREASING);
requestSetOutput.deliver(requestSet);
referenceSetOutput.deliver(documentSet);
resultSetOutput.deliver(result);
}
示例15: doWork
import com.rapidminer.example.Tools; //导入方法依赖的package包/类
@Override
public void doWork() throws OperatorException {
ExampleSet exampleSet = exampleSetInput.getData(ExampleSet.class);
DistanceMeasure measure = measureHelper.getInitializedMeasure(exampleSet);
// additional checks
Tools.onlyNonMissingValues(exampleSet, getOperatorClassName(), this, new String[0]);
Tools.checkAndCreateIds(exampleSet);
Attribute idAttribute = exampleSet.getAttributes().getId();
boolean idAttributeIsNominal = idAttribute.isNominal();
DistanceMatrix matrix = new DistanceMatrix(exampleSet.size());
Map<Integer, HierarchicalClusterNode> clusterMap = new HashMap<Integer, HierarchicalClusterNode>(exampleSet.size());
int[] clusterIds = new int[exampleSet.size()];
// filling the distance matrix
int nextClusterId = 0;
for (Example example1 : exampleSet) {
checkForStop();
clusterIds[nextClusterId] = nextClusterId;
int y = 0;
for (Example example2 : exampleSet) {
if (y > nextClusterId) {
matrix.set(nextClusterId, y, measure.calculateDistance(example1, example2));
}
y++;
}
if (idAttributeIsNominal) {
clusterMap.put(nextClusterId,
new HierarchicalClusterLeafNode(nextClusterId, example1.getValueAsString(idAttribute)));
} else {
clusterMap
.put(nextClusterId, new HierarchicalClusterLeafNode(nextClusterId, example1.getValue(idAttribute)));
}
nextClusterId++;
}
// creating linkage method
AbstractLinkageMethod linkage = new SingleLinkageMethod(matrix, clusterIds);
if (getParameterAsString(PARAMETER_MODE).equals(modes[1])) {
linkage = new CompleteLinkageMethod(matrix, clusterIds);
} else if (getParameterAsString(PARAMETER_MODE).equals(modes[2])) {
linkage = new AverageLinkageMethod(matrix, clusterIds);
}
// now building agglomerative tree bottom up
while (clusterMap.size() > 1) {
Agglomeration agglomeration = linkage.getNextAgglomeration(nextClusterId, clusterMap);
HierarchicalClusterNode newNode = new HierarchicalClusterNode(nextClusterId, agglomeration.getDistance());
newNode.addSubNode(clusterMap.get(agglomeration.getClusterId1()));
newNode.addSubNode(clusterMap.get(agglomeration.getClusterId2()));
clusterMap.remove(agglomeration.getClusterId1());
clusterMap.remove(agglomeration.getClusterId2());
clusterMap.put(nextClusterId, newNode);
nextClusterId++;
}
// creating model
HierarchicalClusterModel model = new DendogramHierarchicalClusterModel(clusterMap.entrySet().iterator().next()
.getValue());
// registering visualizer
ObjectVisualizerService.addObjectVisualizer(model, new ExampleVisualizer((ExampleSet) exampleSet.clone()));
modelOutput.deliver(model);
exampleSetOutput.deliver(exampleSet);
}