use of org.dkpro.tc.ml.report.util.SortedKeyProperties in project dkpro-tc by dkpro.
the class WekaOutcomeIDReport method generateMlProperties.
protected static Properties generateMlProperties(Instances predictions, List<String> labels, MultilabelResult r) throws ClassNotFoundException, IOException {
Properties props = new SortedKeyProperties();
int attOffset = predictions.attribute(ID_FEATURE_NAME).index();
Map<String, Integer> class2number = classNamesToMapping(labels);
int[][] goldmatrix = r.getGoldstandard();
double[][] predictionsmatrix = r.getPredictions();
double bipartition = r.getBipartitionThreshold();
for (int i = 0; i < goldmatrix.length; i++) {
Double[] predList = new Double[labels.size()];
Integer[] goldList = new Integer[labels.size()];
for (int j = 0; j < goldmatrix[i].length; j++) {
int classNo = class2number.get(labels.get(j));
goldList[classNo] = goldmatrix[i][j];
predList[classNo] = predictionsmatrix[i][j];
}
String s = (StringUtils.join(predList, ",") + SEPARATOR_CHAR + StringUtils.join(goldList, ",") + SEPARATOR_CHAR + bipartition);
String stringValue = predictions.get(i).stringValue(attOffset);
props.setProperty(stringValue, s);
}
return props;
}
use of org.dkpro.tc.ml.report.util.SortedKeyProperties 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 org.dkpro.tc.ml.report.util.SortedKeyProperties in project dkpro-tc by dkpro.
the class DynetMetaReport method execute.
@Override
public void execute() throws Exception {
String python = getDiscriminator(getContext(), DIM_PYTHON_INSTALLATION);
String dynetVersion = getDyNetVersion(python);
String numpyVersion = getNumpyVersion(python);
Properties p = new SortedKeyProperties();
p.setProperty("NumpyVersion", numpyVersion);
p.setProperty("DyNetVersion", dynetVersion);
File file = getContext().getFile("softwareVersions.txt", AccessMode.READWRITE);
FileOutputStream fos = null;
try {
fos = new FileOutputStream(file);
p.store(fos, "Version information");
} finally {
IOUtils.closeQuietly(fos);
}
}
Aggregations