Esempio n. 1
0
		static void Main(string[] args)
		{
			Console.WriteLine("--------------------------------------");
			Console.WriteLine(" Data Mining Assignment 3             ");
			Console.WriteLine(" K-Means Algorithm implementation     ");
			Console.WriteLine(" by Volkan Paksoy                     ");
			Console.WriteLine("--------------------------------------");
			
			///////////////////////////////////////////////////////////////
			// Get required parameters from the user: Number of clusters (k) 
			// and the path for the database file
			Console.Write("Enter the number of clusters:  ");
			string strK = Console.ReadLine();
			int k = -1;
			bool bKEntered = Int32.TryParse(strK, out k);
			if (!bKEntered || k < 0)
			{
				Console.WriteLine("Invalid k value");
				return;
			}

			Console.Write("Enter path for database : ");
			filePath = Console.ReadLine();
			if (!File.Exists(filePath))
			{
				Console.WriteLine("File does not exist");
				return;
			}
			///////////////////////////////////////////////////////////////

			KMeansAlgorithm kmeans = new KMeansAlgorithm();
			kmeans.K = k;
			kmeans.FilePath = filePath;
			kmeans.Run();
			
			Console.WriteLine("K-Means clustering completed.");
			Console.WriteLine();
			Console.WriteLine("Clustering output : ");
			Console.WriteLine("----------------------");
			Console.WriteLine(kmeans.GetOutput());
			
			Console.ReadLine();
		}
Esempio n. 2
0
		private void btnRunKMeans1_Click(object sender, EventArgs e)
		{
			string filePath = txtFilePath.Text;
			Dictionary<int, ClusterObject> m_lstData = DataLoader.LoadData(filePath);

			KMeansAlgorithm kmeans = new KMeansAlgorithm();
			kmeans.K = Int32.Parse(txtClusterCount.Text);
			kmeans.FilePath = filePath;
			kmeans.Run();

			using (Graphics g = pnlGraph.CreateGraphics())
			using (CPI.Plot3D.Plotter3D p = new CPI.Plot3D.Plotter3D(g))
			{
				g.Clear(this.BackColor);
				
				foreach (KeyValuePair<int, ClusterObject> kvp in kmeans.ClusteredData)
				{
					p.Location = new CPI.Plot3D.Point3D((int)kvp.Value.Coordinates[0], (int)kvp.Value.Coordinates[1], 0);
					DrawSquare(p, 1, kvp.Value.ClusterId);
				}
			}
		}