Accord.Statistics.Analysis.ConfusionMatrix.ConfusionMatrix C# (CSharp) Method

ConfusionMatrix() public method

Constructs a new Confusion Matrix.
public ConfusionMatrix ( bool predicted, bool expected ) : System
predicted bool The values predicted by the model.
expected bool The actual, truth values from the data.
return System
        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
                    }
                }
            }
        }

Same methods

ConfusionMatrix::ConfusionMatrix ( int matrix ) : System
ConfusionMatrix::ConfusionMatrix ( int predicted, int expected, int positiveValue = 1 ) : System
ConfusionMatrix::ConfusionMatrix ( int truePositives, int falseNegatives, int falsePositives, int trueNegatives ) : System