Regression Algorithms - Linear Regression - Machine learning

Prologue to Straight Relapse
Straight relapse might be characterized as the measurable model that investigates the direct connection between a reliant variable with given set of free factors. Straight connection between factors implies that when the worth of at least one free factors will change (increment or decline), the worth of ward variable will likewise change as needs be (increment or abatement).

Numerically the relationship can be addressed with the assistance of following condition −

Y = mX + b

Here, Y is the reliant variable we are attempting to anticipate

X is the reliant variable we are utilizing to make expectations.

m is the slop of the relapse line which addresses the impact X has on Y

b is a consistent, known as the Y-catch. If X = 0,Y would be equivalent to b.

Moreover, the direct relationship can be positive or negative in nature as made sense of underneath −





%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt



def coef_estimation(x, y):
n = np.size(x)
m_x, m_y = np.mean(x), np.mean(y)

SS_xy = np.sum(y*x) - n*m_y*m_x
SS_xx = np.sum(x*x) - n*m_x*m_x
b_1 = SS_xy / SS_xx
b_0 = m_y - b_1*m_x
return(b_0, b_1)

def plot_regression_line(x, y, b):
plt.scatter(x, y, color="m", marker="o", s=30)
y_pred = b[0] + b[1] * x
plt.plot(x, y_pred, color="g")
plt.xlabel('x')
plt.ylabel('y')
plt.show()


def main():
x = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
y = np.array([100, 300, 350, 500, 750, 800, 850, 900, 1050, 1250])
b = coef_estimation(x, y)
print("Estimated coefficients:\nb_0 = {} \nb_1 = {}".format(b[0], b[1]))
plot_regression_line(x, y, b)


if __name__ == "__main__":
main()




Regression Algorithms - Linear Regression - Machine learning