text_plain_output_1.png
from sklearn.datasets import make_regression

from sklearn.linear_model import LinearRegression

import matplotlib.pyplot as plt

import numpy as np

X, y = make_regression(n_samples=4, n_features=1, n_informative=1, n_targets=1, noise=80, random_state=13)

from sklearn.linear_model import LinearRegression
reg = LinearRegression()
reg.fit(X, y)

(reg.coef_, reg.intercept_)

y_pred = (78.35 * X + 0).reshape(4)

X.ravel()[:5]

m = 78.35
b1 = 100
loss_slope = -2 * np.sum(y - m * X.ravel() - b1)
lr = 0.1
step_size = loss_slope * lr
b1 = b1 - step_size
b1

y_pred1 = (78.35 * X + b1).reshape(4)
plt.figure(figsize=(18, 6))
plt.scatter(X, y)
plt.plot(X, reg.predict(X), color='green', label='OLS')
plt.plot(X, y_pred1, color='#ffdab9', label='b1 = {}_updated'.format(b1))
plt.plot(X, y_pred, color='#ffa500', label='b = 0_initial_random')
plt.legend()
plt.show()