如何从Python的OLSResults获取变量中的P值? [英] How to get the P Value in a Variable from OLSResults in Python?

查看:47
本文介绍了如何从Python的OLSResults获取变量中的P值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

的OLS结果

df2 = pd.read_csv("MultipleRegression.csv")
X = df2[['Distance', 'CarrierNum', 'Day', 'DayOfBooking']]
Y = df2['Price']
X = add_constant(X)
fit = sm.OLS(Y, X).fit()
print(fit.summary())

仅将每个属性的P值显示到小数点后三位.

shows the P values of each attribute to only 3 decimal places.

我需要为每个属性(例如 Distance CarrierNum 等)提取p值,并以科学计数法将其打印出来.

I need to extract the p value for each attribute like Distance, CarrierNum etc. and print it in scientific notation.

我可以使用 fit.params [0] fit.params [1] 等提取系数.

I can extract the coefficients using fit.params[0] or fit.params[1] etc.

需要获取所有P值.

所有P值为0意味着什么?

Also what does all P values being 0 mean?

推荐答案

我们必须执行 fit.pvalues [i] 以获得答案,其中 i 是自变量数量.

We've to do fit.pvalues[i] to get the answer where i is the number of independent variables.

我们还可以使用 dir(< object>)查找对象的所有属性.

We can also look for all the attributes of an object using dir(<object>).

这篇关于如何从Python的OLSResults获取变量中的P值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆