From a dataset like this:
import pandas as pd
import numpy as np
import statsmodels.api as sm
# A dataframe with two variables
np.random.seed(123)
rows = 12
rng = pd.date_range('1/1/2017', periods=rows, freq='D')
df = pd.DataFrame(np.random.randint(100,150,size=(rows, 2)), columns=['y', 'x'])
df = df.set_index(rng)
...and a linear regression model like this:
x = sm.add_constant(df['x'])
model = sm.OLS(df['y'], x).fit()
... you can easily retrieve some model coefficients this way:
print(model.params)
But I just can't find out how to retrieve all other parameters from the model summary:
print(str(model.summary()))
As stated in the question, I'm particularly interested in R-squared.
From the post How to extract a particular value from the OLS-summary in Pandas? I learned that you could just use print(model.r2)
to do the same thing there. But that does not seem to work for statsmodels.
Any suggestions?
You can get R-squared like:
Code:
Test Code:
Results:
Finding All Attribute Names:
With a small bit of code:
You can see all of the attributes on an object: