/** * 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; }
/** * 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; }
m_TotalCost += instance.weight() * m_CostMatrix.getElement(actualClass, predictedClass, instance);
m_TotalCost += instance.weight() * m_CostMatrix.getElement(actualClass, predictedClass, instance);