首页 > 解决方案 > 如何放大python中的肘部图?

问题描述

我正在尝试使用技术计算每个点与其 k 最近邻居之间的平均距离并生成 k 距离肘部图,但我不知道如何在图上应用放大以清楚地看到肘部,像这样: 在此处输入图像描述并 在此处输入图像描述

这是我的代码

neighbors = NearestNeighbors(n_neighbors=6)
neighbors_fit = neighbors.fit(data_scale)
distances, indices = neighbors_fit.kneighbors(data_scale)
print(distances)
distances = np.sort(distances, axis=0)
distances = distances[:,1]
plt.plot(distances)
plt.xlabel('Distance')
plt.ylabel('eps')
plt.title('Elbow Method For Optimal eps')
plt.show()

你能帮助我吗?

标签: pythonmatplotlibplotnearest-neighboreuclidean-distance

解决方案


要放大,您可以通过plt.xlim()plt.ylim()

例如

plt.xlim([5000, 6000])
plt.ylim([0, 400])

推荐阅读