Nga Vu
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    --- tags: COTAI LHP --- # Lecture Notes ML4AI 2021 Course page: https://hackmd.io/@CoTAI/ml4ai1601 machinelearningcoban: https://machinelearningcoban.com/ Tên: VŨ THỊ QUỲNH NGA Lớp: 11CA3 # ML4AI Midterm Questions (written exam, open book, 1 hour) 1. [**5** Point] Given a set of inputs $(X^1,\dots,X^N)$, we use PCA to represent them as $X^t = X_0 + z_1U_1+\dots+z_nU_n$ with $X_0$ the mean input and $U_i$ the orthonormal principal components. - [**2** Points] Write down equation for $X_0$, and equations for properties of $U_i,U_j$: unit length & mutual orthogonal. **Solution**: $X_0=\frac{X^1+X^2+...+X^N}{N}$ - [**1** Point] We need to reduce the dimensions of $X^t$ to visualize them on 2D. What is the embedding vector ${\bf z}^t$ of $X^t$ if we use only 2 first principal components to represent it? What is the last feature of ${\bf z}^t$ in this case? **Solution**: $[X^1, X^2]$ - [**1** Point] What are the main differences between representations by PCA and by sparse coding? **Solution**: - [**1** Point] If we cluster the dataset into 3 groups with centroids $({\bf m}_1, {\bf m}_2, {\bf m}_3),$ what is the label embedding coordinates of $X^t$ if it belongs to cluster 2? **Solution**: 2. [**1** Point] If we use each song as a feature to represent the users, what is the embedding coordinates ${\bf z}_A$ of user A in the dataset below? **Solution**: $z_A = 0.99x_1 \cdot0.02x_2$ ![](https://i.imgur.com/PseEFdZ.png) 3. [**3** Point] From the general form of linear predictors: $\hat{y}=\mathsf{s}(Wz+b)$ with $\mathsf{s}(\cdot)$ a transfer function for desired output interpretation. - [**1** Point] What is $W$ for - 1 dimentional linear regression? **Solution**: $W$ là một con số - sofmax regression with 3 classes? **Solution**: $W$ là một mảng chứa các hệ số tối ưu sao cho giá trị của đầu ra là chính xác nhất - [**1** Point] What is function $\mathsf{s}(\cdot)$ for - 1 dimentional linear regression? **Solution**: Không có hàm $\mathsf{s}(\cdot)$ - SVM binary classification? **Solution**: argmax của hai vector - [**1** Point] Why logistic regression (for binary classification) has only 1 probability output while there are 2 classes? **Solution**:$\to$Nếu output của hàm sigmoid >= 0,5 thì điểm đó thuộc class 0, còn < 0.5 thì điểm đó thuộc class 1. 4. [**2** Points] Evaluation procedure - [**1** Point] Explain the main use of the train--dev (validation)--test sets. **Solution**:Train set dùng để huấn luyện (fit) model. $\to$Validation set dùng để đánh giá lại model sau mỗi lần huấn luyện. Test set dùng để đánh gia model cuối cùng - Khi được tập dữ liệu ta chia nó thành tập train, test, validation - [**1** Point] What are the main similarity and differences between linear SVM and logistic regression? **Solution**: $\to$ Giống nhau: + Đều là các mô hình linear giải quyết các bài toán classification và regression. + Đều tốn ít thời gian và tài nguyên để xử lí và tính toán. - Khác nhau: + SVM tìm margin (khoảng cách giữa các đường với các support vetors) để giảm lỗi trong dữ liệu. + Logistic regression tìm decision boundary với các weights sao cho gần điểm tối ưu nhất. 5. [**2** Points] There are **1100 items** and **one million users**. We need to build a content-based RecSys by extracting **120 features** ${\bf z}_i$ describing each item $i$ then learn a classifier ${\bf \theta}_j$ for each user $j$ to predict **ratings from 1 to 5 stars** of each user for each item. ![](https://i.imgur.com/PseEFdZ.png) - [**1** Point] How many classes do we need? **Solution**:1100 - [**1** Point] What is the size of $W$ if we use softmax regression $\hat{y}=s(Wz+b)$ for to classify ratings? **Solution**: ((1000000, 120) , 1100) 6. [**2** Points] Nonlinear predictors have general form $\hat{y}=s(W'\phi(z)+b')$. For Multilayer Perceptrons (MLP) in particular: $\phi(z) = \gamma(Wz+b)$ recursively, each called a "hidden layer". - [**1** Point] Give explicit equation of an MLP with 2 hidden layers. **Solution**:$\phi(z) = \gamma(Wz'+b) =\gamma(W\cdot \beta(Wz''+b'')+b)$ - [**1** Point] What are the parameters of the fully-connected layer in your equation? **Solution**: 7. [**2** Points] Kernel machines use "kernel trick" $\phi(z_i)\cdot\phi(z_j) = \kappa(z_i,z_j)$. - [**1** Point] Explain why kernel trick is useful. **Solution**: Thay vì tính trực tiếp tọa độ của các điểm trong không gian mới ta chỉ cần tính tích vô hướng giữa hai điểm bất kì trong không gian mới.m Lợi ích: . Giảm bộ nhớ và thời gian xử lí - [**1** Point] Explain how we can use kernel trick in feature-space prediction $\hat{y}=s(W^\phi\phi(z)+b)$ to turn a linear predictor into a nonlinear one. **Solution**: $\to$Để có được mô hình phi tuyến, ta cần biến đổi bằng hàm phi tuyến biến đổi đặc trưng --- ## Session 1 -- Linear Predictors * [Slide](https://hackmd.io/@CoTAI/S154-Ofkd#/) * [Laboratory](https://colab.research.google.com/drive/1P3DlH1zrq9DZyvikCzd_ehX5vDZzqhuU?usp=sharing) * [Homework](https://colab.research.google.com/drive/1Z5O7OsgU7jQbKPrMVAh0RHoXaApHqyGk?usp=sharing) ### 1. Linear Predictors $X_t \to f(i) \to Y_t$ $D = {(x_t, y_t)}^{N}_{t=1}$ VD: Qua một hàm số, một mô tả đưa ra output là giá. Bằng cách tính sai số, tính được độ chính xác. $\Rightarrow$ Đánh gia độ tốt xấu thông qua sai số. ### 1.1. Cách tìm hàm số trí tuệ: $X \rightarrow Z[x_1,x_2,...,x_n] \rightarrow \hat{Y}$ * Trích xuất ra những đặc trưng Z từ basis X thông qua predictor B; * Vẽ lên không gian hệ tọa độ; * Tính khoảng cách giữa các điểm trong hệ tọa độ; * Phân nhóm trên hệ tọa độ; * Đưa ra dự báo $\hat{Y}$; ### 1.2. Các thể loại dữ liệu * Numerical value * Giá trị rời rạc: có thể đếm-không thể đo được * Giá trị liên tục: có thể đo được * Giá trị theo nhóm * Nominal data * Ordinal data ### 1.3. Hai loại dự báo * Dự báo giá trị liên tục * Dự báo giá trị rời rạc ### 1.4. Phân loại(Classification & Clustering) * Phân loại theo ý mình-cần làm mẫu: classification (Supervised Learning) * Phân loại theo ý máy tính: CLustering (Unsupervised learning) ### 1.5. Mô hình tuyến tính cho bài toán #### 1.5.1. Dự đoán giá trị Mô hình tuyến tính **$s(Z \times W + b) = Y$** (hàm số có đồ thị dạng phẳng) (tích chấm) s: hàm số để chỉnh sửa đầu ra theo ý muốn(Softmax, Sigmoid,...) Z: trọng số (array) W: hệ số (array) b: phát sinh(phí ship, etc.) Y: Giá trị được dự đoán #### 1.5.2. Phân biệt nhóm bằng phương pháp tuyến tính ? Làm sao để tính được sự giống nhau => So khớp bằng tích chấm $Y_1 \times Y_2$ = Độ giống nhau $Y_1$: các đặc trưng của mẫu 1(array) $Y_2$: các đặc trưng của mẫu 2(array) ? Tại sao $Y_1 \times Y_2$ lại cho thấy độ giống nhau Cách phân nhóm: VD: phâm một điểm vào nhóm xanh hoặc đỏ => Điểm đó được bao xung quanh bởi nhóm nào nhiều hơn thì điểm sẽ thuộc nhóm đó. **Phần chưa hiểu:** 1. Máy tính sẽ tìm ra các hệ số tối ưu trong bài toán dự đoán giá trị như thế nào? $\to$ Sử dụng các thuật toán tối ưu (VD: gradient, descent,..), sau $i$ vòng lặp thì sẽ tìm ra được hàm $f$ tối ưu nhất. ## Session 2 -- Feature Extraction * [Slide](https://hackmd.io/@CoTAI/B1hrnbjJO#/) * [Laboratory](https://colab.research.google.com/drive/1PjxEzZ3Htod1yse37njz_1KQPuWsa8zQ) * [Homework](https://colab.research.google.com/drive/1Cq8cB3V5m_fdQ-YversPo3xsftGwy0DS?usp=sharing) ### Giới thiệu Cách tìm một hàm số trí tuệ: $X \xrightarrow{\text{B}} Z \xrightarrow{\text{P}} \hat{Y}$ Các cách trích xuất đặc trưng $B$ thường dùng: * Hand-crafted * Sparse coding * PCA: principle components * Convolutional kenels * Word embbedings ### Dimensionality Reduction (Giảm chiều dữ liệu) **Mục đích:** để nén các gói dữ liệu có thông tin lớn về một kích cỡ phù hợp để dễ dàng xử lý và phân tích ### Principal Component (PCA) Là phương pháp đơn giản nhất trong các thuật toán Giảm chiều dữ liệu, dựa trên mô hình tuyến tính **Định nghĩa**: tìm một hệ cơ sở mới mà ở đó, thông tin dữ liệu chỉ tập trung ở một vài hệ tọa độ, và phần còn lại chỉ mang một số ít thông tin ### Các bước thực hiện ## Session 3 -- Nonlinear Predictors * [Slide](https://hackmd.io/@CoTAI/By8dotTkO#/) * [Lab](https://drive.google.com/file/d/1wm0ZvW05FZkLwHTpkPuXneU9J2ziHwPz/view?usp=sharing) * [Homework](https://colab.research.google.com/drive/1sTpIRY1s5vUtRaAdzennAYIotzdysfBG?usp=sharing) ### 3.1 Mô hình phi tuyến(Nonlinear Regression) Định nghĩa: Một mô hình mà ở đó không thể phân nhóm bằng một mặt phẳng #### 3.1.1 Decision Boundary Vùng mà không quyết định được điểm đó thuộc class nào(niềm tin bằng nhau) * Linearly separable(DB là đường phẳng, mặt phẳng) * Nonlinearly separable (DB là đường cong, mặt phẳng cong) * Non-separable(không có DB, chấp nhận lỗi) #### 3.1.2 Regression Curves(Nonlinearly separable) Từ không gian $Z$ đưa thành không gian $Z'$ để nó trở thành Linearly separable $X \xrightarrow{\text{features}} Z$ Nonlinear transformation: trải, gỡ rối những vùng dữ liệu xoắn vào nhau $X \xrightarrow{\text{B}} Z \xrightarrow{\text{T}} Z' \xrightarrow{\text{L}} \hat{Y}$ $B,T,L: s(A\cdot z + b)$ #### 3.1.3Linear transformations: $Z$: phẳng $Z'$: phẳng $Z \xrightarrow{\text{A}} Z'=A\cdot Z$ $\to$ **Thầy HƯNG**: linear transformation đc thực hiện bằng phép nhân ma trận $Z'=AZ$ chứ ko phải phép so khớp bằng tích chấm $z=A\cdot X$ để trích xuất đặc trưng. Các loại: * Xoay/lật * Dãn * Xoay/lật #### 3.1.4 Nonlinear transformations: $Z$: phẳng $Z'$: méo A: $\phi =\gamma (Az+b)$ $\gamma$: activation (ReLU,...) Các loại: * Sigmoid * tanh * ReLU(phổ biến nhất) * Leaky ReLU * Maxout * ELU Không gian đầu vào Z $\to$ Không gian Z' mà có thể dùng linear để separate $\to \hat{y}$ ### 3.2 Nonlinear Predictors $\hat{y}=s(W'\phi(z) + b')$ * Feature engineer * MLP: $Z\rightarrow Z'\rightarrow Z''\rightarrow Z'''$=> không gian linearly separable Experiment with: https://news.ycombinator.com/item?id=11486058 * Kernel machines:$k(z^1,z^2)$ = similarity * Locally linear: chia nhỏ không gian đầu vào, mỗi vùng dùng một linear model khác nhau ### 3.3 Multilayer Perceptron (MLP) ![](https://i.imgur.com/IbURtGj.png) *Input layer*: dữ liệu nhập vào *Output layer*: dữ liệu đầu ra *Hidden layer*: các hàm biến đổi ## Session 4 - Reccommender System Các links: * [Practice lab video](https://drive.google.com/file/d/1XXvq0NsULugeaFIngkbwMyELJD_xEcCU/view?usp=sharing) * [practice lab](https://colab.research.google.com/drive/1Hlp77rr0ByHpFtDIAZaNOSuE-EcnsUSr?usp=sharing) * Lecture video: [part 1](https://drive.google.com/file/d/1uiEd6j-vC1Ok29gXzZMIKOX8mcxqziZv/view?usp=sharing), [part 2](https://drive.google.com/file/d/1Bham5EosRB9w002KzYnffJ-ebt8J_0DM/view?usp=sharing) * [Slide:](https://hackmd.io/@CoTAI/RecSys-ML4AI) * Tham khảo: [Neigborhood based](https://machinelearningcoban.com/2017/05/24/collaborativefiltering/), [Matrix based](https://machinelearningcoban.com/2017/05/31/matrixfactorization/), [Content based](https://machinelearningcoban.com/2017/05/17/contentbasedrecommendersys/) * [Homework](https://colab.research.google.com/drive/1VYgUqtY1bWmj5FqMff3uBaG0bz4nfCt0?usp=sharing) normalized utility $\hat{y}$: giá trị trung bình rating cho 1 item: mang thông tin về tính cách của user ### 4.1. Hiện tượng Long tail trong thương mại 80% doanh số của một công ty có thể được tạo ra chỉ từ doanh thu của 20% số lượng sản phẩm. 20% doanh số còn lại được tạo ra từ rất nhiều các sản phẩm không phổ biến còn lại, tạo thành cái đuôi dài, được gọi là hiện tượng **Long tail**. ### 4.2. RecSys taxonomy ![](https://i.imgur.com/DR6Rk28.png) Có 2 nhóm lớn: * Content based RecSys * Collaborative filtering ### 4.3. Collaborative Filtering (Neigborhood based) ĐN: xác định mức độ quan tâm của *user* tới một *item* dựa trên các *users* khác gần giống với *user* này.Việc *gần giống nhau* giữa các *users* có thể được xác định bằng mức độ quan tâm của các *users* lên các *items* khác mà hệ thống đã biết. * User-based: dựa trên thông tin của các *similar users* mà đưa ra dự đoán. * Item-based: dựa trên *item similarities* mà gợi ý các *items* mà gần giống với các *items* có mức độ quan tâm của user cao. * Model-based CF: dựa trên *phân tích ma trận thành phân tử* #### 4.3.0. ƯU KHUYẾT ĐIỂM ƯU ĐIỂM: * Đơn giản, dựa trên từng đặc trưng của item mà recommend cho user * có thể thực hiện trên mô hình nhỏ * không chịu ảnh hưởng của COLD START KHUYẾT ĐIỂM: * không khai thác được similarity giữa các *users* * Không phải lúc nào ta cũng có *bản mô tả* cho mỗi item để xây dựng *feature vector* Nếu utility matrix trống rỗng thì CF không dùng được: cold start **Pros**: Chỉ cần utility matrix sau đó tính toán ma trận, tiện lợi **Cons**: không dựa vào đặc trưng mà dựa vào neighborhood, cần sự tính toán lớn #### a. User-based Dựa trên mối quan hệ giữa các users mà đưa ra gợi ý **Similarity functions**: Xác định độ giống nhau giữa hai users. Như thế nào là một hàm *similarity* tốt ? B1: Xây dựng *feature vector* B2: tính **cosine similarity**: $cos(u_1,u_2)=\frac{u_1^Tu_2}{||u_1||_2 \cdot ||u_2||_2}$ (con số này này trong khoảng [-1,1]) **Rating prediction**: Tiếp theo, việc cần thiết của ta là dự đoán mức độ quan tâm của user $u_1$ lên một $item$ chưa có đánh giá (missing rating) dựa trên *k users* tương tự. VD k=2: > B1: xác định k các users tương tự nhất đã rated cho $item$ B2: xác định similarities của $u_1$ với các users này. B3: xác định normalized rating của các users này cho $item$. B4: Tính $\hat{y}$ #### b. Item-based Dựa trên *item similarities* mà gợi ý các *items* mà gần giống với các *items* có mức độ quan tâm của user cao. **Similarity Function**: xác định độ giống nhau giữa các *items*, rồi tính tương tự như User-based CF. **Rating Prediction**: dựa trên mối tương quan giữa các items, ta có thể thấy rằng similarity giữa $i_0$ và $i_1$ rất cao: 0.89, và rating của user cho $i_0$ là 5 thì khả năng người dùng cũng sẽ quan tâm tới $i_1$ ### 4.4. Matrix-based (CF) #### 4.4.1. Matrix Factorization Collaborative Filtering ### 4.5. Content-Based Filtering #### 4.5.0. ƯU KHUYẾT ĐIỂM ƯU ĐIỂM: * Đơn giản, dựa trên từng đặc trưng của item mà recommend cho user * có thể thực hiện trên mô hình nhỏ * không chịu ảnh hưởng của COLD START KHUYẾT ĐIỂM: * không khai thác được similarity giữa các *users* * Không phải lúc nào ta cũng có *bản mô tả* cho mỗi item để xây dựng *feature vector* #### 4.5.1. ITEM PROFILES Dựa trên các đặc trưng của item $k$ mà ta xây dựng hồ sơ (profile) cho nó, dưới dạng toán học là một *feature vector* ${\bf z}_k$. ## Session 5 - Evaluation metrics & Losses * [Slides](https://hackmd.io/@CoTAI/H1bEdCSM_) * Lecture video: [theory](https://drive.google.com/file/d/1naSevAn15dEk7gXvG9yixECtjRAvINqi/view?usp=sharing), [lab](https://drive.google.com/file/d/1-fwnI3Xn8ZV6RaITkSAUEom4-eEA0Lo1/view?usp=sharing) * [Practice Lab](https://colab.research.google.com/drive/17Ro39WwQjAVnM79jHhTD58ng1yB5jMt5) * [Homework](https://colab.research.google.com/drive/1M0oGx2arl1lUd6PFf9pWSHXeBATqBPqQ?usp=sharing) * [Machine Learning cơ bản ](https://) ### 5.1 Quy trình đánh giá ![](https://i.imgur.com/34wUpTW.png) ![](https://i.imgur.com/OZMxJjx.png) * Đầu vào của hàm đánh giá: predictor ${\bf f}(x^t)$ và dataset $D$: $P(D,f)$ * Đầu ra: a real number **Sự khái quát hóa** (Generalization): khả năng rút ra quy luật tổng thể từ bộ training dataset **Interpolation**(dữ liệu ta đưa cho máy và easier) $\to$ **extrapolation** $\to$ **combinatorics**(harder) VD: trong bài toán classification, giữa nhiều linear classifiers khác nhau, đường nào là tốt nhất $\to$ Đường có khoảng cách tới dữ liệu của 2 classes lớn nhất thì tốt nhất. ("large-margin" classifier) gamma: độ cong của decision boundary ### 5.2 Chuẩn đánh giá cho bài toán Regression #### 5.2.1 Các chuẩn đánh giá thường gặp ![](https://i.imgur.com/81QstQe.png) *Lưu ý*: MAE ít bị nhiễu nhưng khó để tối ưu ### 5.3 Chuẩn đánh giá cho bài toán Classification * Confusion matrix: thứ đầu tiên cần thiết lập để đánh giá một mô hình phân nhóm * Natural metric: accuracy(chỉ nên dùng cho balanced datasets) ### 5.4 Chuẩn đánh giá cho imbalanced datasets * Positive: vật đã được selected * True positive (TP): vật cần được selected * False positive (FP): vật ko cần được selected nhưng lại bị selected * Negative: vật đã bị ignored * True negatives (TN) * False negatives (FN) * Thresold: nếu thresold = 0.8 thì nếu xác suất của con chó > 0.8 thì mới xác định là con chó, nếu $\leq 0.8$ thì là class "không phải con chó". * Precision= $\frac {\sum TP}{\sum TP + \sum FP}$: độ chính xác * Recall= $\frac {\sum TP}{\sum TP + \sum FN}$: độ nhạy * $F_\beta$ score = $(1+\beta)^2 \frac{Precision \cdot Recall}{\beta^2 Precision + Recall}$ ( $\beta$: độ quan trọng của Precision) #### 5.4.1 Decision-making aspect Tùy ứng dụng mà Precision và Recall có độ quan trọng khác nhau ![](https://i.imgur.com/DEaZymg.png) #### 5.4.2 Dành cho multiclass classifiers **Ví dụ:** ![](https://i.imgur.com/cc96utB.png) | | Precision | Recall | F1 | | -------- | -------- | --- | -------- | | Chó | 1 | 0.75 | 6/7 | | Mèo | 0.75 | 0.75 | 0.75 | ### 5.5 Receiver Operating Characteristic (ROC) * True positive rate $TPR$ = Recall: * False positive rate $FPR$ = $1-\frac{TN}{TN + FP}=1- FNR$ $\to$ vẽ được đường đặc tính hoạt động Khi thay đổi các binary classification thresolds $\to$ $TPR$, $FPR$ thay đổi $\to$ các đường ROC vẽ được cũng khác nhau ![](https://i.imgur.com/nVQ3QiR.png) *Lưu ý:* Càng về phía perfect classifier thì càng tốt, còn ngược về phía random classifier thì càng tệ **Câu hỏi:** Thresold như thế nào là tốt nhất ? $\to$ Có nhiều phương pháp để tìm ra thresold tốt nhất. VD maximize G-Mean,... [others](https://stats.stackexchange.com/questions/123124/how-to-determine-the-optimal-threshold-for-a-classifier-and-generate-roc-curve). ### 5.6 Other metrics: Cho các bài toán Object Detection: IoU Cho các bài toán Machine Translation: BLEU ### 5.7 Chuyển các chuẩn đánh giá (metrics) thành các hàm mất mát (loss functions) trong bài toán phân lớp (classification) ![](https://i.imgur.com/hBHhwOG.png) Không gian là một hàm gồm những bậc thang $\to$ khó tìm model tốt nhất $\to$ chuyển qua smooth proxy losses: dễ để tối ưu hóa và tìm hàm tốt nhất Linear Predictors $\to$ (often) convex losses $\to$ global optimum #### 5.7.1 Hinge Loss và SVM Hinge Loss: ![](https://i.imgur.com/Djk40UV.png) * $y \in \{\pm1\}$; * $\hat{y}^t = sign({\bf w} \cdot {\bf x} - b)$ ( $sign()$: hàm lấy dấu) * $l_t = \max(0,1 - y({\bf w} \cdot {\bf x} - b))$ * Những điểm gần với Decision Boundary được gọi là **support vectors**. **Hung Ngo**'s notes: Notice the difference! The dot product is sum of **element-wise** product vs. matrix multiplication is sum of **row** element-wise product with column (hence the transpose): ${\bf w} \cdot {\bf x} = {\bf w}^\top {\bf x}$ #### 5.7.1 Nonlinear SVM and kernel tricks Z $\to$ Z' bởi $\phi(x)$ sau đó tính dot product giữa các đặc trưng trong Z' **Kernel tricks**: cho phép ta tính dot product mà không cần thông qua hàm biến đổi $\phi(x)$ ![](https://i.imgur.com/VNKKZab.png) ## Session 7 - Optimization and training * [Slide](https://hackmd.io/@CoTAI/S1sLTnFXd#/) * [Practice Lab](https://colab.research.google.com/drive/1viiH90CtotEfwVSsF7vtK9gfJR6OGCrw?usp=sharing) * [Homework](https://colab.research.google.com/drive/1F4cX_dnWSrED9UT8EtJVXH0PQFyRNFPP#scrollTo=tVsDi9ArTVNI) Giải thuật WORK HORSE (giải thuật dựa vào đạo hàm Lớp cuối cùng: fully-connected Tìm một hàm tốt: sai số trên bộ dữ liệu và test set đều nhỏ Từ một điểm đưa vào tính ra sai số -> vẽ được một loss surface -> tìm điểm có loss thấp nhất Task: trong không gian hàm số đi đến được điểm hình chiếu của điểm trũng nhất trong loss surface Experience: Function Space: Performance: Algorithm: $\theta^* = argminJ(\theta; X,y)$ Dành cho mặt phẳng láng: dùng ý tưởng của nước chảu về nơi trũng nhất Hướng dốc nhất: hàm lỗi thay đổi nhanh nhất Note: tìm hiểu về đạo hàm T T Hướng vector vận tốc: hướng thay đổi nhanh nhất => Tốc độ thay đổi hàm số theo từng hướng trong không gian $\theta$ TÌm vector vận tóc thay đổi của hàm số như thế nào? TÌm từng thành phần Đạo hàm cho ta tốc độ thay đổi của hàm số tại một điểm Vector vận tốc của hàm số: Gradient vector: vector vận tốc không gian tham số $\theta$ Đi ngược hướng Gradient vector để tìm về nơi có loss thấp nhất Điểm tối ưu: nơi có gradient bằng 0 Đi trong không gian tham số: đi một bước rất nhỏ () Backpropagation: cho phép ta update MLP Vấn đề learning rate: quá nhỏ: đi chậm quá lớn: oscillate batch $\to$ mini-batch $\to$ SGD: chỉ lấy 1 cái $x^t, y^t$ momentum: phần duy trì của những bước trước (vượt qua local minimum) Khi huấn luyện tắt một vài node random khiến cho máy học những thuộc tính ổn định hơn -> mang generalize tốt hơn: dropout ## Session 8 - Convolutional neural networks * [Slide](https://hackmd.io/@CoTAI/ryP0MgHfd#/16) * [Lab](https://colab.research.google.com/drive/1tyBeAKSPyy06lZ_zq3PHLxewxfkyqsRj?usp=sharing) * [Homework](https://colab.research.google.com/drive/1arhkU7W2Yb6uLK1goHZ_LeJslpYXiW6x) Convolution: tích chập Filter: luôn là hình vuông, số lẻ Trượt theo một chiều: convolution 1D, trượt ngang, dọc: convolution 2D chiều ngang chiều dọc của filter là số lẻ=> điểm được quét là điểm ở chính giữa Phép đệm: giữ được kích thước đầu vào, giữ được thông tin của cạnh đó (padding) output: input - 2 padding Stride: sải chạp nhảy qua k ô tiếp theo cách filter di chuyển tốc độ thu nhỏ dữ liệu ![](https://i.imgur.com/xBcWSaT.png) Layer pooling: đưa input vào pooling kích thước bị giảm phân nửa (max: sharp feature, avg: smooth feature) => để quét cho nhanh Stride = 2 (mặc định) Tại sao không dùng k=2 mà dùng pooling: vì dùng filter thì cần học, cong pooling thì không cần CNN tốt hơn trong TH hình ảnh Tại sao quét nhiều lần: - Receptive field: mỗi chấm càng về sau tượng trưng cho một phần của tấm hình ban đầu problem của CNN: khi xáo trộn thì vẫn đưa ra kết luận ## Session 9 - Recurrent neural networks (RNNs) * [Slide](https://hackmd.io/@CoTAI/B188QSnNO#/1) * [Laboratory](https://colab.research.google.com/drive/1mSLmqq39ZnokfPZeoB7Mf1WZJyz6mT95) * [Homework](https://colab.research.google.com/drive/1TOZ1MAWgFvvcWeZPz-Ey3uBlg1HV0s4t?usp=sharing) Chuỗi dự báo: chuỗi các khái niệm theo thời gian RNN: cho phép đưa ra hành động ( theo chiều thời gian) ### 1. Sequential Data - Dữ liệu có tính chuỗi (Âm thanh, giọng nói, giá vàng, nhu cầu,...) Cho phép xử lý dữ liệu theo tính chuỗi và đưa ra dự báo VD: robot muốn cầm được một vật, cần một chuỗi hành động Di chuyển trong không gian khái niệm: để có thể sinh ra những khái niệm mới liên quan đến nhau Chiều thời gian: cho phép tạo ra sự liên quan giữa các đầu ra Di chuyển trong không gian: thêm một lượng delta rất nhỏ -> sáng tạo Công thức toán RNNs: $h_{t-1} \to h_t = \gamma (Uh_{t-1} + Wx_t + b)$ * Mô hình feed-forward thành recurrent: Lấy z của mô hình trước đưa vào làm input, tất cả các vòng đều sử dụng cùng một bộ trọng số (Weight sharing in time) ![](https://i.imgur.com/z4QfHOT.png) ### 9.2. Vanilla RNN (model) Sử dụng Backpropagation(through time) ### 9.3. Vanishing Gradient Problem Vấn đề: khi truyền ngược dài về sẽ bị suy hao, càng nhân thì gradient sẽ càng giảm( vanishing Gradient) Càng nhân càng lớn (Exploding Gradient) Problem: short term memory: chỉ học được cái gì xảy ra ở gần ban đầu ### 9.4. Introduction to LSTM & GRU LSTM: sửa Exploding, Vanishing Gradient và short-term memory ## Session 10 - K-means Clustering: Unsupervised Learning * [Slide](https://hackmd.io/@CoTAI/rkqW32RSO#/) * [Colab](https://colab.research.google.com/drive/1Bfc7-zJaXMjlis9D7eVrdq_rSRlILOcJ) Ứng dụng: tìm đặc trưng chính, giảm chiều dữ liệu, segmentation ### 10.1 Định nghĩa clustering & k-means clustering Từ những đặc trưng Z, máy tự đưa vào những vùng khái niệm khác nhau $\to$ chúng ta tự diễn giải khái niệm Biểu diễn 1 cụm ntn: Có 1 W đại diệm cho từng cụm Mỗi input thuộc cụm nào: dot product $\to$ simarity $\to$ argmax similarity * K-means clustering: * 1 cụm = 1 centroid = trung bình của tất cả các điểm trong cụm * Input thuộc về cụm có khoảng cách từ centroid đến nó gần nhất (Euclidean distance) ![](https://i.imgur.com/h33r7CH.png) Cách khởi tạo centroid: * Lấy k centroid bất kỳ trong không gian * Lấy k centrod bất kỳ từ bộ dữ liệu ### 10.2 Performance metrics * Giữa các phần tử trong nhóm phải có sự liên kết * GIữa các nhóm phải có sự phân chia rõ ràng Simplest Metrics: tổng khoảng cách các điểm đến centroid là nhỏ nhất *Cách chọn k cụm:* có thể dùng nhiều cách khác nhau nhưng chủ yếu vẫn là dùng thư viện ## Session 11 - MDP Planning * [Laboratory](https://colab.research.google.com/drive/1zVDS25hDNqYDcmO_5SsXVq2b04UgKcKB) * [Slide](https://hackmd.io/@CoTAI/H1UYeaDGu#/1) * [Homework](https://colab.research.google.com/drive/1ZoBuuXHtupY3CM1LEuRjse8N2aJx5YDC#scrollTo=xpySD-p9_4fk) Từ $\hat{y}$ phải dự báo được hành động nào là tốt nhất: X(input) $\to$ Z $\to \hat{y} \to$ Action ### 11.1 Planning Planning: chuỗi các hành động đạt được kết quả mong muốn một cách hiệu quả nhất, bao gồm: * Actions * Goal, performance measure * Trạng thái ( $Z$ ), $\hat{y}: policy \space \pi$ * Kế hoạch ( $policy$ )($cần \space Transition \space Model$ ) ### 11.2 MDP S: state A: action T: transition R: reward $\gamma$: discount factor: nhấn mạnh model lấy được reward lớn hơn thì tốt Tại mỗi trạng thái S ta cần thực hiện hành động A sao cho tổng R tại $S_{t+1}$ lớn nhất Mô hình toán: * $policy \space \pi (s_t) \to a_t$ * tính tổng reward trong tương lai (Bellman equation) *Ghi chú: Khi không tính q, vẫn có cách tính policy thông qua S, A, T, R*: **policy search** & **imitation learning** (RL method, particularly popular for robotics). ![](https://i.imgur.com/phqRp8G.png) ## AI FINAL THEORY TEST **1.The unified TEFPA framework to build a ML model: task $\mathcal{T}$, experience $\mathcal{E}$, function space $\mathcal{F}$, performance $\mathcal{P}$, and algorithm $\mathcal{A}$ to search**. - 1.1 [**2** Point, 3.1] to build a face recognition model using a DCNN? - Task: recognize faces (input: pictures of face, output: who is the person in the picture) - Experience: face samples - Function Space: - Performance: Tỉ lệ nhận diện đúng người - Algorithm: DCNN - 1.2 [**2** Point, 3.1] to build a RecSys? (using one of the models you have learned: item-based, user-based, content-based, MF) - Task: tính toán sự giống nhau giữa các người dùng (input: vector những món đồ của người dùng đã mua, output: những người dùng có xu hướng mua đồ giống nhau) - Experience: user's history shopping list sample - Function Space: vector of features - Performance: Độ hài lòng với giới thiệu của hệ thống - Algorithm: KNN - 1.3 [**2** Point, 3.1] to build a customer segmentation model using k-means? - Task: chia nhóm khách hàng - Experience: Dữ liệu khách hàng đã mua đồ gì - Function Space: - Performance: - Algorithm: KNN - 1.4 [**2** Point, 3.1] to build a sentiment analysis model (good, bad, neutral comments) using RNN+Softmax Classifier? - Task: recognize faces (input: pictures of face, output: who is the person in the picture) - Experience: labeled comments (good, bad, neutral) - Function Space: features - Performance: tỉ lệ dự đoán đúng comments - Algorithm: RNN+Softmax Classifier **2. CONVOLUTIONAL FILTER** - 2.1: - 2.2: Feature maps: mỗi điểm của output tượng trưng cho rất nhiều đặc trưng(feature) của tấm hình ban đầu nên output được gọi là feature map - 2.3: Padding: thêm một vòng đệm ở bên ngoài input Mục đích: tránh thất thoát thông tin ở cạnh, giữ nguyên hoặc tăng kích thước input - 2.4: Pooling: phép gộp gồm max-pooling và average pooling Mục đích: giảm kích thước đầu vào, giảm ảnh hưởng từ các sai lệch nhỏ - 2.5: Stride: sải chạp, nhảy qua k ô tiếp theo Mục đích: đẩy nhanh tốc độ thu nhỏ dữ liệu - 2.6: Receptive field: mỗi điểm của output tượng trưng cho các features của một khu vực trong input nên nó thường rất trừu tượng **3. Recurrent neural networks (RNNs) can be used for sequential modeling.** - 3.1: Sequential data: dữ liệu mà ở đó thứ tự rất quan trọng (VD: thời gian) - 3.2: $h_t = \mathsf{\gamma}(Ah_{t-1}+Wz_t)$ $h_t$: hidden layer $\gamma$: hàm nắn không gian (relu, sigmoid,...) $A, \space W$: bộ trọng số (không đổi) $h_{t-1}$: output của layer trước $z_t$: thông tin mới - 3.3 back-propagation-through-time: báo cáo lỗi lại với các time-steps trước trong quá trình training Ta cần nó để có thể cập nhật các bộ trọng số tốt hơn, cuối cùng bộ trọng số tốt nhất sẽ được đưa vào model RNN - 3.4 Vanishing Gradient: khi truyền ngược dài về gradient sẽ bị suy hao, càng nhân thì gradient sẽ càng giảm 3.5 **4. Planning in Markov Decision Process (MDP) $(S,A,T,R,\gamma)$** 4.1: S: trạng thái A: hành động cần làm T: transition, xác suát để đi từ state này sang một state khác $\gamma$: discount factor: nhấn mạnh model lấy được reward lớn hơn thì tốt 4.2: $a_t = policy \space \pi (s_t)$ 4.3 4.4: $\pi ^*= argmax \space q^\pi(s,a)$ 4.5: bởi vì $Q^\pi(s,a)$ phải đi từng hành động có thể trong tương lai để có thể tính được số reward và trả về 4.6: $\gamma = 1$: nhấn mạnh reward, khiến model cố gắng lấy được reward lớn nhất $\gamma = 0$: ngược lại cái trên **5. Unified ML models** $\text{Input } X \xrightarrow[B_{\beta}]{\text{Features}}\text{ Embedding Coordinates }Z \xrightarrow[P_{\theta}]{\text{Predictor}}\text{ Predictions }\hat{Y} \xrightarrow[{\pi^*}]{\text{Policy}}\text{ Action }A$ - 5.1 [**2** Points] List all *taught* algorithms for feature extraction and their main ideas. - Principle Components Analysis (PCA): create characteristic p - Hand-crafted: tự tìm những features cần trích xuất - Word embeddings: là một không gian vector dùng để biểu diễn dữ liệu có khả năng miêu tả được mối liên hệ, sự tương đồng về mặt ngữ nghĩa, văn cảnh(context) của dữ liệu. - Sparse coding: Embedding coordinates with very few nonzeros (i.e., sparse) coefficients - Convolutional kernels: Inner product + sliding in time/space of input domain = feature map - 5.2 [**2** Points] List all *taught* algorithms for making predictions and their main ideas. - Linear and non-linear predictor: - Support Vector Machine (SVM): - 5.3 [**2** Points] What are the main *general* differences between linear predictors? And in your opinion why do we need different algorithms? - Linear and non-linear predictors: decission boundary của linear predictor là đường thẳng, còn DB của non-linear predictor là đường cong. - 5.4 [**1** Points] For MDPs, what are the predictions $\hat{Y}$ used to make decisions $A$?

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully