Can I calculate RSE in Python if I'm using scikit-learn for regression?

Responsive Ad Header

Question

Grade: Education Subject: Support
Can I calculate RSE in Python if I'm using scikit-learn for regression?
Asked by:
71 Viewed 71 Answers

Answer (71)

Best Answer
(587)
Yes, you can calculate the RSE in Python with `scikit-learn`. While `scikit-learn`'s `LinearRegression` object doesn't directly provide an 'RSE' attribute, you can calculate it manually. First, fit your model and get the predicted values (`y_pred`). Then, use `mean_squared_error` from `sklearn.metrics` to get the Mean Squared Error (MSE), and take the square root of the MSE. Be mindful that `scikit-learn`'s MSE uses `n` in the denominator, so for the true RSE (with adjusted denominator for degrees of freedom), you might need to adjust the calculation slightly or use `statsmodels`.