double[] vals = new double[newInsts.numAttributes()];
for (int j = 0; j < predictedI.numAttributes(); j++) {
vals[j] = predictedI.instance(i).value(j);
}
vals[vals.length - 1] = 2; // default shape size
Instance ni = new DenseInstance(1.0, vals);
newInsts.add(ni);
}
// predicted class attribute is always actualClassIndex - 1
Instances[] classes = new Instances[newInsts.numClasses()];
for (int i = 0; i < newInsts.numClasses(); i++) {
classes[i] = new Instances(newInsts, 0);
classes[i].setRelationName(newInsts.classAttribute().value(i));
}
Instances errors = new Instances(newInsts, 0);
int actualClass = newInsts.classIndex();
for (int i = 0; i < newInsts.numInstances(); i++) {
Instance current = newInsts.instance(i);
classes[(int)current.classValue()].add((Instance)current.copy());
if (current.value(actualClass) != current.value(actualClass - 1)) {
Instance toAdd = (Instance)current.copy();
// larger shape for an error
toAdd.setValue(toAdd.numAttributes() - 1, 5);
// swap predicted and actual class value so
// that the color plotted for the error series
// is that of the predicted class
double actualClassV = toAdd.value(actualClass);
double predictedClassV = toAdd.value(actualClass - 1);
toAdd.setValue(actualClass, predictedClassV);
toAdd.setValue(actualClass - 1, actualClassV);
errors.add(toAdd);
}
}
errors.setRelationName("Errors");
m_offscreenPlotData.add(errors);
for (int i = 0; i < classes.length; i++) {
m_offscreenPlotData.add(classes[i]);
}
} else {
// numeric class - have to make a new set of instances
// with the point sizes added as an additional attribute
FastVector atts = new FastVector();
for (int i = 0; i < predictedI.numAttributes(); i++) {
atts.add(predictedI.attribute(i).copy());
}
atts.add(new Attribute("@@size@@"));
Instances newInsts = new Instances(predictedI.relationName(),
atts, predictedI.numInstances());
int[] shapeSizes = e.getDataSet().getShapeSize();
for (int i = 0; i < predictedI.numInstances(); i++) {
double[] vals = new double[newInsts.numAttributes()];
for (int j = 0; j < predictedI.numAttributes(); j++) {
vals[j] = predictedI.instance(i).value(j);
}
vals[vals.length - 1] = shapeSizes[i];
Instance ni = new DenseInstance(1.0, vals);
newInsts.add(ni);
}
newInsts.setRelationName(predictedI.classAttribute().name());
m_offscreenPlotData.add(newInsts);
}