Exemplo n.º 1
0
 /// <summary>
 /// Writes a test report.
 /// </summary>
 /// <param name="fileName">The path to a file to write the report to.</param>
 /// <param name="report">The report to write.</param>
 /// <param name="mode">Defines the components of the report to write.</param>
 public static void WriteReport(string fileName, ClassificationReport <T> report, ClassificationReportMode mode)
 {
     using (StreamWriter outputFile = File.CreateText(fileName))
     {
         ClassificationReportWriter <T> .WriteReport(outputFile, report, mode);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Writes a test report into a string.
        /// </summary>
        /// <param name="report">The report to write.</param>
        /// <param name="mode">Defines the components of the report to write.</param>
        /// <returns>
        /// The <see cref="string"/> that contains test report.
        /// </returns>
        public static string WriteReport(ClassificationReport <T> report, ClassificationReportMode mode)
        {
            using (StringWriter stream = new StringWriter())
            {
                ClassificationReportWriter <T> .WriteReport(stream, report, mode);

                return(stream.ToString());
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Writes a test report.
        /// </summary>
        /// <param name="writer">The writer used to write the report.</param>
        /// <param name="report">The report to write.</param>
        /// <param name="mode">Defines the components of the report to write.</param>
        public static void WriteReport(TextWriter writer, ClassificationReport <T> report, ClassificationReportMode mode)
        {
            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }

            if (report == null)
            {
                throw new ArgumentNullException(nameof(report));
            }

            IList <ClassSummary <T> > summaries = report.Classes.OrderBy(x => x.Label).ToList();

            if (summaries.Any())
            {
                // print report header
                if (mode.HasFlag(ClassificationReportMode.Summary))
                {
                    writer.WriteLine("=============================================================================");
                    writer.WriteLine("SUMMARY");
                    int maxClassNameLength = Math.Max(summaries.Max(x => x.Label.ToString().Length), 8);
                    writer.Write(string.Format(CultureInfo.InvariantCulture, "{{0,-{0}}},", maxClassNameLength), "Class");
                    writer.Write(ShortFormat, "Total", "%", "#");
                    writer.Write(LongFormat, "Total", "%", "#", "Error %", "Error #", "Valid %", "Valid #");
                    writer.WriteLine();

                    // print each class
                    foreach (ClassSummary <T> summary in summaries)
                    {
                        ClassificationReportWriter <T> .WriteClassStatistics(writer, summary, maxClassNameLength);
                    }

                    // print summary
                    writer.WriteLine();
                    ClassificationReportWriter <T> .WriteClassStatistics(writer, report.AllClasses, maxClassNameLength);
                }

                // print confusion matrix
                if (mode.HasFlag(ClassificationReportMode.ConfusionMatrix))
                {
                    writer.WriteLine();
                    writer.WriteLine("=============================================================================");
                    writer.WriteLine("CONFUSION MATRIX");
                    writer.WriteLine();
                    ClassificationReportWriter <T> .WriteConfusionMatrix(writer, report.ConfusionMatrix);
                }

                // print reject curves
                if (mode.HasFlag(ClassificationReportMode.RejectCurves))
                {
                    writer.WriteLine();
                    writer.WriteLine("=============================================================================");
                    writer.WriteLine("REJECT CURVES");
                    writer.WriteLine();
                    ClassificationReportWriter <T> .WriteRejectCurves(writer, report.AllClasses, summaries);
                }

                // print errors
                if (mode.HasFlag(ClassificationReportMode.Errors))
                {
                    writer.WriteLine();
                    writer.WriteLine("=============================================================================");
                    writer.WriteLine("ERRORS");
                    writer.WriteLine();
                    foreach (ClassSummary <T> summary in summaries)
                    {
                        ClassificationReportWriter <T> .WriteClassificationErrors(writer, summary);
                    }
                }
            }

            // print file results
            if (mode.HasFlag(ClassificationReportMode.Answers))
            {
                writer.WriteLine();
                writer.WriteLine("=============================================================================");
                writer.WriteLine("FILE RESULTS");
                writer.WriteLine();
                ClassificationResult <T> .Write(writer, report.Results);
            }
        }