3
$\begingroup$

I have a dataset with 7 labels in the target variable.

X = data.drop('target', axis=1)
Y = data['target']
Y.unique()

array(['Normal_Weight', 'Overweight_Level_I', 'Overweight_Level_II', 'Obesity_Type_I', 'Insufficient_Weight', 'Obesity_Type_II', 'Obesity_Type_III'], dtype=object)

km = KMeans(n_clusters=7, init="k-means++", random_state=300)
km.fit_predict(X)
np.unique(km.labels_)

array([0, 1, 2, 3, 4, 5, 6])

After performing the KMean clustering algorithm with a number of clusters as 7, the resulted clusters are labelled as 0,1,2,3,4,5,6. But how to know which real label matches the predicted label.

In other words, I want to know how to give original label names to new predicted labels, so that they can be compared like how many values are clustered correctly (Accuracy).

$\endgroup$

1 Answer 1

1
$\begingroup$

If you have Target Variables, why would you want to use Unsupervised learning like K means i believe Supervised Multiclass classification would have been a better approach. That being said your question is still valid, so let me try to answer that.

In K means clustering, cluster number does not have any sequence which means you cannot directly map 0,1,2 cluster to the categories. To know which cluster belongs to which category you will have to do a deeper cluster analysis. You will have to look at average characterstic of each cluster and assign them categories accordingly. This can we done by aggregating data at cluster level and calculating averages for various variables

$\endgroup$
3
  • $\begingroup$ +1. For the first point, additionally there's no guarantee that the clusters won't correspond to the expected classes. $\endgroup$
    – Erwan
    Commented Apr 27, 2022 at 13:45
  • $\begingroup$ exactly my point, no gurantee on either it would correspond or not..Clsuter number are random $\endgroup$ Commented Apr 28, 2022 at 11:25
  • $\begingroup$ what if instead of the predefined labels, i only want to assign each group some label after I inspected the centroids' location? E.g.: labels=['top-right', 'bottom-left'] for 2d data etc..? $\endgroup$
    – Ying Zhang
    Commented Oct 20, 2022 at 16:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.