public void CalculateResultForRules(FuzzyTable testData, List <Rule> rules, ConfusionMatrix confusionMatrix, double tolerance = .5) { Classificator classificator = new Classificator(); for (int i = 0; i < testData.GetTable().Rows.Count; i++) { var predictedResult = classificator.Classify(testData, i, rules); var predicterPositiveResult = predictedResult[testData.PositiveColumn.Id]; var predicterNegativeResult = predictedResult[testData.NegativeColumn.Id]; var actualPositiveResult = testData.GetPositiveColumn(i); var actualNegativeResult = testData.GetNegativeColumn(i); if (Math.Abs(predicterPositiveResult - actualPositiveResult) < tolerance) { confusionMatrix.TruePositiveCount++; } else { confusionMatrix.FalseNegativeCount++; } if (Math.Abs(predicterNegativeResult - actualNegativeResult) < tolerance) { confusionMatrix.TrueNegativeCount++; } else { confusionMatrix.FalsePositiveCount++; } } }
private static void DoResearch(Classificator classificator) { var data = GetDataLines(); var curveInfos = GetCurvesInfos(data); var classifiedCurveInfos = curveInfos.Select(curveInfo => new { curveInfo, curveClass = classificator.Classify(curveInfo) }) .ToArray(); var classesOfCurves = classifiedCurveInfos.GroupBy(info => info.curveInfo.DigitsCountOfFiledOrder) .OrderBy(g => g.Key) .Select(g => { var classesInfo = g .AsEnumerable() .GroupBy(cci => cci.curveClass.ClassNumber) .OrderBy(gr => gr.Key) .Select(gr => new { ClassNumber = gr.Key, Count = gr.Count() }).ToDictionary(x => x.ClassNumber, x => x.Count); return(new { Dimension = g.Key, ClassesInfo = classesInfo }); }) .ToArray(); var classesNumber = classesOfCurves.Max(x => x.ClassesInfo.Count); var paddingLeft = 8; Console.Write("Dim".PadLeft(paddingLeft, ' ')); for (var i = 0; i < classesNumber; i++) { Console.Write($"#{i + 1}".PadLeft(paddingLeft, ' ')); } Console.WriteLine(); foreach (var classesOfCurve in classesOfCurves) { Console.Write($"{classesOfCurve.Dimension}".PadLeft(paddingLeft, ' ')); for (var i = 0; i < classesNumber; i++) { if (classesOfCurve.ClassesInfo.ContainsKey(i + 1)) { Console.Write($"{classesOfCurve.ClassesInfo[i + 1]}".PadLeft(paddingLeft, ' ')); } else { Console.Write("0".PadLeft(paddingLeft, ' ')); } } Console.WriteLine(); } }