多元多项式回归

时间:2018-09-11 22:45:04

标签: python regression multivariate-testing

我正在尝试对python中的数据进行多元多项式回归。我有4个自变量和1个因变量。我不确定从哪里开始。最近几天,我浏览了许多博客,但并不清楚。大多数博客都是针对单变量数据的。任何人都可以指引我到任何地方的好帖子,它解释了概念并提供了示例代码? 非常感谢您的帮助。

谢谢!

1 个答案:

答案 0 :(得分:0)

scipy在这里https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.curve_fit.html

有一个很好的解决方案
def defa(x, a,b,c,d):
    return a*b*c*d # the form for regresion you want to do
var1, var2 = scipy.optimize.curve_fit(defa,[x cordinates],[y cordinates])
print(var1)
# your a b c and d will ne printed out in order

btw如果您是第一次安装scipy,您应该知道scipy还需要您拥有numpy:)

f.x。

import numpy as np
from scipy.optimize import curve_fit

def defa(x,a,b,c,d,e):
    return a**2+b**3+c**4+d**5+e
print(curve_fit(defa,range(1000),range(1000)))

输出:

(array([9.32720415, 4.0480121, 3.12719445, 2.49008364, 154.80388797]),array([...]))

这意味着

a = 9.32720415
b = 4.0480121
c = 3.12719445
d = 2.49008364
e = 154.80388797