Fit plane to a set of points in 3D: scipy.optimize.minimize vs scipy.linalg.lstsq
<p>Given a set of points in 3D, the general problem is to find the <code>a, b, c</code> coefficients of a plane equation in the form:</p>

<pre><code>z = a*x + b*y + c
</code></pre>

<p>such that the resulting plane is the <em>best fit</em> possible to that set of points.</p>

<ol>
<li><p>In <a href="https://stackoverflow.com/a/20700063/1391441">this SO answer</a>, the function <a href="http://docs.scipy.org/doc/scipy-0.16.1/reference/generated/scipy.optimize.minimize.html" rel="noreferrer">scipy.optimize.minimize</a> is used to solve this problem.</p>

<p>It relies on initial guesses for the coefficients, and minimizes an error function that sums the distances of each point to the surface of the plane.</p></li>
<li><p>In <a href="https://gist.github.com/amroamroamro/1db8d69b4b65e8bc66a6" rel="noreferrer">this code</a> (based on <a href="https://stackoverflow.com/a/18648210/97160">this other SO answer</a>) the <a href="http://docs.scipy.org/doc/scipy-0.16.1/reference/generated/scipy.linalg.lstsq.html" rel="noreferrer">scipy.linalg.lstsq</a> function is used to tackle the same problem (when restricted to a 1st order polynomial).</p>

<p>It solves for <code>C</code> in the equation <code>z = A*C</code>, where <code>A</code> is the concatenation of the <code>x,y</code> coordinates of the set of points, <code>z</code> is the <code>z</code> coordinate of the set, and <code>C</code> are the <code>a,b,c</code> coefficients.</p>

<p>Unlike the code in the method above, this one does not seem to require initial guesses for the plane coefficients.</p></li>
</ol>

<p>Since the  <code>minimize</code> function requires an initial guess, this means that it may or may not converge to the optimal solution (depending on how good the guess is). Does the second method have a similar caveat or will it return an always exact solution?</p>