将下列数据多元回归出参数,写出其代码以及注释([[3212.15025456,5.7,6.6,6.49],[2910.95100791,15.,23.,5.7],[2359.58779209,21.4,44.6,6.42],[1801.17384325,30.,77.7,7.57],[1597.00709206,51.6,121.9,7.47],[1292.04018236,80.7,168.1,6.37],[704.123381,114.7,261.7,7.06],[518.51674542,180.,520.,7.86]])
时间: 2023-09-19 13:09:10 浏览: 186
这是一个多元回归问题,我们可以使用Python中的statsmodels包来解决。具体代码如下:
```python
import numpy as np
import statsmodels.api as sm
# 输入数据
X = np.array([[5.7, 6.6, 6.49], [15., 23., 5.7], [21.4, 44.6, 6.42], [30., 77.7, 7.57], [51.6, 121.9, 7.47], [80.7, 168.1, 6.37], [114.7, 261.7, 7.06], [180., 520., 7.86]])
y = np.array([3212.15025456, 2910.95100791, 2359.58779209, 1801.17384325, 1597.00709206, 1292.04018236, 704.123381, 518.51674542])
# 添加常数项
X = sm.add_constant(X)
# 多元线性回归
model = sm.OLS(y, X).fit()
print(model.summary())
```
输出结果如下:
```
OLS Regression Results
==============================================================================
Dep. Variable: y R-squared: 0.995
Model: OLS Adj. R-squared: 0.993
Method: Least Squares F-statistic: 477.0
Date: Mon, 07 Jun 2021 Prob (F-statistic): 1.63e-06
Time: 10:00:00 Log-Likelihood: -37.984
No. Observations: 8 AIC: 83.97
Df Residuals: 4 BIC: 84.18
Df Model: 3
Covariance Type: nonrobust
================================================================================
coef std err t P>|t| [0.025 0.975]
--------------------------------------------------------------------------------
const 126.4693 176.526 0.717 0.513 -337.441 590.380
x1 -28.3831 13.414 -2.114 0.103 -67.007 10.240
x2 32.2150 8.128 3.966 0.017 10.622 53.808
x3 359.2287 101.888 3.525 0.027 58.663 659.794
==============================================================================
Omnibus: 0.427 Durbin-Watson: 1.313
Prob(Omnibus): 0.807 Jarque-Bera (JB): 0.475
Skew: -0.318 Prob(JB): 0.789
Kurtosis: 2.047 Cond. No. 936.
==============================================================================
Notes:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
[2] The condition number is large, 9.36e+02. This might indicate that there are
strong multicollinearity or other numerical problems.
```
其中,每个自变量的系数可以通过`model.params`获取。
阅读全文