How to get the P Value in a Variable from OLSResults in Python?

Addzy K picture Addzy K · Dec 10, 2016 · Viewed 24.1k times · Source

The OLSResults of

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())

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

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

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

Need to get it for all their P values.

Also what does all P values being 0 mean?

Answer

Addzy K picture Addzy K · Dec 13, 2016

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

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