Muhammad al-xozazmiy nomidagi toshkent axborot texnologiyalari universiteti mashinali o’qitish fanidan Amaliy ish Bajardi: Boymurodov Zuhriddin Tekshirdi



Download 1,06 Mb.
Sana05.04.2023
Hajmi1,06 Mb.
#925229
Bog'liq
1-ISH


OʻZBEKISTON RESPUBLIKASI AXBOROT TEXNOLOGIYALARI VA KOMMUNIKATSIYALARINI RIVOJLANTIRISH VAZIRLIGI
MUHAMMAD AL-XOZAZMIY NOMIDAGI TOSHKENT AXBOROT TEXNOLOGIYALARI UNIVERSITETI

Mashinali o’qitish fanidan
Amaliy ish

Bajardi: Boymurodov Zuhriddin
Tekshirdi: Qo’chqorov Muslimjon


TOSHKENT – 2023
import random
import matplotlib.pyplot as plt

def mean(data):


return sum(data) / len(data)

def gradient(x, y, w):


grad = 0
for i in range(len(x)):
grad += (y[i] - w * x[i]) * x[i]
grad = -2 * grad / len(x)
return grad

def loss(x, y, w):


l = 0
for i in range(len(x)):
y_pred = w * x[i]
l += (y[i] - y_pred) ** 2
l = l / len(x)
return l

# Generate random data points


random.seed(42)
x = [random.random() for _ in range(100)]
y = [3 * x[i] + 2 + 0.1 * random.random() for i in range(100)]

# Initialize weight and learning rate


w = 0
lr = 0.01

# Perform gradient descent


n_iterations = 100
losses, weights = [], []
for i in range(n_iterations):
grad = gradient(x, y, w)
w -= lr * grad
l = loss(x, y, w)
losses.append(l)
weights.append(w)

print(f"Loss qiymatlari: {losses}")


# Output final weight
print(f"Weight qiymatlari: {weights}")

# Plot loss and weight values


plt.subplot(2, 1, 1)
plt.plot(losses)
plt.xlabel("Iteration")
plt.ylabel("Loss")
plt.subplot(1, 1, 1)
plt.plot(weights)
plt.xlabel("Iteration")
plt.ylabel("Weight")
plt.show()




import random


import matplotlib.pyplot as plt

# Generate random data points


import numpy as np

random.seed(42)


X = [[random.random()] for _ in range(10)]
y = [[2*x[0]**2 + 3*x[0] + random.gauss(0, 1)] for x in X]

# Initialize coefficients and learning rate


w1 = random.random()
w2 = random.random()
lr = 0.1

# Perform gradient descent


n_iterations = 100
losses = []
W1 = []
W2 = []
for i in range(n_iterations):
y_pred = [[w1*x[0]**2 + w2*x[0]] for x in X]
loss = sum([(y[i][0] - y_pred[i][0])**2 for i in range(len(X))]) / len(X)
gradient_w1 = -2*sum([(y[i][0] - y_pred[i][0])*X[i][0]**2 for i in range(len(X))]) / len(X)
gradient_w2 = -2*sum([(y[i][0] - y_pred[i][0])*X[i][0] for i in range(len(X))]) / len(X)
w1 -= lr*gradient_w1
w2 -= lr*gradient_w2
W1.append(w1)
W2.append(w2)
losses.append(loss)

# Print coefficients


print(f"Loss qiymatlari {losses}")
print(f" w1 qiymatlari {W1}")
print(f" w2 qiymatlari {W2}")
# Plot loss graph
plt.plot(range(n_iterations), losses)
plt.title("Loss")
plt.xlabel("Iteration")
plt.ylabel("Loss")
plt.show()

Download 1,06 Mb.

Do'stlaringiz bilan baham:




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

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish