> For the complete documentation index, see [llms.txt](https://uzbek.gitbook.io/ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://uzbek.gitbook.io/ai/kurslar/less-than-03-greater-than-gradient-pastlash.md).

# <03> GRADIENT PASTLASH

{% embed url="<https://youtu.be/US41FuoLIZs>" %}

## GRADIENT PASTLASH (DESCENT)

![](/files/-MQfb7cFR49Z0EHvUN6u)

**Gradient Descent** algoritmi weight **"w"** ning optimal qiymatini topishda qo'llaniladigan algoritmdir. Sodda qilib aytganda, bu algoritm  bizlarga avtomatik tarzda optimal yechimni topib beradi. Ushbu algortim nafaqat **w** ning qiymatini topishda balki keyinchalik **cost function**(kelasi darslarimizda o'rganamiz) ni hisoblashda ham qo'llaniladi.&#x20;

## MATEMATIK FORMULASI (LOSS UCHUN)

![](/files/-MQj3---y-6LnvbtEnix)

## <img src="/files/-MP8BpNTUwnLvpov9gYN" alt="" data-size="line"> AMALIYOT

```python
# Training Data(O'rgatishdagi ma'lumotlar)
x_soat = [1.0, 2.0, 3.0]
y_baho = [2.0, 4.0, 6.0]

w = 1.0  #w uchun dastalbki taxminiy qiymat


# (Modelimiz)To'g'ri hisoblash uchun funksiya
def forward(x):
    return x * w


# Xatolik (Loss) ning funkisyasi
def loss(x, y):
    y_pred = forward(x)
    return (y_pred - y) * (y_pred - y)


# Gradient uchun funksiya
def gradient(x, y):  # d_loss/d_w
    return 2 * x * (x * w - y)


# Training dan avval
print("Bashorat (training dan avval)",  "4 soat o'qilganda:", forward(4))

# Training zanjiri (loop)
learning_rate =0.01
for epoch in range(10):
    for x_hb_qiym, y_hb_qiym in zip(x_soat, y_baho):
        # Hosilani hisoblash
        # w ning qiymatini yangilash
        # xatolikni hisoblab progressni chop qilish
        grad = gradient(x_hb_qiym, y_hb_qiym)
        w = w - learning_rate * grad
        print("\tgrad: ", x_hb_qiym, y_hb_qiym, round(grad, 2))
        l = loss(x_hb_qiym, y_hb_qiym)
    print("progress:", epoch, "w=", round(w, 2), "loss=", round(l, 2))

# Traningdan so'ng
print("Bashorat (training dan keyin)",  "4 saot o'qilganda: ", forward(4))
```

## <img src="/files/-MQRhqm0AV-Z33WBTWBa" alt="" data-size="line"> MATERIALLAR

{% file src="/files/-MW-4jnzO5InRQZWWVon" %}
3-darslik. Slayd
{% endfile %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://uzbek.gitbook.io/ai/kurslar/less-than-03-greater-than-gradient-pastlash.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
