Search code examples
pythonscikit-learnlinear-regression

Python: Different R-squared values from summary and r_squared function


I am building a multiple linear regression model using the following:

regressor = sm.OLS(y_train, X_train).fit()

When requesting a summary of the model with regressor.summary(), the R-squared is 0.204. However, when using r2_score(y_test, y_pred) I get 0.023.

What am I missing here?


Solution

  • regressor.summary() is giving r2 for training data while r2_score(y_test, y_pred) is giving r2 for testing data