返回首页

在我的代码,我通过双维数组值观察到k均值算法,但我的问题,我想它的动态,而如果已经初始化的值。

我如何才能让代码从键盘输入和存储在多维数组,然后把它传递到k手段功能。

 static class Program 

      {

        /// <summary>

        /// The main entry point for the application.

        /// </summary>

        [STAThread]

        static void Main()

        {

          

          

           

     double[][] observations =

            {

                 new double[] {  1,  2,  3 },

                 new double[] {  1,  3,  2 },

                 new double[] {  2,  1,  3 },

                 new double[] {  2,  3,  1 },

                 new double[] {  3,  1,  2 },

                 new double[] {  3,  2,  1 },

                 new double[] {  2,  1,  3 },

                 new double[] {  2,  1,  3 },

                 new double[] {  2,  1,  3 },

                 new double[] {  2,  1,  3 },

                 new double[] {  3,  2,  1 },

                 new double[] {  3,  2,  1 },

               //new double[] {  100,  100,  100 },

              // new double[] {  120,  120,  120 },

              // new double[] {  200,  200,  200 },

               //new double[] {  201,  202,  203 },

               //new double[] {   500,  500,  500 },

               //new double[] {  12,  13,  11 },

               //new double[] {  15,  12,  11 },

            };

         

            // Create a new K-Means algorithm with 3 clusters 

            KMeans kmeans = new KMeans(3);

 

            // Compute the algorithm, retrieving an integer array

            //  containing the labels for each of the observations

            int[] medoid = kmeans.Compute(observations);

            

            

           

            // As a result, the first two observations should belong to the

            //  same cluster (thus having the same label). The same should

            //  happen to the next four observations and to the last three.



            Console.Write("The most efficient prediction via K-Means is : ");

            for (int counter = 0; counter < medoid.Length; counter++)

            {

               Console.Write(medoid[counter] + " ");

            }

            Console.WriteLine();

            Console.WriteLine();

            Console.WriteLine();

 

            

        }

    }

}

回答

评论会员: 时间:2
O