Пример #1
0
        private static ConfusionMatrixValidation TestClassificator(AbstractClassification classificator, bool printToStdout = false)
        {
            List <DataElement> dataSet = new List <DataElement>();

            using (Database db = new Database())
            {
                dataSet = db.GetElements();
            }

            classificator.Learn(dataSet);
            ConfusionMatrixValidation validator = new ConfusionMatrixValidation(classificator, dataSet, crossValidationSets);

            if (printToStdout)
            {
                Console.WriteLine($"Accuracy rate: {validator.AccuracyRate}");
                Console.WriteLine($"Correct: {validator.CorrectCount}");
                Console.WriteLine($"Errors: {validator.ErrorCount}");

                for (int i = 0; i < Enum.GetNames(typeof(SongGenre)).Length; i++)
                {
                    SongGenre genre = (SongGenre)i;
                    Console.WriteLine("------------");
                    Console.WriteLine(genre.ToString().ToUpper());
                    Console.WriteLine("------------");
                    Console.WriteLine($"ROC > True Positive rate: {validator.TPRate(genre)}");
                    Console.WriteLine($"ROC > False Positive rate: {validator.FPRate(genre)}");
                    Console.WriteLine($"True positive: {validator.TP(genre)}");
                    Console.WriteLine($"True negative: {validator.TN(genre)}");
                    Console.WriteLine($"False positive: {validator.FP(genre)}");
                    Console.WriteLine($"False negative: {validator.FN(genre)}");
                }
            }
            return(validator);
        }
Пример #2
0
        private static string ConvertToString(ConfusionMatrixValidation validator, string delimiter)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(validator.AccuracyRate);
            sb.Append(delimiter);
            sb.Append(validator.CorrectCount);
            sb.Append(delimiter);
            sb.Append(validator.ErrorCount);
            sb.Append(delimiter);
            sb.Append(validator.ComputationTime);
            sb.Append(delimiter);

            for (int i = 0; i < Enum.GetNames(typeof(SongGenre)).Length; i++)
            {
                SongGenre genre = (SongGenre)i;
                sb.Append(validator.Precision(genre));
                sb.Append(delimiter);
                sb.Append(validator.Recall(genre));
                sb.Append(delimiter);
                sb.Append(validator.TPRate(genre));
                sb.Append(delimiter);
                sb.Append(validator.FPRate(genre));
                sb.Append(delimiter);
                sb.Append(validator.TP(genre));
                sb.Append(delimiter);
                sb.Append(validator.TN(genre));
                sb.Append(delimiter);
                sb.Append(validator.FP(genre));
                sb.Append(delimiter);
                sb.Append(validator.FN(genre));
                sb.Append(delimiter);
            }

            return(sb.ToString());
        }