Bir qatlamli neron to`ri


Download 41.12 Kb.
Sana29.01.2023
Hajmi41.12 Kb.
#1139293
Bog'liq
nuriddin1


Bir qatlamli neron to`ri

import matplotlib.pyplot as plt

b=0
w=0
alfa=0.06

x=[-0.36,-0.72,-1.08,-1.44,-1.8,-2.16,-2.88,-3.24,-3.6]


y=[0.432,0.864,1.296,1.728,2.16,2.592,3.024,3.888,4.32]
y_predArr = []
for epoch in range(200):
s=0
for x_in, y_in in zip(x, y):

y_pred = x_in * w + b


E_error = (y_in - y_pred) ** 2
s+=E_error
grad_w = 2 * (y_pred - y_in) * x_in
w = w - alfa * grad_w
grad_b = 2 * (y_pred - y_in)
b = b - alfa * grad_b

print(s/10)


print("\nepoch",epoch)

for i in x:


y_p=i*w+b
y_predArr.append(y_p)

plt.plot(y, color='red')


plt.plot(y_predArr, color='blue')
plt.show()

Download 41.12 Kb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling