Ejemplo n.º 1
0
        /// <summary>
        /// Writes a sequence of classification results into the stream.
        /// </summary>
        /// <param name="writer">The stream to write to.</param>
        /// <param name="results">The sequence of <see cref="ClassificationResult{T}"/> structures to write.</param>
        public static void Write(TextWriter writer, IEnumerable <ClassificationResult <T> > results)
        {
            if (results == null)
            {
                throw new ArgumentNullException(nameof(results));
            }

            foreach (ClassificationResult <T> result in results)
            {
                ClassificationResult <T> .Write(writer, result);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Writes class errors.
        /// </summary>
        /// <param name="writer">A stream to write the report to.</param>
        /// <param name="summary">Classification results for the class.</param>
        private static void WriteClassificationErrors(TextWriter writer, ClassSummary <T> summary)
        {
            int acceptedErrors = summary.Errors.Count();

            if (acceptedErrors > 0)
            {
                writer.WriteLine(string.Format(CultureInfo.InvariantCulture, "{0} ({1})", summary.Label, acceptedErrors));
                writer.WriteLine();
                ClassificationResult <T> .Write(writer, summary.Errors);

                writer.WriteLine("-----------------------------------------------------------------------------");
                writer.WriteLine();
            }
        }
Ejemplo 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);
            }
        }