Problem with regression challenge

Hi,

I am trying to figure out theta 0 and theta 1 for the ML linear regression challenge : Hardwork Pays Off.
I have tried the following code and a lot of combinations of theta 0 and theta 1. However, when I plot the error function, it is observed that initially the error is zero and then it jumps to infinity. please help.

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from mpl_toolkits.mplot3d import axes3d

# Setting data
dfx = pd.read_csv('.../Training Data/Linear_X_Train.csv')
dfy = pd.read_csv('.../Training Data/Linear_Y_Train.csv')
x = dfx.values
y = dfy.values
x = x.reshape((-1,))
y = y.reshape((-1,))

plt.scatter(x,y)
X = (x-x.mean())/x.std()
Y = y
print (X.shape[0])
plt.scatter(X,Y)

plt.show()
plt.hist(X, 10)
plt.show()
plt.hist(Y,10)
plt.show()

def hypothesis(x,theta):
    return theta[0] + theta[1]*x


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

def gradient(X,Y,theta):
    
    grad = np.zeros((2,))
    m = X.shape[0]

    for i in range(m):
        hx = hypothesis(X[i],theta)
        grad[0] +=  (hx-Y[i])
        grad[1] += (hx-Y[i])*X[i]
        
    return grad
    
#Algorithm
def gradientDescent(X,Y,learning_rate=0.1):
    
    theta = np.array([1.0,0.0])
    #theta = theta.astype('float64') 
    print (type(theta))
    
    itr = 0
    max_itr = 100
    
    error_list = []
    theta_list = []
    
    while(itr<=max_itr):
        grad = gradient(X,Y,theta)
        e = error(X,Y,theta)
        #print (e)
        error_list.append(e)
        
        theta_list.append((theta[0],theta[1]))
        theta[0] = theta[0] - learning_rate*grad[0]
        theta[1] = theta[1] - learning_rate*grad[1]
        
        
        itr += 1
        
    
    return theta,error_list,theta_list


# In[128]:


final_theta, error_list,theta_list = gradientDescent(X,Y)
plt.plot(theta_list)
plt.show()
plt.plot(error_list)
plt.show()
print (final_theta)

Kindly help

Use Mini Batch instead of simple gradient descent because sample data is big.
Like this
"
def batch_gradient(X,Y,theta,batch_size=30):
m=Y.shape[0]
indices=np.arange(m)
np.random.shuffle(indices)
indices=indices[:batch_size]
grad=np.zeros((2,))
for i in indices:
hx=hypothesis(X[i],theta)
grad[0]+=(hx-Y[i])
grad[1]+=(hx-Y[i])*X[i]

return(grad)

"
This may help you.

Use mini batch to calculate the gradients.
def batch_gradient(X,Y,theta,batch_size=30):
m=Y.shape[0]
indices=np.arange(m)
np.random.shuffle(indices)
indices=indices[:batch_size]
grad=np.zeros((2,))
for i in indices:
hx=hypothesis(X[i],theta)
grad[0]+=(hx-Y[i])
grad[1]+=(hx-Y[i])*X[i]

    return(grad)