如何在python中绘制k距离图 [英] how to plot a k-distance graph in python

查看:118
本文介绍了如何在python中绘制k距离图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在DBSCAN中绘制给定的最小点值的距离图(在python中)?

How do I plot (in python) the distance graph for a given value of min-points in DBSCAN???

我正在寻找膝盖和相应的epsilon值.

I am looking for the knee and corresponding epsilon value.

在sklearn中,我看不到任何返回此距离的方法....我缺少什么吗?

In the sklearn I do not see any method that return such distances.... Am I missing something?

推荐答案

您可能希望使用numpy提供的矩阵运算来加快距离矩阵的计算速度.

You probably want to use the matrix operations provided by numpy to speed up your distance matrix calculation.

def k_distances2(x, k):
    dim0 = x.shape[0]
    dim1 = x.shape[1]
    p=-2*x.dot(x.T)+np.sum(x**2, axis=1).T+ np.repeat(np.sum(x**2, axis=1),dim0,axis=0).reshape(dim0,dim0)
    p = np.sqrt(p)
    p.sort(axis=1)
    p=p[:,:k]
    pm= p.flatten()
    pm= np.sort(pm)
    return p, pm
m, m2= k_distances2(X, 2)
plt.plot(m2)
plt.ylabel("k-distances")
plt.grid(True)
plt.show()

这篇关于如何在python中绘制k距离图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆