gpt4 book ai didi

python - 线性回归的标准差/误差

转载 作者:太空狗 更新时间:2023-10-30 00:32:10 29 4
gpt4 key购买 nike

所以我有:

t = [0.0, 3.0, 5.0, 7.2, 10.0, 13.0, 15.0, 20.0, 25.0, 30.0, 35.0]
U = [12.5, 10.0, 7.6, 6.0, 4.4, 3.1, 2.5, 1.5, 1.0, 0.5, 0.3]
U_0 = 12.5
y = []
for number in U:
y.append(math.log(number/U_0, math.e))
(m, b) = np.polyfit(t, y, 1)
yp = np.polyval([m, b], t)
plt.plot(t, yp)
plt.show()

因此,通过这样做,我得到了符合 m=-0.1071b=0.0347 的线性回归。

如何获取 m 值的偏差或误差?

我想要m = -0.1071*(1+ plus/minus error)

m is k and b is n in y=kx+n

最佳答案

import numpy as np
import pandas as pd
import statsmodels.api as sm
import math

U = [12.5, 10.0, 7.6, 6.0, 4.4, 3.1, 2.5, 1.5, 1.0, 0.5, 0.3]
U_0 = 12.5
y = []

for number in U:
y.append(math.log(number/U_0, math.e))

y = np.array(y)

t = np.array([0.0, 3.0, 5.0, 7.2, 10.0, 13.0, 15.0, 20.0, 25.0, 30.0, 35.0])
t = sm.add_constant(t, prepend=False)

model = sm.OLS(y,t)
result = model.fit()
result.summary()

enter image description here

关于python - 线性回归的标准差/误差,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22268273/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com