我正在寻找:“60岁女性肌肉质量的估计值”,这是我用以下代码生成的图表:
data = pd.DataFrame({'x': x, 'y': y})
model = ols('y ~ x', data).fit()
print(model.summary())
a1 = model.params[1]
print('a1 (slope) = {:.4f}'.format(a1))
a0 = model.params[0]
print('a0 (intercept) = {:.4f}'.format(a0))
#line of regression
def y_model(x):
return a0 + a1*x
# now plot the regressed line as a function of the input data x
plt.plot(x, y_model(x), label='least-squares fit')
# plot the original data
plt.plot(x, y,'ro', label='original data')
plt.xlabel('age, years')
plt.ylabel('muscle mass')
plt.title('Muscle Mass in Women Ages 40-79' )
plt.legend()
plt.grid()如果可能,我想使用model中的a函数。即使我能想出一种方法来返回x ==60处的y值,我怎么才能让它成为一个‘估计’呢?我应该取平均值吗?

发布于 2020-09-13 18:10:01
模型对象有一个您可以使用的"predict“方法。如果模型尚未拟合,则params不是可选的,但如果已拟合,则params将保存在模型实例中。点击此处阅读:https://www.statsmodels.org/dev/generated/statsmodels.regression.linear_model.OLS.predict.html#statsmodels.regression.linear_model.OLS.predict
基本上可以这样做: y_new = model.predict(new_sample)
https://stackoverflow.com/questions/63869239
复制相似问题