use of weka.core.Instance in project dkpro-tc by dkpro.
the class WekaOutcomeIDReport method generateSlProperties.
protected Properties generateSlProperties(Instances predictions, boolean isRegression, boolean isUnit, Map<Integer, String> documentIdMap, List<String> labels) throws Exception {
Properties props = new SortedKeyProperties();
String[] classValues = new String[predictions.numClasses()];
for (int i = 0; i < predictions.numClasses(); i++) {
classValues[i] = predictions.classAttribute().value(i);
}
int attOffset = predictions.attribute(ID_FEATURE_NAME).index();
prepareBaseline();
int idx = 0;
for (Instance inst : predictions) {
Double gold;
try {
gold = new Double(inst.value(predictions.attribute(CLASS_ATTRIBUTE_NAME + WekaUtils.COMPATIBLE_OUTCOME_CLASS)));
} catch (NullPointerException e) {
// if train and test data have not been balanced
gold = new Double(inst.value(predictions.attribute(CLASS_ATTRIBUTE_NAME)));
}
Attribute gsAtt = predictions.attribute(WekaTestTask.PREDICTION_CLASS_LABEL_NAME);
Double prediction = new Double(inst.value(gsAtt));
if (!isRegression) {
Map<String, Integer> class2number = classNamesToMapping(labels);
// Integer predictionAsNumber = class2number
// .get(gsAtt.value(prediction.intValue()));
Integer goldAsNumber = class2number.get(classValues[gold.intValue()]);
String stringValue = inst.stringValue(attOffset);
if (!isUnit && documentIdMap != null) {
stringValue = documentIdMap.get(idx++);
}
props.setProperty(stringValue, getPrediction(prediction, class2number, gsAtt) + SEPARATOR_CHAR + goldAsNumber + SEPARATOR_CHAR + String.valueOf(-1));
} else {
// the outcome is numeric
String stringValue = inst.stringValue(attOffset);
if (documentIdMap != null) {
stringValue = documentIdMap.get(idx++);
}
props.setProperty(stringValue, prediction + SEPARATOR_CHAR + gold + SEPARATOR_CHAR + String.valueOf(0));
}
}
return props;
}
use of weka.core.Instance in project iobserve-analysis by research-iobserve.
the class TVectorQuantizationClustering method printInstances.
private void printInstances(final ClusteringResults results) {
results.printClusteringResults();
final Instances centroids = results.getClusteringMetrics().getCentroids();
for (int i = 0; i < centroids.numInstances(); i++) {
String logString = "";
logString += "***************************";
logString += "Cluster " + i;
logString += "***************************";
final Instance instance = centroids.instance(i);
for (int a = 0; a < instance.numAttributes(); a++) {
logString += centroids.attribute(a).name() + " : " + instance.value(a);
}
TVectorQuantizationClustering.LOGGER.info(logString);
}
}
use of weka.core.Instance in project iobserve-analysis by research-iobserve.
the class ClusterMerger method execute.
/*
* (non-Javadoc)
*
* @see teetime.framework.AbstractConsumerStage#execute(java.lang.Object)
*/
@Override
protected void execute(final Map<Integer, List<Pair<Instance, Double>>> clustering) throws Exception {
/**
* simply pick the first instance of every cluster lookup attributes to build a new
* instances Object
*/
Instance instance = clustering.entrySet().iterator().next().getValue().get(0).getElement1();
final FastVector attributes = new FastVector();
for (int j = 0; j < instance.numAttributes(); j++) {
attributes.addElement(instance.attribute(j));
}
final Instances result = new Instances("Clustering Result", attributes, clustering.size());
for (final List<Pair<Instance, Double>> entry : clustering.values()) {
if (!entry.isEmpty()) {
instance = entry.get(0).getElement1();
result.add(instance);
}
}
this.printInstances(result);
this.outputPort.send(result);
}
use of weka.core.Instance in project iobserve-analysis by research-iobserve.
the class BehaviorModelTable method toInstance.
/**
* returns an instance vector.
*
* @return instance
*/
public Instance toInstance() {
final List<Double> attValues = new ArrayList<>();
// add transitions
for (int i = 0; i < this.signatures.size(); i++) {
for (int j = 0; j < this.signatures.size(); j++) {
if (this.transitions[i][j] > AbstractBehaviorModelTable.TRANSITION_THRESHOLD) {
attValues.add(Double.valueOf(this.transitions[i][j]));
} else {
continue;
}
}
}
this.signatures.values().stream().forEach(pair -> Arrays.stream(pair.getSecond()).forEach(callInformation -> attValues.add(callInformation.getRepresentativeCode())));
final double[] attArray = new double[attValues.size()];
for (int i = 0; i < attValues.size(); i++) {
attArray[i] = attValues.get(i) == null ? 0.0 : attValues.get(i);
}
final Instance instance = new Instance(1.0, attArray);
return instance;
}
Aggregations