0

I am working on Kmeans clustering algorithm. When I try to access the cluster labels it is showing:

numpy.ndarray object has no attribute labels_

My code is as follows:

movies=np.array(movies)
kmeans=KMeans(n_clusters=19).fit_predict(movies)
print(kmeans.labels_)
1
  • Use print dir(kmeans) to get a list of all the attributes available in the kmeans object Commented Oct 21, 2017 at 6:57

1 Answer 1

3

kmeans isn't a KMeans object as constructed. fit_predict returns an array (which is equivalent to labels_ of the object). You want something like:

movies=np.array(movies)
kmeans=KMeans(n_clusters=19)
kmeans.fit(movies)
print(kmeans.labels_)

Or even just print(kmeans) instead of print(kmeans.labels_) in your original code.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.