Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Stuck with KMeans Clustering Algorithm

 
Suzanne Velliere
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Someone PLEASE HELP!!!
 
Mohamed Sanaulla
Saloon Keeper
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Suzanne Velliere
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49733
69
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
    Posts: 6
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    @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
    Posts: 808
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Pie
    Posts: 49733
    69
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Sort out the stylistic problems first, then you can actually see the other problems!
     
    Jeff Verdegan
    Bartender
    Posts: 6109
    6
    Android IntelliJ IDE Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 6
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic