What is the mathematical definition of the 'Elbow Method'? In K-means algorithm, it is recommender to pick the optimal K, according to the Elbow Method. However all the tutorials explain the elbow method in these 4 steps:


*

*Run K-means for a range of K's

*Calculate the Sum of Squares of the distances from the cluster mean

*Plot a curve of the SSD over K's

*Visually pick the K at the elbow


Can I code it as an algorithm? What is the mathematical definition of the elbow?
For example - Where is the elbow of the following curve? and Why?

 A: Elbow method is a heuristic. There's no "mathematical" definition and you cannot create algorithm for it, because the point of the method is about visually finding the "breaking point" on the plot. This is subjective criteria and it often happens that different people could end up with different conclusions given same plots.
A: It is possible to make a mathematical model for the elbow point, at least if you have a smooth decreasing curve. In fact, here are three definitions of the elbow point, where we draw a line segment $A$ that connects the endpoints of the curve:
(1) Find the tangent line to the curve that is parallel to the line segment  $A.$ Define the elbow point as the point where the tangent line intersects the curve.
(2) Find the point on the curve that has the greatest vertical distance to the line segment $A.$ Define the point as the elbow point.
(3) Find the point on the curve that has the greatest perpendicular distance to $A.$ Define this point as the elbow point.
Interestingly, under some surprisingly general conditions these definitions will all determine the same point.
Update: I eyeballed the OP's data and fit a power curve of the form $y=ax^{-b},$ which gives a great fit $(R^2 > 0.99)$. Using method (1) as described above, the elbow point is around 7.7 (so the user would likely select $k=8.$ Here is a visual: 
I also fit a logarithmic curve, (not shown here, but again $R^2 > 0.99$), which gave an elbow point of 7.99, in good agreement with the first fit.
