我知道在这个主题上this,和{a2}的存在。不过,这次我想用Python完成一个实际的实现。在
我唯一的问题是肘点似乎从我代码的不同实例化发生了变化。观察这篇文章中显示的两个图。虽然它们看起来在视觉上相似,但肘部点的值发生了显著变化。这两条曲线都是从平均20次不同的运行中生成的。即使这样,肘部点的值也有显著的变化。我可以采取什么预防措施来确保值落在某个范围内?在
我的尝试如下:def elbowPoint(points):
secondDerivative = collections.defaultdict(lambda:0)
for i in range(1, len(points) - 1):
secondDerivative[i] = points[i+1] + points[i-1] - 2*points[i]
max_index = secondDerivative.values().index(max(secondDerivative.values()))
elbow_point = max_index + 1
return elbow_point
points = [0.80881476685027154, 0.79457906121371058, 0.78071124401504677, 0.77110686192601441, 0.76062373158581287, 0.75174963969985187, 0.74356408965979193, 0.73577573557299236, 0.72782434749305047, 0.71952590556748364, 0.71417942487824781, 0.7076502559300516, 0.70089375208028415, 0.69393584640497064, 0.68550490458450741, 0.68494440529025913, 0.67920157634796108, 0.67280267176628761]
max_point = elbowPoint(points)