MetricCollection<T>

Models & Types · AiDotNet.Evaluation.Results.Core

A collection of metrics, providing easy access by name and category.

Implements: IEnumerable<MetricWithCI<T>>

For Beginners

This is like a dictionary of metrics. You can access any metric by name (e.g., collection[“Accuracy”]) or iterate through all metrics. It also groups metrics by category (Classification, Regression, etc.) for organized reporting.

How It Works

MetricCollection provides a convenient way to store, access, and iterate over evaluation metrics. It supports indexing by name, filtering by category, and various output formats.

Constructors

Constructor Summary
MetricCollection() Initializes a new empty metric collection.
MetricCollection(IEnumerable<MetricWithCI<T>> metrics) Initializes a metric collection from an existing dictionary.

Properties

Property Summary
IReadOnlyCollection<string> Categories { get; } Gets all categories in the collection.
IReadOnlyCollection<string> Names { get; } Gets all metric names in the collection.
MetricWithCI<T> Item { get; }
int Count { get; } Gets the number of metrics in the collection.

Methods

Method Summary
Dictionary<string, Dictionary<string, T>> ToDictionaryByCategory() Converts the collection to a dictionary grouped by category.
Dictionary<string, T> ToDictionary() Converts the collection to a dictionary.
IEnumerable<MetricWithCI<T>> GetByCategory(string category) Gets all metrics in a specific category.
IEnumerable<MetricWithCI<T>> GetValidMetrics() Gets all valid metrics (non-NaN, non-infinite values).
IEnumerable<MetricWithCI<T>> Where(Func<MetricWithCI<T>, bool> predicate) Filters metrics by a predicate.
IEnumerator<MetricWithCI<T>> GetEnumerator() Returns an enumerator that iterates through the metrics.
MetricWithCI<T> GetBest(MetricDirection direction) Gets the best metric by the specified direction.
MetricWithCI<T> GetWorst(MetricDirection direction) Gets the worst metric by the specified direction.
bool Contains(string name) Checks if a metric exists in the collection.
bool TryGetMetric(string name, MetricWithCI<T> metric) Tries to get a metric by name.
string ToTableString(int decimalPlaces, bool includeCI) Formats all metrics as a table string.
void Add(MetricWithCI<T> metric) Adds a metric to the collection.
void AddOrUpdate(MetricWithCI<T> metric) Adds or updates a metric in the collection.
void AddRange(IEnumerable<MetricWithCI<T>> metrics) Adds multiple metrics to the collection.