question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

'KMeans' object has no attribute 'k'

See original GitHub issue

When trying to run example:

from yellowbrick.cluster import KElbowVisualizer
from sklearn.cluster import KMeans
model = KElbowVisualizer(KMeans(), k=10)
model.fit(X)

The following error appears:

AttributeError: 'KMeans' object has no attribute 'k'

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:15 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
nipnipjcommented, Aug 23, 2022

This example worked for me now:

from sklearn.cluster import KMeans
from sklearn.datasets import make_blobs
from yellowbrick.cluster import KElbowVisualizer

X, y = make_blobs(n_samples=1000, n_features=12, centers=8, random_state=42)

model = KMeans()
visualizer = KElbowVisualizer(model, k=(4,12))

visualizer.fit(X)
visualizer.show()
0reactions
shayandavoodiicommented, Aug 23, 2022

@nipnipj @shayandavoodii glad to hear the v1.5 update fixed things!

@shayandavoodii Jupyter notebooks will automatically render figures that were created in the cell above; that’s why both the estimator description figure and the partial K-Elbow figure are visible. Some advice on how to prevent this can be found in this StackOverflow post. Note that without the call to show the Yellowbrick figure doesn’t have a title, axes names, legend etc. If you want to render these without calling show you can call finalize instead.

Thanks. Yes, I was aware of them. Actually, I don’t need the plot. Thanks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

AttributeError: 'KMeans' object has no attribute 'k'
Based on this, yellowbrick got updated to v1.5 , and the problem with AttributeError: 'KMeans' object has no attribute 'k' got solved.
Read more >
[FIXED] 'KMeans' object has no attribute 'k' - PythonFixing
I am using the Yellowbrick package to plot an elbow curve for a dataset to find the most optimal number of clusters for...
Read more >
AttributeError: 'KMeans' object has no attribute '_n_threads'
i have saved my kmeans clustering model using pickle and when i try to predict clusters on new data after loading it throws...
Read more >
'KMeans' object has no attribute 'labels_' with pytorch ... - GitHub
first of all I thank , I tried to train model with pytorch but I got the following error: AttributeError: 'KMeans' object has...
Read more >
AttributeError: 'KMeans' object has no attribute '_n_threads'
Hello, I created a KMeans model on some dataset, pickled it and then loaded it in the Streamlit app that I made.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found