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_
df_segm_pca_kmeans
--------------------------------------------------------------------------- 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 answers ( 0 marked as helpful)
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:
kmeans_pca.fit(scores_pca)
before you create the df_segm_pca_kmeans table.
Hope this helps!
Best,
Eli