aspose file tools*
The moose likes Java in General and the fly likes Stuck with KMeans Clustering Algorithm Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Stuck with KMeans Clustering Algorithm" Watch "Stuck with KMeans Clustering Algorithm" New topic
Author

Stuck with KMeans Clustering Algorithm

Suzanne Velliere
Greenhorn

Joined: Dec 18, 2011
Posts: 6
Hi, I am supposed to implement the KMeans clustering algo for numerical and textual data. This is what I have done for data that's been read from a binary file. This code uses packages, I want to know a better way to code KMeans without involvong packages. I would also like some help on how to convert textual data to data that can have KMeans applied directly on them. Finding working codes online is a struggle. Right now m at my wits end and I read somewhere that people of this forum have a vast amountof knowledge & background. I think I made a mistake posting here since I don't think KMeans can be considered beginner's Java implementation but any help is readily welcome.


Suzanne Velliere
Greenhorn

Joined: Dec 18, 2011
Posts: 6
Someone PLEASE HELP!!!
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3071
    
  33

Hi, I have moved it to Java In General Forum. I am not sure if this is a better place. But someone would be able to move it to correct forum.

And you need to TellTheDetails.


Mohamed Sanaulla | My Blog
Suzanne Velliere
Greenhorn

Joined: Dec 18, 2011
Posts: 6
Ok that's fine with me. I once again request suggestions on how my code posted above can be improved upon or revamped to make it more elegant. The program compiles correctly, no issues but I want to change it for elegance reasons. Too many people will come up with a similar code so I want to give more clarity to mine. I would be grateful for any suggestions or information on mistakes spotted.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38896
    
  23
All sorts of things you can do to improve the code style:
  • 1: Use Java variable naming conventions: don’t start with capital letters, no _ or $.
  • 2: Use /* * ... * ... */ format for block comments rather than //
  • 3: Many of those comments ought to be documentation comments for the methods.
  • 4: Restrict the lengths of your lines; long lines are very difficult to read.
  • 5: Restrict the lengths of your methods. Long methods should be subdivided if possible.
  • 6: Never use == false or == true.
  • 7: Your indentation is inconsistent.

  • Why have you made everything in that class static?
    Suzanne Velliere
    Greenhorn

    Joined: Dec 18, 2011
    Posts: 6
    @Campbell: I am not referring to the elegance of the code in terms of code style. I am asking how lines within the different functions can be changed to make the code more understandable and efficient. I will take some of your suggestions but what I am looking for is how to make the coding more efficient yet achieve the same purpose. I have used static because I thought in classes, that was the way to do things well.
    dennis deems
    Ranch Hand

    Joined: Mar 12, 2011
    Posts: 808
    Suzanne Velliere wrote:I have used static because I thought in classes, that was the way to do things well.

    Static is for attributes that will be the same for all instances of the class. And it is for methods and attributes that are available from the class without requiring an instance to be present.

    It's difficult to comment on code that is so hard to read. A great many of the variable names are impenetrable clusters of characters. The changeable indenting doesn't help either.
    Campbell Ritchie
    Sheriff

    Joined: Oct 13, 2005
    Posts: 38896
        
      23
    Sort out the stylistic problems first, then you can actually see the other problems!
    Jeff Verdegan
    Bartender

    Joined: Jan 03, 2004
    Posts: 6109
        
        6

    Suzanne Velliere wrote:This code uses packages, I want to know a better way to code KMeans without involvong packages.


    Why? There's no good reason to go out of your way to avoid using packages.
    Suzanne Velliere
    Greenhorn

    Joined: Dec 18, 2011
    Posts: 6
    How to convert the given list in the code to map? I heard map is better to use but I am confused about its implementation here although I do understand a map's put & get methods. I want to know also how to read SVTLM files and store in a map.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Stuck with KMeans Clustering Algorithm