CategoryType
- The type of the category object over the confusion matrix.public class DefaultConfusionMatrix<CategoryType> extends AbstractConfusionMatrix<CategoryType>
ConfusionMatrix
interface. It is
backed by a two-level map storing the category object counts, making a
sparse representation.Modifier and Type | Class and Description |
---|---|
static class |
DefaultConfusionMatrix.ActualPredictedPairSummarizer<CategoryType>
A confusion matrix summarizer that summarizes actual-predicted pairs.
|
static class |
DefaultConfusionMatrix.CombineSummarizer<CategoryType>
A confusion matrix summarizer that adds together confusion matrices.
|
static class |
DefaultConfusionMatrix.Factory<CategoryType>
A factory for default confusion matrices.
|
Modifier and Type | Field and Description |
---|---|
protected java.util.Map<CategoryType,java.util.Map<CategoryType,MutableDouble>> |
confusions
The backing map of confusion matrix entries.
|
Constructor and Description |
---|
DefaultConfusionMatrix()
Creates a new, empty
DefaultConfusionMatrix . |
DefaultConfusionMatrix(ConfusionMatrix<? extends CategoryType> other)
Creates a copy of a given confusion matrix.
|
Modifier and Type | Method and Description |
---|---|
void |
add(CategoryType target,
CategoryType estimate,
double value)
Adds a given value to the matrix entry for the (actual, predicted)
pair.
|
void |
clear()
Empties out all the data in this confusion matrix.
|
DefaultConfusionMatrix<CategoryType> |
clone()
This makes public the clone method on the
Object class and
removes the exception that it throws. |
static <CategoryType> |
createFromActualPredictedPairs(java.util.Collection<? extends Pair<? extends CategoryType,? extends CategoryType>> pairs)
Creates a new
DefaultConfusionMatrix from the given
actual-predicted pairs. |
static <CategoryType> |
createUnweighted(java.util.Collection<? extends TargetEstimatePair<? extends CategoryType,? extends CategoryType>> pairs)
Creates a new
DefaultConfusionMatrix from the given
actual-predicted pairs. |
java.util.Set<CategoryType> |
getActualCategories()
Gets the set of all the actual categories.
|
double |
getActualCount(CategoryType target)
Gets the total number of entries for the given actual category.
|
java.util.Set<CategoryType> |
getCategories()
Gets the set of all categories in the confusion matrix.
|
double |
getCount(CategoryType target,
CategoryType estimate)
Gets the entry in the matrix for the given actual and predicted
categories, which is the count of the number of times the predicted
category was given for the given actual category.
|
java.util.Set<CategoryType> |
getPredictedCategories()
Gets the set of all the predicted categories.
|
java.util.Set<CategoryType> |
getPredictedCategories(CategoryType target)
Gets the predicted categories for a given actual category.
|
java.lang.String |
toString() |
add, addAll, getAccuracy, getAverageCategoryAccuracy, getAverageCategoryErrorRate, getCategoryAccuracy, getCategoryErrorRate, getErrorRate, getPredictedCount, getTotalCorrectCount, getTotalCount, getTotalIncorrectCount, isEmpty
protected java.util.Map<CategoryType,java.util.Map<CategoryType,MutableDouble>> confusions
public DefaultConfusionMatrix()
DefaultConfusionMatrix
.public DefaultConfusionMatrix(ConfusionMatrix<? extends CategoryType> other)
other
- The other confusion matrix to copy.public DefaultConfusionMatrix<CategoryType> clone()
AbstractCloneableSerializable
Object
class and
removes the exception that it throws. Its default behavior is to
automatically create a clone of the exact type of object that the
clone is called on and to copy all primitives but to keep all references,
which means it is a shallow copy.
Extensions of this class may want to override this method (but call
super.clone()
to implement a "smart copy". That is, to target
the most common use case for creating a copy of the object. Because of
the default behavior being a shallow copy, extending classes only need
to handle fields that need to have a deeper copy (or those that need to
be reset). Some of the methods in ObjectUtil
may be helpful in
implementing a custom clone method.
Note: The contract of this method is that you must use
super.clone()
as the basis for your implementation.clone
in interface CloneableSerializable
clone
in class AbstractCloneableSerializable
public void add(CategoryType target, CategoryType estimate, double value)
ConfusionMatrix
target
- The actual category.estimate
- The predicted category.value
- The value to add.public double getCount(CategoryType target, CategoryType estimate)
ConfusionMatrix
target
- The actual category.estimate
- The predicted category.public double getActualCount(CategoryType target)
ConfusionMatrix
getActualCount
in interface ConfusionMatrix<CategoryType>
getActualCount
in class AbstractConfusionMatrix<CategoryType>
target
- The actual category.public void clear()
ConfusionMatrix
public java.util.Set<CategoryType> getCategories()
ConfusionMatrix
public java.util.Set<CategoryType> getActualCategories()
ConfusionMatrix
public java.util.Set<CategoryType> getPredictedCategories()
ConfusionMatrix
public java.util.Set<CategoryType> getPredictedCategories(CategoryType target)
ConfusionMatrix
target
- The actual category to get the set of prediction categories for.public java.lang.String toString()
toString
in class java.lang.Object
public static <CategoryType> DefaultConfusionMatrix<CategoryType> createUnweighted(java.util.Collection<? extends TargetEstimatePair<? extends CategoryType,? extends CategoryType>> pairs)
DefaultConfusionMatrix
from the given
actual-predicted pairs.CategoryType
- The category type.pairs
- The actual-category pairs.public static <CategoryType> DefaultConfusionMatrix<CategoryType> createFromActualPredictedPairs(java.util.Collection<? extends Pair<? extends CategoryType,? extends CategoryType>> pairs)
DefaultConfusionMatrix
from the given
actual-predicted pairs.CategoryType
- The category type.pairs
- The actual-category pairs.