text_plain_output_1.png
from sklearn.metrics import r2_score

import statsmodels.api as sm

x_train.shape

x_train_sm = sm.add_constant(x_train)
x_train_sm

model = sm.OLS(y_train, x_train_sm)
lr_model = model.fit()

lr_model.params

lr_model.summary()

y_train_pred = lr_model.predict(x_train_sm)

x_test_sm = sm.add_constant(x_test)
y_test_pred = lr_model.predict(x_test_sm)

r2 = r2_score(y_test, y_test_pred)

r2