. 1 . 3. Visual Studio 2010 C# ClusteringKMeans; Visual Studio. Solution Explorer Program.cs ClusteringKMeansProgram.cs, , . using .
. 3.
1. using System;
2. namespace ClusteringKMeans
3. {
4. class ClusteringKMeansProgram
5. {
6. static void Main(string [] args)
7. {
Try
9. {
10. Console.WriteLine("\nBegin outlier data detection demo\n");
11. Console.WriteLine("Loading all (height-weight) data into memory");
12. string [] attributes = new string [] { "Height", "Weight" };
13. double [][] rawData = new double [20][];
14. rawData[0] = new double [] { 65.0, 220.0 };
15. rawData[1] = new double [] { 73.0, 160.0 };
16. rawData[2] = new double [] { 59.0, 110.0 };
17. rawData[3] = new double [] { 61.0, 120.0 };
18. rawData[4] = new double [] { 75.0, 150.0 };
19. rawData[5] = new double [] { 67.0, 240.0 };
20. rawData[6] = new double [] { 68.0, 230.0 };
21. rawData[7] = new double [] { 70.0, 220.0 };
22. rawData[8] = new double [] { 62.0, 130.0 };
23. rawData[9] = new double [] { 66.0, 210.0 };
24. rawData[10] = new double [] { 77.0, 190.0 };
25. rawData[11] = new double [] { 75.0, 180.0 };
26. rawData[12] = new double [] { 74.0, 170.0 };
27. rawData[13] = new double [] { 70.0, 210.0 };
28. rawData[14] = new double [] { 61.0, 110.0 };
29. rawData[15] = new double [] { 58.0, 100.0 };
30. rawData[16] = new double [] { 66.0, 230.0 };
31. rawData[17] = new double [] { 59.0, 120.0 };
32. rawData[18] = new double [] { 68.0, 210.0 };
33. rawData[19] = new double [] { 61.0, 130.0 };
34. Console.WriteLine("\nRaw data:\n");
35. ShowMatrix(rawData, rawData.Length, true);
36. int numAttributes = attributes.Length;
37. int numClusters = 3;
38. int maxCount = 30;
39. Console.WriteLine("\nk = " + numClusters + " and maxCount = " + maxCount);
40. int [] clustering = Cluster(rawData, numClusters, numAttributes, maxCount);
41. Console.WriteLine("\nClustering complete");
42. Console.WriteLine("\nClustering in internal format: \n");
43. ShowVector(clustering, true);
44. Console.WriteLine("\nClustered data:");
45. ShowClustering(rawData, numClusters, clustering, true);
46. double [] outlier = Outlier(rawData, clustering, numClusters, 0);
47. Console.WriteLine("Outlier for cluster 0 is:");
48. ShowVector(outlier, true);
49. Console.WriteLine("\nEnd demo\n");
50. }
51. catch (Exception ex)
52. {
53. Console.WriteLine(ex.Message);
54. }
55. } // Main
56. // 14
|
|
57. }
58. }
. . 20, rawData. SQL-. . , , , .
, k- . , , .
ShowMatrix . numAttributes, numClusters maxCount 2 (height weight), 3 30 . , maxCount . k- , maxCount.
Cluster. int, , . , .
, , , Outliers. , ( ) ( ). 0 (67.0, 240.0).