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.
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.
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?
Joined: Dec 18, 2011
@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.
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.
Joined: Dec 18, 2011
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.