🛠️ Scheduled Maintenance | We’ll be undergoing scheduled maintenance and upgrades between 00:00 PST Jan 26th until 00:00 PST Jan 28th. There may be brief interruption of services in that period. We apologize for the inconvenience.

The 365 Data Science team is proud to invite you to our own community forum. A very well built system to support your queries, questions and give the chance to show your knowledge and help others in their path of becoming Data Science specialists.
Anybody can ask a question
Anybody can answer
The best answers are voted up and moderated by our team

KMeans label attribute

KMeans label attribute


How to fix that thing? I was trying to follow the video. Thank you so much.



df_segm_pca_kmeans = pd.concat([df_segmentation.reset_index(drop = True), pd.DataFrame(scores_pca)], axis = 1)
df_segm_pca_kmeans.columns.values[-3: ] = ["Component 1", "Component 2", "Component 3"]
df_segm_pca_kmeans["Segment K-means PCA"] = kmeans_pca.labels_




AttributeError                            Traceback (most recent call last)
<ipython-input-52-a697fdea9e43> in <module>
      1 df_segm_pca_kmeans = pd.concat([df_segmentation.reset_index(drop = True), pd.DataFrame(scores_pca)], axis = 1)
      2 df_segm_pca_kmeans.columns.values[-3: ] = ["Component 1", "Component 2", "Component 3"]
----> 3 df_segm_pca_kmeans["Segment K-means PCA"] = kmeans_pca.labels_
      4 df_segm_pca_kmeans

AttributeError: 'KMeans' object has no attribute 'labels_'
1 Answer

365 Team

Hi Liqian, 
You need to fit your kmeans_pca first, for it to have the labels_ attribute.
So, you should make sure you run this line:
before you create the df_segm_pca_kmeans table.
Hope this helps!

lol I kinda did, but I forgot to change it to kmeans_pca. Thanks.

10 months

No worries, glad it’s working! (:

10 months