0
$\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$
2
  • $\begingroup$ +1. For the first point, additionally there's no guarantee that the clusters won't correspond to the expected classes. $\endgroup$
    – Erwan
    Apr 27 at 13:45
  • $\begingroup$ exactly my point, no gurantee on either it would correspond or not..Clsuter number are random $\endgroup$ Apr 28 at 11:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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