Click here to Skip to main content
15,893,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using Accord.MachineLearning;
using Accord.Imaging;
using Accord.Math;
using Accord.Statistics;
using System.Windows.Forms;
using System.IO;

namespace DriverApp
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
         KMeans kmeans = new KMeans(3);
          String line;
            try
            {
                //Pass the file path and file name to the StreamReader constructor
                StreamReader sr = new StreamReader(@"D:\input.txt");

                //Read the first line of text
                line = sr.ReadLine();

                //Continue to read until you reach end of file
                while (line != null)
                {
                    //write the lie to console window
                     
                     int[] medoid =kmeans.Compute(line); // here i am getting error
                   
                    //Read the next line
                    line = sr.ReadLine();
                }

                //close the file
                sr.Close();
                Console.ReadLine();
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception: " + e.Message);
            }
            finally
            {
                Console.WriteLine("Executing finally block.");
            }

        
           
   
           // 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();


        }
    }
}

This is the code I am trying to impliment,
Actually I am trying to read values from file and transfer it to k means algorithm, but it oly takes double value,how should I convert string value taken from file to double value required by k means
error i am getting is double[][] had some invalid arguments
please help me out this prob
Posted
Updated 28-Dec-11 0:25am
v2
Comments
Wendelius 28-Dec-11 6:26am    
Pre tags added

1 solution

Can you use Double.TryParse[^]
 
Share this answer
 
Comments
Member 11394686 26-Feb-15 21:04pm    
how can i cluster the text in the textbox using class kmeans

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900