public void Training() { foreach (var data in Datas) { Distance = Math.Abs(data.Value - Clusters.ElementAt(0)); BeLong = new BeLongTo() { Cluster = 0, Distance = Distance }; for (var index = 0; index < Clusters.Count; index++) { Distance = Math.Abs(data.Value - Clusters[index]); if (Distance <= BeLong.Distance) { BeLong.Cluster = index; BeLong.Distance = Distance; } } TrainingDatas[BeLong.Cluster].Data.Add(data); } }
public KMean(List <Data> datas, int sumCluster, int maxTraining = 1200) { Clusters = new List <double>(); Datas = new List <Data>(datas); PreClusters = new List <double>(); TrainingDatas = new List <TrainingData>(); BeLong = new BeLongTo(); SumOfClusters = sumCluster; MaxTrainingTimes = maxTraining; }