Is there a Python function or methodology for locating the first elbow of a plot?

Viewed 81

I have a situation where I need to find the first x-value for which an "elbow" (or backwards "L") in the data occurs. For example, I have drawn an arrow on a plot to show what I mean:

enter image description here

What's the fastest way to find this in Python? Is there a function for this?

1 Answers

You can calculate the 1st derivative of your data with the numpu function gradient, for example.

Let's assume that your data is stored in the variable numpy variable 'x', so the 1st derivative is calculated with np.gradient(x). Basically the derivative calculate the rate of change of your function.

With this you can specify a tolerance for the derivative, as the function grows a lot you can check where the gradient is greater than the tolerance (some big number).

Ps: to really understand it you have to know a little about calculus, so I encourage you to search something about the derivative of a function.

Related