public double calculateAccuracy(ArrayList predictions) { double correct = 0; if (predictions != null && predictions.size() > 0) { for (Object prediction : predictions) { NominalPrediction np = (NominalPrediction) prediction; if (np.predicted() == np.actual()) { correct++; } } return 100 * correct / predictions.size(); } return 0.0; }
/** * Gets a human readable representation of this prediction. * * @return a human readable representation of this prediction. */ public String toString() { StringBuffer sb = new StringBuffer(); sb.append("NOM: ").append(actual()).append(" ").append(predicted()); sb.append(' ').append(weight()); double [] dist = distribution(); for (int i = 0; i < dist.length; i++) { sb.append(' ').append(dist[i]); } return sb.toString(); }
/** * Gets a human readable representation of this prediction. * * @return a human readable representation of this prediction. */ public String toString() { StringBuffer sb = new StringBuffer(); sb.append("NOM: ").append(actual()).append(" ").append(predicted()); sb.append(' ').append(weight()); double [] dist = distribution(); for (int i = 0; i < dist.length; i++) { sb.append(' ').append(dist[i]); } return sb.toString(); }
/** * Includes a prediction in the confusion matrix. * * @param pred the NominalPrediction to include * @exception Exception if no valid prediction was made (i.e. unclassified). */ public void addPrediction(NominalPrediction pred) throws Exception { if (pred.predicted() == NominalPrediction.MISSING_VALUE) { throw new Exception("No predicted value given."); } if (pred.actual() == NominalPrediction.MISSING_VALUE) { throw new Exception("No actual value given."); } set((int) pred.actual(), (int) pred.predicted(), get((int) pred.actual(), (int) pred.predicted()) + pred.weight()); }
/** * Includes a prediction in the confusion matrix. * * @param pred the NominalPrediction to include * @exception Exception if no valid prediction was made (i.e. unclassified). */ public void addPrediction(NominalPrediction pred) throws Exception { if (pred.predicted() == NominalPrediction.MISSING_VALUE) { throw new Exception("No predicted value given."); } if (pred.actual() == NominalPrediction.MISSING_VALUE) { throw new Exception("No actual value given."); } set((int) pred.actual(), (int) pred.predicted(), get((int) pred.actual(), (int) pred.predicted()) + pred.weight()); }
protected static ExperimentResults resultsFromEvaluation(Evaluation eval, String authorCSV, List<String> documentTitles){ ExperimentResults results = new ExperimentResults(); FastVector predictions = eval.predictions(); String[] authors = getAuthorsFromAttributeString(authorCSV); //for each document for (int i = 0; i<predictions.size(); i++){ NominalPrediction prediction = (NominalPrediction)predictions.elementAt(i); String actual = authors[(int)prediction.actual()]; double[] probabilities = prediction.distribution(); Map<String,Double> probMap = new HashMap<String,Double>(); //for each potential author... for (int j = 0; j< probabilities.length; j++){ probMap.put(authors[j], probabilities[j]); } results.addDocResult(new DocResult(documentTitles.get(i),actual,probMap)); } return results; }
if (pred.actual() == Prediction.MISSING_VALUE) { System.err.println(getClass().getName() + " Skipping prediction with missing class value"); continue; if (pred.actual() == classIndex) { totPos += pred.weight(); } else { if (pred.actual() == Prediction.MISSING_VALUE) { System.err.println(getClass().getName() + " Skipping prediction with missing class value"); continue; if (pred.actual() == classIndex) { cumulativePos += pred.weight(); } else {
if (pred.actual() == Prediction.MISSING_VALUE) { System.err.println(getClass().getName() + " Skipping prediction with missing class value"); continue; if (pred.actual() == classIndex) { totPos += pred.weight(); } else { if (pred.actual() == Prediction.MISSING_VALUE) { System.err.println(getClass().getName() + " Skipping prediction with missing class value"); continue; if (pred.actual() == classIndex) { cumulativePos += pred.weight(); } else {