Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong clustering with pre_computed adjacency matrix #35

Closed
mosikh opened this issue Sep 16, 2022 · 3 comments
Closed

Wrong clustering with pre_computed adjacency matrix #35

mosikh opened this issue Sep 16, 2022 · 3 comments

Comments

@mosikh
Copy link

mosikh commented Sep 16, 2022

Hello,
I used k-means-constrained library to cluster some points with a precomputed adjacency matrix. But I faced a wrong clustering.
The project and further explanations are available in this link.

https://github.com/mosikh/k-means-constrained

I appreciate any help to improve the result.

Best regards,
Mostafa

@joshlk
Copy link
Owner

joshlk commented Sep 16, 2022

Hi Mostafa,

Thank you for the example. I wouldn’t consider the provided example a minimum workable example. Stackoverflow have a good article on how to produce this. Importantly the example should contain the least amount of code and data to reproduce the result you want to present. Ideally you should be able to paste it as few lines of code and include only a few datapoints of data within a GitHub comment.

I also don’t understand the problem? Why is the desired output not what you expected and why should the algorithm not give this output?

I know the above is more difficult to produce but it really helps me understand the issue. Otherwise it’s very hard for me to debug it 🙂

Thanks,
Josh

@mosikh
Copy link
Author

mosikh commented Sep 17, 2022

Hi Josh,
Thanks a lot for your answer.

You are right. My codes were long.
Now, I changed the code in the repository and now we have 5 lines of cods and a CSV which is the adjacency matrix.
You need just the python code (5 lines) and also the input CSV file to debug.
Please check the repository once again.

As I explained in the readme file, the ESRI Shapefiles are there just in case that somebody needs to visualize. But they are not necessary to debug. So, you can skip them.

About your question:
I have uploaded two pictures: clustering_output.jpeg which is the result of the algorithm and library. The other picture whose name is desired_output.jpeg is my favorite mood of clustering, but the algorithm doesn't provide such a result.
And I really don't know what is the problem that the library makes mistake. I hope you can help me improve the result and the repository is ready to debug and sorry for the inconvenience.

Thanks,
Mostafa

@mosikh
Copy link
Author

mosikh commented Jun 1, 2023

Hi Josh,
I think K-Means clustering generally is not the best method to cluster based on pre-computed matrix. It shows some inaccuracies even in the normal cases without constraint and without maximum cluster size limitation.

I believe AgglomerativeClustering is the best method to cluster based on pre-computed matrices. So, it is worth to try constraint methods on this clustering approach. I think the result will be much better than K-means.

Best regards,
Mostafa

@joshlk joshlk closed this as completed Jun 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants