Exemple #1
0
        public double CalculateMeasure(Model.IClassifier classifier, Data.Dataset dataset)
        {
            double measure = 0;

            switch (this._mode)
            {
            case AUCMode.Pooled:
            {
                measure = this.CalculatePooledAUC(classifier, dataset);
                break;
            }

            case AUCMode.Averaged:
            {
                measure = this.CalculateAverageAUC(classifier, dataset);
                break;
            }

            case AUCMode.Wegithed:
            {
                measure = this.CalculateWeightedAUC(classifier, dataset);
                break;
            }
            }

            return(measure);
        }
Exemple #2
0
        public static ConfusionMatrix[] ComputeConfusionMatrixes(Model.IClassifier classifier, Data.Dataset testset)
        {
            ConfusionMatrix[] list = new ConfusionMatrix[testset.Metadata.Target.Values.Length];

            Instance instance = null;

            for (int i = 0; i < testset.Size; i++)
            {
                instance = testset[i];
                bool correct = false;
                int  actual  = instance.Label;

                Prediction prediction  = classifier.Classify(instance);
                int        predicted   = prediction.Label;
                double     probability = prediction.Probabilities[prediction.Label];

                if (predicted == actual)
                {
                    correct = true;
                }

                for (int classIndex = 0; classIndex < list.Length; classIndex++)
                {
                    if (correct)
                    {
                        if (classIndex == actual)
                        {
                            list[classIndex].TP++;
                            list[classIndex].TP_Prob += probability;
                        }

                        else
                        {
                            list[classIndex].TN++;
                            list[classIndex].TN_Prob += probability;
                        }
                    }
                    else
                    {
                        if (classIndex == actual)
                        {
                            list[classIndex].FN++;
                            list[classIndex].FN_Prob += probability;
                        }
                        else if (classIndex == predicted)
                        {
                            list[classIndex].FP++;
                            list[classIndex].FP_Prob += probability;
                        }
                        else
                        {
                            list[classIndex].TN++;
                            list[classIndex].TN_Prob += probability;
                        }
                    }
                }
            }

            return(list);
        }
Exemple #3
0
        public static ConfusionMatrix[] GetConfusionMatrixes(Model.IClassifier classifier, Data.Dataset testset)
        {
            ConfusionMatrix[] list = new ConfusionMatrix[testset.Metadata.Target.Values.Length];


            foreach (Data.Example example in testset)
            {
                bool correct = false;
                int  actual  = example.Label;

                Prediction prediction  = classifier.Classify(example);
                int        predicted   = prediction.Label;
                double     probability = prediction.Probability;

                if (predicted == actual)
                {
                    correct = true;
                }

                for (int classIndex = 0; classIndex < list.Length; classIndex++)
                {
                    if (correct)
                    {
                        if (classIndex == actual)
                        {
                            list[classIndex].TP++;
                            list[classIndex].TP_Prob += probability;
                        }

                        else
                        {
                            list[classIndex].TN++;
                            list[classIndex].TN_Prob += probability;
                        }
                    }
                    else
                    {
                        if (classIndex == actual)
                        {
                            list[classIndex].FN++;
                            list[classIndex].FN_Prob += probability;
                        }
                        else if (classIndex == predicted)
                        {
                            list[classIndex].FP++;
                            list[classIndex].FP_Prob += probability;
                        }
                        else
                        {
                            list[classIndex].TN++;
                            list[classIndex].TN_Prob += probability;
                        }
                    }
                }
            }

            return(list);
        }