Tashkent university of information technologies named after muhammad al-khorezmi


Download 0.7 Mb.
Sana17.06.2023
Hajmi0.7 Mb.
#1553193




TASHKENT UNIVERSITY OF INFORMATION TECHNOLOGIES NAMED AFTER MUHAMMAD AL-KHOREZMI
1-LABORATORY WORK
Subject: Introduction to Machine learning
Group: 214-20
Done by: Abdullayev Shoxrux
Checked by: Qo’chqarov Muslimjon

Toshkent-2023

1-Practical task


Code:
import numpy as np
import matplotlib.pyplot as plt
n=int (input())
a=0.01
x=[1,2,3]
y=[2,4,6]
w=np.zeros(n)
r=np.zeros(n)
for i in range (1,n):
for j in range(0,3):
w[i]=w[i-1]-a*2*(w[i-1]*x[j]-y[j])*x[j]
r[i-1]=(w[i-1]*x[j]-y[j])**2
if 0.0001>r[i-1] and r[i-1]<=0.001:
print(r[i-1])
print(w[n-1]*4)
plt.plot(r)
plt.show()

2 - practical task.


Code:
import numpy as np
import matplotlib.pyplot as plt
n=int (input())
a=0.0001
x1=[1,2,3]
x2=[3,4,5]
y=[18,26,34]
e1 = 0
e2 = 0
w1=np.zeros(n)
w2=np.zeros(n)
loss=np.zeros(n)
for i in range (1,n):
for j in range (0,3):
e1+=(w1[i-1]*x1[j]+w2[i-1]*x2[j]-y[j])*x1[j]
e2+=(w1[i-1]*x1[j]+w2[i-1]*x2[j]-y[j])*x2[j]
loss[i] += (w1[i - 1] * x1[j] + w2[i - 1] * x2[j] - y[j]) ** 2
w1[i] = w1[i - 1] - a * (2 / 3 * e1)
w2[i] = w2[i - 1] - a * (2 / 3 * e2)
if loss[i]>=0.0001 and loss[i]< 0.001:
print(w1[i],w2[i],loss[i])
plt.plot(loss)
plt.show()

Download 0.7 Mb.

Do'stlaringiz bilan baham:




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