use of de.bwaldvogel.liblinear.Feature in project dkpro-tc by dkpro.
the class LiblinearLoadModelConnector method runPrediction.
@Override
protected File runPrediction(File infile) throws Exception {
Problem predictionProblem = Problem.readFromFile(infile, 1.0);
File tmp = File.createTempFile("libLinearePrediction", ".txt");
BufferedWriter writer = null;
try {
writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(tmp), "utf-8"));
Feature[][] testInstances = predictionProblem.x;
for (int i = 0; i < testInstances.length; i++) {
Feature[] instance = testInstances[i];
Double prediction = Linear.predict(liblinearModel, instance);
writer.write(prediction.toString() + "\n");
}
} finally {
IOUtils.closeQuietly(writer);
}
tmp.deleteOnExit();
return tmp;
}
use of de.bwaldvogel.liblinear.Feature in project dkpro-tc by dkpro.
the class LiblinearTestTask method runPrediction.
@Override
protected void runPrediction(TaskContext aContext, Object trainedModel) throws Exception {
Model model = (Model) trainedModel;
File fileTest = getTestFile(aContext);
File predFolder = aContext.getFolder("", AccessMode.READWRITE);
File predictionsFile = new File(predFolder, Constants.FILENAME_PREDICTIONS);
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(predictionsFile), "utf-8"));
writer.append("#PREDICTION;GOLD" + "\n");
Problem test = Problem.readFromFile(fileTest, 1.0);
Feature[][] testInstances = test.x;
for (int i = 0; i < testInstances.length; i++) {
Feature[] instance = testInstances[i];
Double prediction = Linear.predict(model, instance);
writer.write(prediction + SEPARATOR_CHAR + new Double(test.y[i]));
writer.write("\n");
}
writer.close();
}
Aggregations