Supervised Learning: Predicting from Labeled Examples
هوش مصنوعی برای همه: هوش مصنوعی چطور باهوش شد؟
- Features and labels in a fruit dataset.
- Classification as choosing a category and regression as predicting a numerical quantity.
- Learning a decision boundary or numerical relationship from examples.
- Prediction error and loss as feedback for adjusting a model.
- A small visual example of improving predictions over repeated updates.
- How learned rules differ from both memorizing individual examples and writing every decision manually.
یادگیری از نمونههای جوابدار
```svg
<svg viewBox="0 0 800 450" xmlns="http://www.w3.org/2000/svg"><defs><marker id="arrow" markerWidth="10" markerHeight="10" refX="8" refY="5" orient="auto"><path class="tm-arrow" d="M0 0 L10 5 L0 10 Z"/></marker></defs><rect class="tm-soft" x="40" y="35" width="220" height="75" rx="14"/><text class="tm-text" x="150" y="65" text-anchor="middle" font-size="20" direction="rtl">مشخصات میوه</text><text class="tm-text2" x="150" y="93" text-anchor="middle" font-size="17" direction="rtl">رنگ و وزن</text><path class="tm-line" d="M270 73 H330" marker-end="url(#arrow)"/><rect class="tm-surface" x="340" y="35" width="140" height="75" rx="14"/><text class="tm-text" x="410" y="80" text-anchor="middle" font-size="21" direction="rtl">دستگاه</text><path class="tm-line" d="M490 73 H550" marker-end="url(#arrow)"/><rect class="tm-soft" x="560" y="35" width="200" height="75" rx="14"/><text class="tm-text" x="660" y="80" text-anchor="middle" font-size="21" direction="rtl">سیب یا پرتقال؟</text><rect class="tm-soft" x="40" y="180" width="720" height="64" rx="12"/><rect class="tm-soft" x="40" y="255" width="720" height="64" rx="12"/><text class="tm-text" x="150" y="220" text-anchor="middle" font-size="20" direction="rtl">قرمز</text><text class="tm-text" x="365" y="220" text-anchor="middle" font-size="20">\(150\,\mathrm{g}\)</text><text class="tm-text" x="660" y="220" text-anchor="middle" font-size="20" direction="rtl">سیب</text><text class="tm-text" x="150" y="295" text-anchor="middle" font-size="20" direction="rtl">نارنجی</text><text class="tm-text" x="365" y="295" text-anchor="middle" font-size="20">\(180\,\mathrm{g}\)</text><text class="tm-text" x="660" y="295" text-anchor="middle" font-size="20" direction="rtl">پرتقال</text><path class="tm-line-accent" d="M55 170 V157 H465 V170"/><text class="tm-text-accent" x="260" y="145" text-anchor="middle" font-size="19" direction="rtl">features: ورودیهای مدل</text><path class="tm-line" d="M520 175 V322"/><path class="tm-line-accent" d="M555 170 V157 H745 V170"/><text class="tm-text-accent" x="650" y="145" text-anchor="middle" font-size="19" direction="rtl">label: جواب هدف</text><text class="tm-text2" x="650" y="350" text-anchor="middle" font-size="17" direction="rtl">از قبل معلوم؛ نه حدس مدل</text><rect class="tm-accent tm-enter" x="100" y="375" width="600" height="55" rx="12"/><text class="tm-text" x="400" y="410" text-anchor="middle" font-size="20" direction="rtl">موقع استفاده: فقط features؛ جواب را مدل پیشبینی میکند</text></svg>
```
نوع سؤال، نوع پیشبینی را تعیین میکند
**classification: پیشبینی دسته**
«این میوه سیبه یا پرتقال؟»
label: سیب یا پرتقال
**regression: پیشبینی مقدار عددی**
«وزن این میوه چقدره؟»
feature: رنگ و اندازه
label: وزن واقعی؛ سیب \(150\,\mathrm{g}\)، پرتقال \(180\,\mathrm{g}\)
**نقش وزن به سؤال بستگی دارد**
پیشبینی نوع میوه: وزن میتواند feature باشد.
پیشبینی وزن: وزن label است؛ جواب هدف را بهعنوان ورودی نمیدهیم.
**معنی جواب، نه شکل نوشتن**
وزن عددی: مقدار قابل اندازهگیری ← regression
کد عددیِ سیب یا پرتقال: فقط نام دسته ← classification
یک مرز مشترک برای تصمیم
```svg
<svg viewBox="0 0 800 550" xmlns="http://www.w3.org/2000/svg"><defs><marker id="arrow" markerWidth="8" markerHeight="8" refX="7" refY="4" orient="auto"><path class="tm-arrow" d="M0 0 L8 4 L0 8 Z"/></marker></defs><line class="tm-line" x1="120" y1="340" x2="710" y2="340" marker-end="url(#arrow)"/><line class="tm-line" x1="120" y1="340" x2="120" y2="45" marker-end="url(#arrow)"/><text class="tm-text" x="680" y="378" font-size="18" text-anchor="middle" direction="rtl">وزن بیشتر</text><text class="tm-text" x="130" y="28" font-size="18" text-anchor="middle" direction="rtl">رنگ نزدیکتر به نارنجی</text><circle class="tm-accent" cx="290" cy="275" r="11"/><text class="tm-text" x="290" y="245" font-size="18" text-anchor="middle" direction="rtl">سیب قرمز</text><text class="tm-text2" x="290" y="320" font-size="16" text-anchor="middle">\(150\,\mathrm{g}\)</text><circle class="tm-gold" cx="590" cy="110" r="11"/><text class="tm-text" x="590" y="80" font-size="18" text-anchor="middle" direction="rtl">پرتقال نارنجی</text><text class="tm-text2" x="590" y="150" font-size="16" text-anchor="middle">\(180\,\mathrm{g}\)</text><line class="tm-line-accent" x1="390" y1="60" x2="390" y2="340" stroke-width="3"/><text class="tm-text-accent" x="390" y="378" font-size="18" text-anchor="middle">\(160\,\mathrm{g}\)</text><text class="tm-text-accent" x="245" y="195" font-size="18" text-anchor="middle" direction="rtl">پیشبینی: سیب</text><text class="tm-text-gold" x="560" y="275" font-size="18" text-anchor="middle" direction="rtl">پیشبینی: پرتقال</text><text class="tm-text-accent" x="425" y="50" font-size="18" text-anchor="middle">decision boundary</text><text class="tm-muted" x="400" y="420" font-size="17" text-anchor="middle" direction="rtl">مثال ساختگی؛ نه قانون همهٔ میوهها</text><rect class="tm-soft tm-enter" x="425" y="445" width="330" height="80" rx="12"/><text class="tm-text" x="590" y="475" font-size="18" text-anchor="middle" direction="rtl">دستی: تعیین خط توسط ما</text><text class="tm-text2" x="590" y="505" font-size="16" text-anchor="middle" direction="rtl">تصمیم از پیش نوشتهشده</text><rect class="tm-soft tm-enter" x="45" y="445" width="355" height="80" rx="12"/><text class="tm-text" x="222" y="475" font-size="18" text-anchor="middle" direction="rtl">یادگیری: پیدا کردن خط از داده</text><text class="tm-text2" x="222" y="505" font-size="16" text-anchor="middle" direction="rtl">مقایسهٔ پیشبینی با جواب آموزشی</text></svg>
```
مقایسهٔ مدلها با میانگین خطا
دو مدل، همان سیب و پرتقال آموزشی؛ یک معیار مشترک برای loss.
**اختلاف وزن، بدون توجه به جهت**
\[ \ell=|\hat{w}-w| \]
وزن پیشبینیشده و وزن هدف؛ حدس سبکتر و سنگینتر با فاصلهٔ برابر، loss برابر دارند.
**مدل الف: خطای سیب، خطای پرتقال**
\[ \ell_{A,1}=1\,\mathrm{g},\qquad \ell_{A,2}=3\,\mathrm{g} \]
**مدل ب: خطای سیب، خطای پرتقال**
\[ \ell_{B,1}=1\,\mathrm{g},\qquad \ell_{B,2}=1\,\mathrm{g} \]
**میانگین خطای مدل الف**
\[ \bar{\ell}_A=\frac{1+3}{2}\,\mathrm{g}=\frac{4}{2}\,\mathrm{g}=2\,\mathrm{g} \]
**میانگین خطای مدل ب**
\[ \bar{\ell}_B=\frac{1+1}{2}\,\mathrm{g}=\frac{2}{2}\,\mathrm{g}=1\,\mathrm{g} \]
**برازش بهتر مدل ب روی همین نمونههای آموزشی**
\[ \bar{\ell}_B<\bar{\ell}_A\qquad (1\,\mathrm{g}<2\,\mathrm{g}) \]
دادهها و معیار loss یکساناند؛ دربارهٔ میوههای ندیده هنوز نتیجهای نداریم.
یادگیری؛ چرخهی پیشبینی و اصلاح
```svg
<svg viewBox="0 0 800 450" xmlns="http://www.w3.org/2000/svg"><defs><marker id="arrow" markerWidth="8" markerHeight="8" refX="7" refY="4" orient="auto"><path class="tm-arrow" d="M0 0 L8 4 L0 8 Z"/></marker></defs><path class="tm-line" d="M70 45 V280 H550" fill="none"/><text class="tm-text2" x="42" y="40" font-size="16" text-anchor="middle" direction="rtl">رنگ</text><text class="tm-text2" x="535" y="307" font-size="16" text-anchor="middle" direction="rtl">وزن</text><text class="tm-muted" x="125" y="65" font-size="15" text-anchor="middle" direction="rtl">سمت سیبها</text><text class="tm-muted" x="435" y="65" font-size="15" text-anchor="middle" direction="rtl">سمت پرتقالها</text><path class="tm-line" d="M200 80 V268 M320 80 V268" stroke-dasharray="4 6" opacity="0.3"/><path class="tm-line-accent" d="M390 80 V268" stroke-width="3"/><text class="tm-text-accent" x="390" y="35" font-size="16" text-anchor="middle" direction="rtl">مرز مدل</text><circle class="tm-green" cx="230" cy="210" r="12"/><circle class="tm-green" cx="285" cy="175" r="12"/><circle class="tm-green" cx="355" cy="195" r="12"/><path class="tm-gold" d="M465 100 L479 114 L465 128 L451 114 Z"/><path class="tm-gold" d="M515 150 L529 164 L515 178 L501 164 Z"/><rect class="tm-soft" x="585" y="70" width="190" height="220" rx="14"/><text class="tm-text" x="680" y="102" font-size="17" text-anchor="middle" direction="rtl">label واقعی</text><circle class="tm-green" cx="620" cy="135" r="9"/><text class="tm-text" x="685" y="141" font-size="16" text-anchor="middle" direction="rtl">سیب</text><path class="tm-gold" d="M620 158 L630 168 L620 178 L610 168 Z"/><text class="tm-text" x="685" y="174" font-size="16" text-anchor="middle" direction="rtl">پرتقال</text><circle class="tm-line-accent" cx="620" cy="202" r="12" fill="none"/><text class="tm-text2" x="690" y="208" font-size="14" text-anchor="middle" direction="rtl">پیشبینی نادرست</text><text class="tm-text-green" x="680" y="259" font-size="23" text-anchor="middle" direction="rtl">خطا: صفر</text><rect class="tm-soft" x="80" y="335" width="170" height="48" rx="10"/><rect class="tm-soft" x="310" y="335" width="180" height="48" rx="10"/><rect class="tm-soft" x="550" y="335" width="170" height="48" rx="10"/><text class="tm-text" x="165" y="365" font-size="17" text-anchor="middle" direction="rtl">پیشبینی</text><text class="tm-text" x="400" y="365" font-size="17" text-anchor="middle" direction="rtl">مقایسه با label</text><text class="tm-text" x="635" y="365" font-size="17" text-anchor="middle" direction="rtl">اصلاح مدل</text><path class="tm-line" d="M250 359 H300 M490 359 H540" fill="none" marker-end="url(#arrow)"/><path class="tm-line" d="M635 383 V409 H165 V390" fill="none" marker-end="url(#arrow)"/><text class="tm-text-accent tm-enter" x="400" y="440" font-size="17" text-anchor="middle" direction="rtl">انسان: آمادهسازی مسئله، داده و معیار؛ نه انجام دستی هر اصلاح</text></svg>
```
Back to course