from sklearn import datasets
from sklearn.cluster import KMeans
from yellowbrick.cluster import KElbowVisualizer
# Load the IRIS dataset
iris = datasets.load_iris()
X = iris.data
y = iris.target
# Instantiate the clustering model and visualizer
km = KMeans(random_state=42)
visualizer = KElbowVisualizer(km, k=(2,10))
visualizer.fit(X) # Fit the data to the visualizer
visualizer.show() # Finalize and render the figure
elbow_value = visualizer.elbow_value
1条答案
按热度按时间dpiehjr41#
使用
yellowbrick
库进行肘关节可视化。或者,您可以计算每个失真分数之间的导数,并在导数的变化小于阈值变量时返回手肘值。有关详细信息,请查看此文档。