【问题标题】:How do I zoom in on the elbow plot in python?如何放大python中的肘部图?
【发布时间】:2023-11-29 08:02:02
【问题描述】:

我正在尝试使用计算每个点与其 k 个最近邻居之间的平均距离并生成 k 距离肘部图的技术来查找 eps 值,但我不知道如何在图上应用放大以查看肘部清晰,像这样: enter image description hereenter image description here

这是我的代码

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()

你能帮帮我吗?

【问题讨论】:

    标签: python matplotlib plot nearest-neighbor euclidean-distance


    【解决方案1】:

    要放大,您可以通过plt.xlim()plt.ylim() 更改坐标轴范围

    例如

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

    【讨论】:

      最近更新 更多