如何比较两组不同长度的 xy 坐标?



我想比较两组不同的x-y坐标。集合的大小不同,但我想计算两者之间的某种相似性指数。

例:

Set1 = [(1,2), (3,6), (7,8)] 
Set2 = [(2,2), (3,5)]

我正在寻找的指标/算法的目标是评估预测算法在查找相对于已知地面真实值点集的点方面的"准确性"。

我尝试过取地面真值点相对于最近预测点的最小距离,但作为指标,无法量化/惩罚过度预测的错误。

我要比较的两个数据集的示例散点图

  1. 使用您选择的内核估计地面实况和预测数据集的密度。选择哪个内核取决于域;盒子内核或 RBF 可能是一个合理的选择。
  2. 计算这些密度之间的背离。背离的概念再次取决于你,平均平方距离或KL背离可能有效。

使用盒核和均方实现:

from scipy.signal import convolve2d
# constants: don't forget to replace with your own values
x_width, y_width = 10, 10
kernel_width = 3
gt_field = np.zeros((x_width, y_width))
prediction_field = gt_field.copy()
# split Set1 into two lists of x and y coordinates
# then set these points to 1
gt_field[list(zip(*Set1))] = 1
prediction_field[list(zip(*Set2))] = 1
# using box kernel as the simplest one
kernel = np.ones((kernel_width, kernel_width)) / kernel_width ** 2
# apply kernel - now we have densities
gt_field = convolve2d(gt_field, kernel)
prediction_field = convolve2d(prediction_field, kernel)
# calculate mean squared error
mse = ((gt_field - prediction_field) ** 2).mean()

我很确定有一种更有效的方法来实现它,但即使这样也应该像示例图片一样适用于几百点。

最新更新