ClusteringGridSearch<T>

Models & Types · AiDotNet.Clustering.AutoML

Grid search for clustering hyperparameter optimization.

Inheritance: UnsupervisedAutoMLBase<T> → ClusteringGridSearch<T>

For Beginners

Grid Search tries every combination of parameters.

Example: For KMeans with K={2,3,4} and init={“random”,“kmeans++”} Grid Search will try:

  • K=2, init=random
  • K=2, init=kmeans++
  • K=3, init=random
  • K=3, init=kmeans++
  • K=4, init=random
  • K=4, init=kmeans++

It evaluates each combination and returns the best one.

How It Works

ClusteringGridSearch systematically searches through a specified parameter grid to find the optimal hyperparameters for a given clustering algorithm.

Example

var dataMatrix = new Matrix<double>(new double[,] { { 1.0, 2.0 }, { 3.0, 4.0 }, { 5.0, 6.0 }, { 7.0, 8.0 } });
var gridSearch = new ClusteringGridSearch<double>();
var paramGrid = new Dictionary<string, object[]>
{
    { "NumClusters", new object[] { 2, 3, 4, 5 } }
};
var result = gridSearch.Search(dataMatrix, p => new KMeans<double>(
    ), paramGrid);

Constructors

Constructor Summary
ClusteringGridSearch(ClusteringMetricType primaryMetric) Initializes a new ClusteringGridSearch instance.

Methods

Method Summary
GridSearchCVResult<T> SearchCV(Matrix<T> data, Func<Dictionary<string, object>, IClustering<T>> clusteringFactory, Dictionary<string, object[]> parameterGrid, int numFolds) Performs grid search with cross-validation for more robust results.
GridSearchResult<T> Search(Matrix<T> data, Func<Dictionary<string, object>, IClustering<T>> clusteringFactory, Dictionary<string, object[]> parameterGrid) Performs grid search over parameter combinations.