public void Go() { var slow_VI = new List <myClusterable>(); slow_VI = GetData(); Console.WriteLine("Raw unclustered data:\n"); Console.WriteLine("----------------------"); ShowData(slow_VI, 1, true, false); var c = new Clusterer(); c.Data = slow_VI; Console.WriteLine("\nSetting numClusters to 3"); Console.WriteLine("Starting clustering using k-means algorithm"); int numClusters = c.numCentroids = 3; int[] results = c.Cluster(); Console.WriteLine("Clustering complete\n"); Console.WriteLine("Final clustering in internal form:\n"); ShowVector(results, true); Console.WriteLine("Raw data by cluster:\n"); ShowClustered(slow_VI, results, numClusters, 1); Console.WriteLine("OK, done"); //Console.ReadLine(); }
public void CreateItemClusters() { // this is equal to the number of possible genres (in the MovieLens 1M dataset that is 18) int numFeatures = 18; double[,] genreFeatures = new double[Items.Count, numFeatures]; var itemIds = new List <string>(); int i = 0; foreach (var item in Items.Values) { itemIds.Add(item.Id); string genresStr = item.Properties["genres"]; var genres = genresStr.Split('|'); foreach (string g in genres) { genreFeatures[i, _mapper.ToInternalID(g)] = 1; } i++; } _itemsCluster = Clusterer.Cluster(itemIds, genreFeatures, NumDomains); }
public static void Run() { //const string path = @"F:\thoughts\"; while (true) { Console.WriteLine("Write path to file(s):"); var path = Console.ReadLine(); Console.WriteLine("Where to save results?"); var savePath = Console.ReadLine(); if (path != null) { var fileReader = new FileReader(path); var documents = fileReader.PerformRead(); var clusterableDocuments = new MyDocumentToClusterableEntityMapper().MapAllData(documents); var kMeansDatas = new ClusterableEntityToKMeansEntityMapper().MapAllData(clusterableDocuments); var clusterer = new Clusterer(7); clusterer.Cluster(kMeansDatas, null); var results = new ClusteredDataResultWriter().WriteResults(kMeansDatas); if (savePath != null) { File.WriteAllText(savePath, results); } } Console.WriteLine($"Amount of exceptions while reading: {exceptionsCount}"); Console.Read(); } }
private async void performKMeans_Click(object sender, EventArgs e) { informer.Text = " "; var task = Task.Run(() => { var clusterer = new Clusterer(5); clusterer.Cluster(data, DrawChangedData); }); await task; informer.Text = "Done!"; }
static void K_Means_Main(string[] args) { Console.WriteLine($@"\nBegin k-means clustering demo\n"); #region setup double[][] rawData = new double[10][]; rawData[0] = new double[] { 73, 72.6 }; rawData[1] = new double[] { 61, 54.4 }; rawData[2] = new double[] { 67, 99.9 }; rawData[3] = new double[] { 68, 97.3 }; rawData[4] = new double[] { 62, 59.0 }; rawData[5] = new double[] { 75, 81.6 }; rawData[6] = new double[] { 74, 77.1 }; rawData[7] = new double[] { 66, 97.3 }; rawData[8] = new double[] { 68, 93.3 }; rawData[9] = new double[] { 61, 59.0 }; //double[][] rawData = LoadData("..\\..\\HeightWeight.txt", 10, 2, ','); #endregion Console.WriteLine("Raw unclustered height (in.) weight (kg.) data:\n"); Console.WriteLine(" ID Height Weight"); Console.WriteLine("----------------------"); ShowData(rawData, 1, true, false); int numClusters = 3; Console.WriteLine("\nSetting numClusters to " + numClusters); Console.WriteLine("Starting clustering using k-means algorithm"); Clusterer c = new Clusterer(numClusters); int[] clustering = c.Cluster(rawData); Console.WriteLine("Clustering complete\n"); Console.WriteLine("Final clustering in internal form:\n"); ShowVector(clustering, true); Console.WriteLine("Raw data by cluster:\n"); ShowClustered(rawData, clustering, numClusters, 1); Console.WriteLine("\nEnd k-means clustering demo\n"); Console.ReadLine(); }