Does anyone know a command or a way to obtain the residual standard error of a regression or standard error of a regression?
I use the following commands to get the coefficients and the R-squared, I would like to learn one command like these for the standard error of the regression:
#For the coefficients:
model = smf.OLS(y, X).fit()
print(model.params)
#For the R-squared:
model = smf.OLS(y, X).fit()
print(model.rsquared)
I will be really grateful to the person that can help me with this issue.
For a smf.ols fit
# Residual Standard Error of the model
np.sqrt(fitted_model.scale)
To get Residual Standard Error (RSE) of a regression model in python's statsmodels library, you can simply apply the standard deviation method with the degree of freedom equal to the number of predictors (p) + 1 as below:
model = sm.OLS(y, X).fit()
model.resid.std(ddof=X.shape[1])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With