Reputation: 31
My problem is, that I have about 50.000 non-linear data points (x,y,z) with z depending on the independent variables x and y. From one side, so from a two-dimensional perspective, the data points look like a polynomial of degree 7. Unfortunately I cannot show this data.
My goal is to find a polynomial in 3D that can fit this data, without knowing the degree of the polynom beforehand. So I would like a function like f(x,y) = ax^3 + bx^2 + cx^2y + dy^3 + ...
Unfortunately, in python I have only found something like surface-fitting, where you need the degree beforehand. Or something like transforming the polynomial problem into a mutlivariable linear problem with scikit-learn. The later had very poor results with my dataset.
Does anyone know of a better method for this problem? Many thanks in advance.
Upvotes: 1
Views: 1235
Reputation: 2174
As far as fitting a polynomial to a surface, I think your best bet is to try different sets of polynomials and rank them based on fit, as described here.
If you are willing to try different surface fitting methods, I would recommend looking into what scipy has to offer, particularly in the Multivariate, unstructured data section. scipy.interpolate.griddata
, for example, uses a cubic spline to interpolate between data points. See below code for a demo:
import numpy as np
from scipy.interpolate import griddata
# X and Y features are a 2D numpy array
xy = np.random.randn(20,2)
# z is nonlinear function of x and y
z = xy[:,0] + xy[:,1]**2
# make grid of x and y points to interpolate
xsurf = np.arange(-3,3,0.1)
ysurf = xsurf
xsurf, ysurf = np.meshgrid(xsurf,ysurf)
surfPts = griddata(xy,z, np.vstack((xsurf.flatten(),ysurf.flatten())).T)
that code will yield the following surface fit:
Upvotes: 2