Click here to Skip to main content
15,886,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm applying kmedoid method to cluster group of points stored in a text file as x and y. The code I'm using results only a file of clusters to which the points belong, something like this:

2
2
4
5
2
2
.
.
2
1
3

but I want to get the points coordinates together with its cluster number like this:
1.056 2.0546 2
1.128 2.1546 3
.
.
How to get this?

What I have tried:

This is the code I'm using:
from sklearn_extra.cluster import KMedoids
import numpy as np
point_cloud = np.genfromtxt('D:/Point cloud data/Data mabna 4/Downsampled/Roof_only/New Microsoft Excel Worksheet.txt')
kmedoids = KMedoids(n_clusters=7, random_state=0).fit(point_cloud)
kmedoids.labels_
with open("D:/Point cloud data/Data mabna 4/Downsampled/Roof_only/Microsoft Excel Worksheet.txt", 'w') as f:
    for i in range(len(kmedoids.labels_)):
        f.write("{}\n".format(str(kmedoids.labels_[i])))
Posted
Updated 11-Jun-22 8:23am
v3

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