绘制OLS回归参数
我正在尝试使用 OLS 回归中的一些系数来构建条形图。我的模型名为 jun07_OLS
。因此,我调用了 jun07_OLS.params 来获取:
Intercept 4.580174
jun06 0.616195
treat1 -0.520858
treat2 0.912693
treat3 -0.952914
dtype: float64
如何绘制在单个“jun07”列上分组的 treat1、treat2、treat3 的值?我想要一个列,因为我将在其他月份根据多个 OLS 回归结果构建此条形图。
这就是我到目前为止所得到的:
def get_indicies(mylist):
a_list = mylist.params
indices_to_access = [2, 3, 4]
a_series = pd.Series(a_list)
accessed_series = a_series[indices_to_access]
accessed_list = list(accessed_series)
return accessed_list
jun_coefs = get_indicies(jun07_OLS)
ax = plt.subplot(111)
ax.bar('jun07', jun_coefs, width=0.2, color='b', align='center')
plt.show()
这正在生产一根酒吧。
I am trying to build a bar plot using a few coefficients from an OLS regression. My model is called jun07_OLS
. So I have called jun07_OLS.params
to get:
Intercept 4.580174
jun06 0.616195
treat1 -0.520858
treat2 0.912693
treat3 -0.952914
dtype: float64
How can I plot the values of treat1, treat2, treat3 grouped on a single 'jun07' column? I'd like a single column because I will be building this bar plot from multiple OLS regression results in other months.
This is what I have so far:
def get_indicies(mylist):
a_list = mylist.params
indices_to_access = [2, 3, 4]
a_series = pd.Series(a_list)
accessed_series = a_series[indices_to_access]
accessed_list = list(accessed_series)
return accessed_list
jun_coefs = get_indicies(jun07_OLS)
ax = plt.subplot(111)
ax.bar('jun07', jun_coefs, width=0.2, color='b', align='center')
plt.show()
This is producing one bar.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定我是否误解了你,但似乎不需要你的第一个功能。请看下面:
I am not sure if I am misunderstanding you, but it seems that your first function is not needed. Please see below:
您可以将每个 OLS 回归结果放入列表中(本例中为
regression_list
),并使用 pd.Series 列表中的信息创建数据框。然后,为 x 轴设置正确的值 (set_index('date')
) 并使用df.plot
和参数kind='酒吧'
。You could place every OLS regression result you have in a list (
regression_list
in this example) and create a dataframe using the information inside the pd.Series list. Then, set the index with the correct value (set_index('date')
) for the x-axis and usedf.plot
with the parameterkind='bar'
.