<jupyter_start><jupyter_text>Updating the theta value<jupyter_code># cost_function
theta_sec = np.array([[-1], [2]])
m = len(points)
nextout = 1/(2*m)*np.sum(np.power(np.subtract(np.dot(X, theta_sec),y),2))
nextout<jupyter_output><empty_output><jupyter_text>Gradient Descent<jupyter_code>cost_hist = np.zeros(iteration)
theta_hist = np.zeros((iteration, 2))
theta_sec = np.zeros((2, 1))
for iter in range(iteration):
    prediction = np.dot(X, theta_sec)
    theta_sec = theta_sec - (1/m)*learning_rate*(X.T.dot((prediction -y)))  #gradient descent
    theta_hist[iter,:] = theta_sec.T
    tempcost = 1/(2*m)*np.sum(np.power(np.subtract(np.dot(X, theta_sec),y),2)) #leanring rate
    cost_hist[iter] = tempcost
theta_hist
plt.plot(np.arange(iteration), cost_hist, 'r', 5)
plt.xlabel('Iteration')
plt.ylabel('J (theta)')
cost_hist[1480:-1], cost_hist[0]
mat = np.arange(20).reshape((4,5))
mat
maty= np.random.randint(6, 15, 4).reshape((4,1))
maty
theta_ = np.linspace(-1, 2, 5).reshape(5,1)
theta_
dot_ans = np.dot(mat,theta_)
dot_ans
(maty - dot_ans)**2
data = pd.read_csv('https://s3-eu-west-1.amazonaws.com/shanebucket/downloads/uk-500.csv')
data['id'] = np.random.randint(0,1000, 500)
data.columns = data.columns.str.upper()
data.rename({'COUN': 'COUNTRY'}, axis = 1,inplace = True)
data.head(2)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.19352409638554216, 'fraction_numerical': 0.03765060240963856, 'mean_word_length': 6.183783783783784, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '203128', 'license': 'Apache-2.0', 'n_tokens_mistral': 601, 'n_tokens_neox': 568, 'n_words': 85, 'path': 'machine learning practice.ipynb', 'repo_name': 'lawallanre00490038/Machine-Learning-Practice', 'size': '1328'}