I am trying to extract the value of k from Yellow brick KElbowVisualizer visualizer for further processing. I can see the k value on the visualization, but I cannot seem to extract it and put in a variable.
Asked
Active
Viewed 2,003 times
4
-
1Hi, Can you share your code that you tried, and expected output? – Peacepieceonepiece Oct 09 '21 at 07:52
1 Answers
2
from sklearn.cluster import KMeans
from sklearn.datasets import make_blobs
from yellowbrick.cluster import KElbowVisualizer
# Generate synthetic dataset with 8 random clusters
X, y = make_blobs(n_samples=1000, n_features=12, centers=8, random_state=42)
# Instantiate the clustering model and visualizer
model = KMeans()
visualizer = KElbowVisualizer(model, k=(4,12))
visualizer.fit(X) # Fit the data to the visualizer
visualizer.show() # Finalize and render the figure
visualizer.elbow_value_ # Get elbow value

larrywgray
- 993
- 1
- 7
- 14