The equation for determining the print surface in python

I am trying to map a surface model to a 3D dataset (x, y, z) using matplotlib.
Where z = f(x,y).
So I'm going for a quadratic fitting with the equation:

f(x,y) = ax^2+by^2+cxy+dx+ey+f 

So far, I have successfully built a 3D surface using the least squares method using:

# best-fit quadratic curve    
   A = np.c_[np.ones(data.shape[0]), data[:,:2], np.prod(data[:,:2], axis=1), data[:,:2]**2]    
   C,_,_,_ = scipy.linalg.lstsq(A, data[:,2])    
   #evaluating on grid      
   Z = np.dot(np.c_[np.ones(XX.shape), XX, YY, XX*YY, XX**2, YY**2], C).reshape(X.shape)

But, how can I print / get the set surface equation (with coefficients)?

It will be of little use to me very much. thank.

+4
source share
1 answer

scipy.linalg.lstsq http://docs.scipy.org/doc/scipy-0.15.1/reference/generated/scipy.linalg.lstsq.html C ( , A).

, 2 :

print 'f(x,y) = {:.2f}x^2+{:.2f}y^2+{:.2f}xy+{:.2f}x+{:.2f}y+{:.2f}'.format(C[4],C[5],C[3],C[1],‌​C[2],C[0])

print 'f(x,y) = {4:.2f}x^2+{5:.2f}y^2+{3:.2f}xy+{1:.2f}x+{2:.2f}y+{0:.2f}'.format(*C)

, pandas statsmodels (, check OLS Pandas Data Frame)

+3

All Articles