text_html_output_1.png
import matplotlib.pyplot as plt

import pandas as pd

import statsmodels.api as sm

df = pd.read_csv('../input/random-linear-regression/train.csv')

df.shape

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)

res = y_train - y_train_pred

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

plt.figure()
plt.scatter(x_test, y_test)
plt.plot(x_test, y_test_pred, 'y')