<jupyter_start><jupyter_text>Gradient Descent Algorithm<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
x=np.arange(1,11)
y=np.array([1.1,3.2,4.5,5.7,10,11.5,12.8,15,16.5,20.1])
plt.scatter(x,y);

"""       H(x) = teta0 + teta1*x    """
teta = np.ones((2,1)) 
train_num = len(x)  
train_num

""" J(teta)=1/(2m) * SUM(h(x)-y)"""

plt.scatter(x,y)

error_fonc= 1/(2*train_num)*pow((teta[0]+teta[1]*x-y),2)

epsilon=10e-9  
learning_rate=0.0001  

i=0
trying=0
max_trying=10000 

while sum(error_fonc)>epsilon and  trying<max_trying:       
    while  i<train_num:
        temp0=teta[0] - learning_rate*(1/train_num) * (teta[0] + teta[1] * x[i] - y[i])
        temp1=teta[1] - learning_rate*(1/(train_num)) * (teta[0] + teta[1] * x[i] - y[i]) * x[i]
        teta[0]=temp0
        teta[1]=temp1
        errorFonk[i]= 1/(2*train_num)*pow((teta[0]+teta[1]*x[i]-y[i]),2)        
        i+=1
    trying+=1    
    i=0
    
plt.plot(x,teta[0]+x*teta[1])
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.2155688622754491, 'fraction_numerical': 0.07684630738522955, 'mean_word_length': 3.6009174311926606, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '350336', 'license': 'MIT', 'n_tokens_mistral': 518, 'n_tokens_neox': 494, 'n_words': 59, 'path': 'Data Science and Machine Learning/Machine-Learning-In-Python-THOROUGH/MACHINE_LEARNING/06_GRADIENT_DESCENT_ALGORITHM.ipynb', 'repo_name': 'okara83/Becoming-a-Data-Scientist', 'size': '1002'}