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()

结果如下:

发布了27 篇原创文章 · 获赞 3 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/robot_learner/article/details/104294156