是否有多元插值的Python库?现在我有三个自变量和一个因变量。我的数据看起来像这样:
X1=[3,3,3.1,3.1,4.2,5.2,6.3,2.3,7.4,8.4,5.4,3.4,3.4,3.4,...]
X2=[12.1,12.7,18.5,18.3,18.4,18.6,24.2,24.4,24.3,24.5,30.9,30.7,30.3,30.4,6.1,6.2,...]
X3=[0.3,9.2,0.3,9.4,0.1,9.8,0.4,9.3,0.7,9.7,18.3,27.4,0.6,9.44,...]
Y=[-5.890,-5.894,2.888,-3.8706,2.1516,-2.7334,1.4723,-2.1049,0.9167,-1.7281,-2.091,-6.7394,0.8777,-1.7046,...]
and len(X1)=len(X2)=len(X3)=len(Y)=400
我想拟合或插值数据,以便给定任意x1, x2, x3
值,函数f(x1,x2,x3)
将产生估计的y
值。就像给定x1=4.11, x2=10.34, and x3=10.78,
,函数将产生-8.7567(best estimate).
,我想象函数将是多项式。所以样条插值可能是最好的选择?
2条答案
按热度按时间r1zk6ea11#
scipy.optimize workd.在这个代码中,估计是线性函数,但它可能是更好的一个。
然后用
fitParams[0] + fitParams[1] * x1 + fitParams[2] * x2 + fitParams[3] * x3
估计y。将结果与原始y进行比较。
参考scipy、stackoverflow-multifit、stackoverflow-plot xy
xjreopfe2#
通常,您可以使用PolynomialFeatures
PolynomialFeature,deg=1 [<$'1' 0.0]<$'x 0' 1.44528075]<$'x1' -1.95544098]<$'x2' 3.02024807]] RMSE为:0.956660546736911
请注意,如果需要,可以通过从X_ array中删除某些元素来删除它们。(例如,如果你不想拟合x²的原因.)这将不会使用样条,但它是解决你心目中的那种多项式的最佳线性回归解决方案。