public static void ShowClusters(BaseKMeans kMeans) { Console.WriteLine(); Console.WriteLine($"Clusters count: {kMeans.ClustersCount}"); Console.WriteLine(); Console.WriteLine($"Centroids:"); kMeans.Centroids.ForEach(Console.WriteLine); ShowSongsByClusters(kMeans); }
static List <Prediction> MakePredictions(BaseKMeans model, List <Song> analyzingSongs) { SongSuccessPredictor predictor = new SongSuccessPredictor(model, model.DistanceFunc); predictor.PrepareData(); List <Prediction> predictions = analyzingSongs.Select(predictor.PredictSuccess).ToList(); // Console.WriteLine("Predictions:"); // predictions.ForEach(Console.WriteLine); return(predictions); }
double AnalyzeSilhouetteCoef(List <AnalyzedSong> analyzedSongs, BaseKMeans model) { double silhouetteCoefMean = 0.0; foreach (AnalyzedSong analyzedSong in AnalyzedSongs) { int nearestClusterIndex = model.GetNearestClusterIndex(analyzedSong.AssociatedSong); int secondNearestClusterIndex = model.GetSecondNearestClusterIndex(analyzedSong.AssociatedSong); List <Song> nearestCluster = model.Clusters[nearestClusterIndex]; List <Song> secondNearestCluster = model.Clusters[secondNearestClusterIndex]; double nearestClusterMeanDistance = 0.0; double secondNearestClusterMeanDistance = 0.0; foreach (Song song in nearestCluster) { double distance = model.DistanceFunc.GetDistance(song, analyzedSong.AssociatedSong); nearestClusterMeanDistance += distance; } foreach (Song song in secondNearestCluster) { double distance = model.DistanceFunc.GetDistance(song, analyzedSong.AssociatedSong); secondNearestClusterMeanDistance += distance; } nearestClusterMeanDistance /= nearestCluster.Count; secondNearestClusterMeanDistance /= secondNearestCluster.Count; double silhouetteCoef = (secondNearestClusterMeanDistance - nearestClusterMeanDistance) / Math.Max(nearestClusterMeanDistance, secondNearestClusterMeanDistance); analyzedSong.SilhouetteCoef = silhouetteCoef; silhouetteCoefMean += silhouetteCoef; } silhouetteCoefMean /= analyzedSongs.Count; return(silhouetteCoefMean); }
static void ShowSongsByClusters(BaseKMeans clusterizer) { Console.WriteLine(); Console.WriteLine($"Clusters size:"); clusterizer.Clusters.ForEach(cluster => Console.WriteLine($"Size: {cluster.Count}")); }
public ModelAnalyzer(BaseKMeans model) { Model = model; }
public SongSuccessPredictor(BaseKMeans clusterizer, IDistanceFunc distanceFunc) { Clusterizer = clusterizer; DistanceFunc = distanceFunc; Probabilities = new List <double>(Clusterizer.Clusters.Capacity); }