I need help performing polynomial features on 3 dimensional data and performing linear regression to create a line of best fit on the 3 dimensional polynomial.
I have a random dataframe with x, y, and z as the columns that forms a polynomial scatterplot. X and Y are similar values while z is vastly different. Example:
X=(-3,9,-20,-8,-14)
Y=(-2,8,-19,-8,-13)
Z=(-960,110,4867,-149,1493)
I have done this for 2 dimensional data but not 3d.
poly=PolynomialFeatures(degree=2,include_bias=False)
X_poly=poly.fit_transform(X.reshape(-1,1))
X_poly[0]
However, how do I handle the data when I have x, y, and z? Do I need to perform poly.fit_transform x and y?
Next I did linear regression
from sklearn.linear_model import LinearRegression
LinReg = LinearRegression()
LinReg.fit(X_poly,z)
Then when I create test data for x and y and perform the predict method on z, the resulting line is linear instead of a polynomial.
Any help would be much appreciated.