python三维曲面拟合_用Python拟合多项式曲面

现在,两年后,我可以解决这个问题:

这是一个具有多项式特征的经典回归问题,其中输入变量排列在网格中。在下面的代码中,我手动计算了我需要的多项式特征,分别是这些特征,它们将解释我的目标变量。在import pandas as pd

import numpy as np

from sklearn.linear_model import LinearRegression

import matplotlib.pyplot as plt

from mpl_toolkits.mplot3d import Axes3D

# create random data, which will be the target values

Z = np.random.rand(7,7) * 100

# create a 2D-mesh

x = np.arange(1,8).reshape(7,1)

y = np.arange(1,8).reshape(1,7)

X,Y = np.meshgrid(x,y)

# calculate polynomial features based on the input mesh

features = {}

features['x^0*y^0'] = np.matmul(x**0,y**0).flatten()

features['x*y'] = np.matmul(x,y).flatten()

features['x*y^2'] = np.matmul(x,y**2).flatten()

features['x^2*y^0'] = np.matmul(x**2, y**0).flatten()

features['x^2*y

你可能感兴趣的:(python三维曲面拟合)