小编Kyr*_*far的帖子

如何在线性回归中强制零拦截?

如果这个问题已经得到解答,我有点道歉,我已经看了一眼,找不到我想要的具体内容.

我有一些或多或少的线性数据形式

x = [0.1, 0.2, 0.4, 0.6, 0.8, 1.0, 2.0, 4.0, 6.0, 8.0, 10.0, 20.0, 40.0, 60.0, 80.0]
y = [0.50505332505407008, 1.1207373784533172, 2.1981844719020001, 3.1746209003398689, 4.2905482471260044, 6.2816226678076958, 11.073788414382639, 23.248479770546009, 32.120462301367183, 44.036117671229206, 54.009003143831116, 102.7077685684846, 185.72880217806673, 256.12183145545811, 301.97120103079675]
Run Code Online (Sandbox Code Playgroud)

scipy.optimize.leastsq用来拟合线性回归:

def lin_fit(x, y):
    '''Fits a linear fit of the form mx+b to the data'''
    fitfunc = lambda params, x: params[0] * x + params[1]    #create fitting function of form mx+b
    errfunc = lambda p, x, y: fitfunc(p, x) - y              #create …
Run Code Online (Sandbox Code Playgroud)

python numpy scipy linear-regression

18
推荐指数
3
解决办法
3万
查看次数

标签 统计

linear-regression ×1

numpy ×1

python ×1

scipy ×1