/** * Generates a <code>ConfusionMatrix</code> representing the current two-class * statistics, using class names "negative" and "positive". * * @return a <code>ConfusionMatrix</code>. */ public ConfusionMatrix getConfusionMatrix() { ConfusionMatrix cm = new ConfusionMatrix(CATEGORY_NAMES); cm.set(0, 0, m_TrueNeg); cm.set(0, 1, m_FalsePos); cm.set(1, 0, m_FalseNeg); cm.set(1, 1, m_TruePos); return cm; }
/** * Gets the number of correct classifications (that is, for which a correct * prediction was made). (Actually the sum of the weights of these * classifications) * * @return the number of correct classifications */ public double correct() { double correct = 0; for (int i = 0; i < size(); i++) { correct += get(i, i); } return correct; }
/** * Makes a copy of this ConfusionMatrix after applying the supplied CostMatrix * to the cells. The resulting ConfusionMatrix can be used to get * cost-weighted statistics. * * @param costs the CostMatrix. * @return a ConfusionMatrix that has had costs applied. * @exception Exception if the CostMatrix is not of the same size as this * ConfusionMatrix. */ public ConfusionMatrix makeWeighted(CostMatrix costs) throws Exception { if (costs.size() != size()) { throw new Exception("Cost and confusion matrices must be the same size"); } ConfusionMatrix weighted = new ConfusionMatrix(m_ClassNames); for (int row = 0; row < size(); row++) { for (int col = 0; col < size(); col++) { weighted.set(row, col, get(row, col) * costs.getElement(row, col)); } } return weighted; }
for (int i = 0; i < size(); i++) { for (int j = 0; j < size(); j++) { double current = get(i, j); if (current < 0) { current *= -10; (int) (Math.log(size()) / Math.log(IDChars.length))); text.append(title).append("\n"); for (int i = 0; i < size(); i++) { if (fractional) { text.append(" ").append(num2ShortID(i, IDChars, IDWidth - 3)) .append(" "); } else { text.append(" ").append(num2ShortID(i, IDChars, IDWidth)); for (int i = 0; i < size(); i++) { for (int j = 0; j < size(); j++) { text.append(" ").append( Utils.doubleToString(get(i, j), IDWidth, (fractional ? 2 : 0))); text.append(" | ").append(num2ShortID(i, IDChars, IDWidth)).append(" = ") .append(m_ClassNames[i]).append("\n");
/** * 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()); }
/** * Calls toString() with a default title. * * @return the confusion matrix as a string */ @Override public String toString() { return toString("=== Confusion Matrix ===\n"); }
/** * Includes a whole bunch of predictions in the confusion matrix. * * @param predictions a FastVector containing the NominalPredictions to * include * @exception Exception if no valid prediction was made (i.e. unclassified). */ public void addPredictions(ArrayList<Prediction> predictions) throws Exception { for (int i = 0; i < predictions.size(); i++) { addPrediction((NominalPrediction) predictions.get(i)); } }
/** * Makes a copy of this ConfusionMatrix after applying the supplied CostMatrix * to the cells. The resulting ConfusionMatrix can be used to get * cost-weighted statistics. * * @param costs the CostMatrix. * @return a ConfusionMatrix that has had costs applied. * @exception Exception if the CostMatrix is not of the same size as this * ConfusionMatrix. */ public ConfusionMatrix makeWeighted(CostMatrix costs) throws Exception { if (costs.size() != size()) { throw new Exception("Cost and confusion matrices must be the same size"); } ConfusionMatrix weighted = new ConfusionMatrix(m_ClassNames); for (int row = 0; row < size(); row++) { for (int col = 0; col < size(); col++) { weighted.set(row, col, get(row, col) * costs.getElement(row, col)); } } return weighted; }
for (int i = 0; i < size(); i++) { for (int j = 0; j < size(); j++) { double current = get(i, j); if (current < 0) { current *= -10; (int) (Math.log(size()) / Math.log(IDChars.length))); text.append(title).append("\n"); for (int i = 0; i < size(); i++) { if (fractional) { text.append(" ").append(num2ShortID(i, IDChars, IDWidth - 3)) .append(" "); } else { text.append(" ").append(num2ShortID(i, IDChars, IDWidth)); for (int i = 0; i < size(); i++) { for (int j = 0; j < size(); j++) { text.append(" ").append( Utils.doubleToString(get(i, j), IDWidth, (fractional ? 2 : 0))); text.append(" | ").append(num2ShortID(i, IDChars, IDWidth)).append(" = ") .append(m_ClassNames[i]).append("\n");
/** * 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()); }
/** * Calls toString() with a default title. * * @return the confusion matrix as a string */ @Override public String toString() { return toString("=== Confusion Matrix ===\n"); }
/** * Includes a whole bunch of predictions in the confusion matrix. * * @param predictions a FastVector containing the NominalPredictions to * include * @exception Exception if no valid prediction was made (i.e. unclassified). */ public void addPredictions(ArrayList<Prediction> predictions) throws Exception { for (int i = 0; i < predictions.size(); i++) { addPrediction((NominalPrediction) predictions.get(i)); } }
/** * Gets the number of correct classifications (that is, for which a correct * prediction was made). (Actually the sum of the weights of these * classifications) * * @return the number of correct classifications */ public double correct() { double correct = 0; for (int i = 0; i < size(); i++) { correct += get(i, i); } return correct; }
/** * Generates a <code>ConfusionMatrix</code> representing the current two-class * statistics, using class names "negative" and "positive". * * @return a <code>ConfusionMatrix</code>. */ public ConfusionMatrix getConfusionMatrix() { ConfusionMatrix cm = new ConfusionMatrix(CATEGORY_NAMES); cm.set(0, 0, m_TrueNeg); cm.set(0, 1, m_FalsePos); cm.set(1, 0, m_FalseNeg); cm.set(1, 1, m_TruePos); return cm; }
/** * Gets the number of predictions that were made (actually the sum of the * weights of predictions where the class value was known). * * @return the number of predictions with known class */ public double total() { double total = 0; for (int row = 0; row < size(); row++) { for (int col = 0; col < size(); col++) { total += get(row, col); } } return total; }
/** * Gets the number of predictions that were made (actually the sum of the * weights of predictions where the class value was known). * * @return the number of predictions with known class */ public double total() { double total = 0; for (int row = 0; row < size(); row++) { for (int col = 0; col < size(); col++) { total += get(row, col); } } return total; }
/** * Gets the number of incorrect classifications (that is, for which an * incorrect prediction was made). (Actually the sum of the weights of these * classifications) * * @return the number of incorrect classifications */ public double incorrect() { double incorrect = 0; for (int row = 0; row < size(); row++) { for (int col = 0; col < size(); col++) { if (row != col) { incorrect += get(row, col); } } } return incorrect; }
/** * Gets the number of incorrect classifications (that is, for which an * incorrect prediction was made). (Actually the sum of the weights of these * classifications) * * @return the number of incorrect classifications */ public double incorrect() { double incorrect = 0; for (int row = 0; row < size(); row++) { for (int col = 0; col < size(); col++) { if (row != col) { incorrect += get(row, col); } } } return incorrect; }