gpt4 book ai didi

regression - 普通最小二乘回归给出错误的预测

转载 作者:太空狗 更新时间:2023-10-30 02:44:52 34 4
gpt4 key购买 nike

我正在使用 statsmodels OLS 将一系列点拟合成一条线:

import statsmodels.api as sm
Y = [1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15]
X = [[73.759999999999991], [73.844999999999999], [73.560000000000002],
[73.209999999999994], [72.944999999999993], [73.430000000000007],
[72.950000000000003], [73.219999999999999], [72.609999999999999],
[74.840000000000003], [73.079999999999998], [74.125], [74.75],
[74.760000000000005]]

ols = sm.OLS(Y, X)
r = ols.fit()
preds = r.predict()
print preds

我得到以下结果:

[ 7.88819844  7.89728869  7.86680961  7.82937917  7.80103898  7.85290687
7.8015737 7.83044861 7.76521269 8.00369809 7.81547643 7.92723304
7.99407312 7.99514256]

这些是大约 10 倍的折扣。我究竟做错了什么?我尝试添加一个常量,这只会使值大 1000 倍。我不太了解统计数据,所以也许我需要对这些数据做些什么?

最佳答案

我认为你已经改变了你的 react 和你的预测,就像迈克尔梅耶在他的评论中建议的那样。如果您根据模型的预测绘制数据,您会得到如下结果:

import statsmodels.api as sm
import numpy as np
import matplotlib.pyplot as plt

Y = np.array([1,2,3,4,5,6,7,8,9,11,12,13,14,15])
X = np.array([ 73.76 , 73.845, 73.56 , 73.21 , 72.945, 73.43 , 72.95 ,
73.22 , 72.61 , 74.84 , 73.08 , 74.125, 74.75 , 74.76 ])
Design = np.column_stack((np.ones(14), X))
ols = sm.OLS(Y, Design).fit()
preds = ols.predict()

plt.plot(X, Y, 'ko')
plt.plot(X, preds, 'k-')
plt.show()

enter image description here

如果你切换 X 和 Y,这是我认为你想要的,你会得到:

Design2 = np.column_stack((np.ones(14), Y))
ols2 = sm.OLS(X, Design2).fit()
preds2 = ols2.predict()
print preds2
[ 73.1386399 73.21305699 73.28747409 73.36189119 73.43630829
73.51072539 73.58514249 73.65955959 73.73397668 73.88281088
73.95722798 74.03164508 74.10606218 74.18047927]

plt.plot(Y, X, 'ko')
plt.plot(Y, preds2, 'k-')
plt.show()

enter image description here

关于regression - 普通最小二乘回归给出错误的预测,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27467213/

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