python 中的 statsmodels 包用来做线性回归分析,最小二乘法

更多专业的人工智能相关文章,微信搜索  : robot-learner , 或扫码

 

multi variable linear regression,

考虑的模型如下:

y= ax1 + bx2+cx3

其中a,b,c为参数, x1,x2,x3为三个变量。

 

python code 如下:

 

 

import statsmodels.api as sm

X=[[544.0, 27.0, 0.0],
 [786.0, 17.0, 27.0],
 [1246.0, -3.0, 44.0],
 [1934.0, 0.0, 41.0],
 [2703.0, 0.0, 41.0],
 [4472.0, 2.0, 41.0],
 [5933.0, -2.0, 43.0],
 [7670.0, 0.0, 41.0],
 [9651.0, 0.0, 41.0],
 [11733.0, 17.0, 41.0],
 [14244.0, 78.0, 58.0],
 [17007.0, 62.0, 136.0],
 [20147.0, 93.0, 198.0],
 [23884.0, 149.0, 291.0],
 [27447.0, 131.0, 440.0],
 [30331.0, 259.0, 571.0],
 [33259.0, 457.0, 830.0],
 [35223.0, 688.0, 1287.0],
 [37427.0, 769.0, 1975.0],
 [38123.0, 1771.0, 2744.0]]

Y=[34.0,
 38.0,
 49.0,
 51.0,
 60.0,
 103.0,
 124.0,
 171.0,
 243.0,
 328.0,
 475.0,
 632.0,
 892.0,
 1153.0,
 1540.0,
 2050.0,
 2649.0,
 3281.0,
 3996.0,
 4740.0]

# fit the data with OLS model
model = sm.OLS(Y, X).fit()
predictions = model.predict(X) # make the predictions by the model

# Print out the statistics
model.summary()

 

结果如下:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值