How to find knee of curve in python?

  curve, python

I am trying to find a way to find the knee of a curve, given a set of points, and found the python package kneed which seems like the right tool to get the job done. By the "knee" of the curve here, I mean the point in the curve where the slope most drastically shoots up. I am specifically looking for the value on the x-axis where this occurs. Though I am having some trouble interpreting my results, since they don’t appear to be what I would expect.

Here is the kneed documentation I am trying to learn from: https://kneed.readthedocs.io/en/stable/parameters.html

Here is the code I have tried:

x = np.array([30, 60, 90, 120, 150, 180, 210, 240, 270, 300, 330, 360, 390, 420, 450, 480, 510, 540, 570, 600, 630, 660, 690, 720, 750])
y = np.array([1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,15,15,15,16,16,])
kneedle = KneeLocator(x, y, curve="convex", direction="increasing")
kneedle.knee

From this code I am creating data that has x-axis values and y-axis values. Just observing the data, we can see that the biggest "jump" in y values is from 2 to 15, seen at 600 to 630 on the x-axis. As is represented by the data, the curve is convex and the data is increasing. I would imagine that this code would then produce 600 or 630 as the knee. Instead this code produces 750 as the knee, which most certainly is not the knee of the curve.

Where might I be going wrong in producing the correct knee value? I will be using python.

Source: Python Questions

LEAVE A COMMENT