فيديو المحاضرة
فيديو المحاضرة
بعد الفيديو: الأمثلة والاختبار والتمارين والمشروع الصغير تحت.
رسوم متحركة
أمثلة Python
أمثلة قصيرة وبسيطة
الكود قصير والنتيجة اتجرّبت فعلاً. عدّل في المحرر واضغط شغّل.
المثال ١: Neuron بإيدينا
Sample output (press Run to produce your own): weighted sum z: 0.5 neuron output : 0.622
المثال ٢: Tensors و shapes و broadcasting
Sample output (press Run to produce your own): shapes: () (4,) (2, 3) column means: [ 2. 20.] centered: [[ -1. -10.] [ 0. 0.] [ 1. 10.]] X @ W shape: (3, 4)
المثال ٣: neuron بيتعلّم AND
Sample output (press Run to produce your own): step 0 loss 0.693 step 100 loss 0.143 step 200 loss 0.081 step 300 loss 0.056 step 400 loss 0.043 step 500 loss 0.035 predictions: [0. 0.04 0.04 0.94]
اختبار قصير
اختبر فهمك
1. What does a single artificial neuron compute?
2. A tensor with shape (32, 8) most naturally means:
3. What does the loss function tell us?
4. What does gradient descent do in each step?
5. For a small table with a few numeric columns, a good first move is:
تمارين برمجة
جرّب بإيدك
التمرين 1
احسب خرج neuron: المجموع الموزون z وبعدين الـ sigmoid، واطبع الاتنين.
Compute a neuron: the weighted sum z, then the sigmoid. Print both.
(output appears here)
import numpy as np
x = np.array([1.0, 2.0, -1.0])
w = np.array([0.5, -0.25, 1.0])
b = -0.5
z = np.dot(w, x) + b
out = 1 / (1 + np.exp(-z))
print('z =', round(float(z), 3))
print('output =', round(float(out), 3))
Output
z = -1.5 output = 0.182
التمرين 2
اعمل standardization لكل عمود (اطرح المتوسط واقسم على الانحراف) واطبع الناتج ومتوسطات الأعمدة الجديدة.
Standardize each column (subtract the mean, divide by the std). Print the result and the new column means.
(output appears here)
import numpy as np
X = np.array([[1.0, 200.0], [2.0, 400.0], [3.0, 600.0], [4.0, 800.0]])
Z = (X - X.mean(axis=0)) / X.std(axis=0)
print(np.round(Z, 2))
print('means:', np.round(Z.mean(axis=0), 2))
Output
[[-1.34 -1.34] [-0.45 -0.45] [ 0.45 0.45] [ 1.34 1.34]] means: [0. 0.]
مشروع صغير في آخر المحاضرة
درّب neuron واحد يشخّص أورام الثدي
الداتا: Breast Cancer Wisconsin (Diagnostic): 569 samples, 30 numeric features, benign or malignant. Source: UCI Machine Learning Repository.
License / source: Ships with scikit-learn. Dataset page
الخطوات
- حمّل الداتا وقسّمها ٨٠/٢٠ بـ random_state=0 و stratify.
- اعمل standardization للـ features (احسب المتوسط والانحراف من الـ training بس).
- اكتب neuron واحد (وزن لكل feature + bias) بالـ sigmoid بإيدك بـ numpy.
- درّبه ٣٠٠ خطوة gradient descent بـ lr=0.5 على الـ cross-entropy.
- اطبع دقة الـ test وقارنها بـ LogisticRegression من scikit-learn.
Expected output (press Run to produce your own): our neuron test accuracy: 0.974 sklearn test accuracy : 0.982
Credits: the topic order follows the book "Dive into Deep Learning" (d2l.ai) by Zhang, Lipton, Li and Smola, whose text is licensed CC BY-SA 4.0. The explanations, diagrams and code in this lecture are our own and are not copied from the book. Reference: d2l.ai, Introduction.