Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Residual standard error of a regression in python

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.

like image 744
Nicolás P Avatar asked Oct 16 '25 17:10

Nicolás P


2 Answers

For a smf.ols fit

# Residual Standard Error of the model
np.sqrt(fitted_model.scale)
like image 88
rahul-ahuja Avatar answered Oct 18 '25 07:10

rahul-ahuja


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])
like image 43
Mohammad Reza Malekpour Avatar answered Oct 18 '25 07:10

Mohammad Reza Malekpour



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!