ClusteringEvaluator<T>

Models & Types · AiDotNet.Clustering.Evaluation

Comprehensive evaluator for clustering results.

For Beginners

This is your “one-stop shop” for evaluating clusters.

Instead of calling each metric separately:

  • Create a ClusteringEvaluator
  • Call EvaluateAll() to get all metrics at once
  • Compare different clusterings easily

The evaluator handles:

  • Internal validity: How well-structured are the clusters?
  • External validity: How well do clusters match known labels?
  • Model selection: Which K is best? Which algorithm works best?

Use this when:

  • Comparing different clustering algorithms
  • Tuning parameters (like number of clusters)
  • Validating clustering results

How It Works

ClusteringEvaluator provides a unified interface to compute multiple cluster validity indices and metrics. It supports both internal metrics (using only the data) and external metrics (comparing to ground truth).

Constructors

Constructor Summary
ClusteringEvaluator() Initializes a new ClusteringEvaluator with default metrics.

Methods

Method Summary
ClusteringEvaluationResult EvaluateAll(Matrix<T> data, Vector<T> predictedLabels, Vector<T> trueLabels) Evaluates all metrics for a clustering result.
Dictionary<string, double> EvaluateExternal(Vector<T> trueLabels, Vector<T> predictedLabels) Evaluates all external metrics for a clustering result.
Dictionary<string, double> EvaluateInternal(Matrix<T> data, Vector<T> labels) Evaluates all internal metrics for a clustering result.
List<ClusteringComparisonResult> CompareClusterings(Matrix<T> data, List<Vector<T>> labelsList, List<string> algorithmNames) Compares multiple clustering results and ranks them.
OptimalKAnalysis FindOptimalK(Matrix<T> data, Func<int, Vector<T>> clusteringFunction, ValueTuple<int, int> kRange) Finds the optimal number of clusters using multiple criteria.
void AddExternalMetric(IExternalClusterMetric<T> metric) Adds a custom external metric to the evaluator.
void AddInternalMetric(IClusterMetric<T> metric) Adds a custom internal metric to the evaluator.