<jupyter_start><jupyter_text>Algorithm - Linear Regression !<jupyter_code>def hypothesis(theta,x):
    return theta[0] + theta[1]*x

def error(X,Y, theta):
    total_error = 0
    m = X.shape[0]
    
    for i in range(m):
        total_error += (Y[i] - hypothesis(theta, X[i]))**2
        
    return 0.5*total_error

def gradient(Y,X,theta):
    grad = np.array([0.0,0.0])
    m = X.shape[0]
    for i in range(m):
        grad[0] += -1*(Y[i] - hypothesis(theta,X[i]))
        grad[1] += -1*(Y[i] - hypothesis(theta,X[i]))*X[i]
    return grad

def gradientDescent(X,Y,learning_rate, maxItr):
    grad = np.array([0.0, 0.0])
    theta = np.array([0.0,0.0])
    e = []
    
    for i in range(maxItr):
        grad = gradient(Y,X,theta)
        ce = error(X,Y,theta)
        theta[0] = theta[0] - learning_rate*grad[0]
        theta[1] = theta[1] - learning_rate*grad[1]
        e.append(ce)
        print(ce)
    return theta, e 

theta,e = gradientDescent(X,Y,learning_rate=0.001,maxItr=100)
print(theta[0], theta[1])
plt.scatter(X,Y)
plt.plot(X,hypothesis(theta,X), color='r')
plt.show()
plt.plot(e)
plt.show()
print(e[50])
print(e[99])
### Convergence Criteria<jupyter_output><empty_output>