public ConfusionMatrix(bool[] predicted, bool[] expected)
{
// Initial argument checking
if (predicted == null)
throw new ArgumentNullException("predicted");
if (expected == null)
throw new ArgumentNullException("expected");
if (predicted.Length != expected.Length)
throw new DimensionMismatchException("expected", "The size of the predicted and expected arrays must match.");
// For each of the predicted values,
for (int i = 0; i < predicted.Length; i++)
{
bool prediction = predicted[i];
bool expectation = expected[i];
// If the prediction equals the true measured value
if (expectation == prediction)
{
// We have a hit. Now we have to see
// if it was a positive or negative hit
if (prediction == true)
{
truePositives++; // Positive hit
}
else
{
trueNegatives++; // Negative hit
}
}
else
{
// We have a miss. Now we have to see
// if it was a positive or negative miss
if (prediction == true)
{
falsePositives++; // Positive hit
}
else
{
falseNegatives++; // Negative hit
}
}
}
}