从黄砖KElbowVisualizer中提取k

问题描述 投票:0回答:1

我正在尝试从黄砖 KElbowVisualizer 可视化工具中提取 k 的值以进行进一步处理。我可以在可视化中看到 k 值,但我似乎无法提取它并将其放入变量中。

python k-means yellowbrick
1个回答
3
投票
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
© www.soinside.com 2019 - 2024. All rights reserved.