Encoder
Mô hình UML Endoder
Yêu cầu: Tạo lớp abstract generic Encoder chứa các phương thức Fit, Transform, FitTransform và inverse như trong mô hình UML. Sau đó Cài đặt các lớp cụ thể như LabelEncoder, OneHotEncoder, OrdinalEncoder các quy tắc tính toán được hướng dẫn cụ thể được mô tả phía dưới.
1. LabelEncoder (3 điểm)
Quy tắc chuyển đổi
Ví dụ
| Input | Aqua | Blue | Dune | Dune | Cyan | Aqua | Aqua | Cyan | Cyan |
| Transform | 0 | 1 | 2 | 2 | 3 | 0 | 0 | 3 | 3 |
| Inverse | Aqua | Blue | Dune | Dune | Cyan | Aqua | Aqua | Cyan | Cyan |
2. OneHotEncoder (3.5 điểm)
Quy tắc chuyển đổi
| Aqua | 1 | 0 | 0 | 0 |
| Blue | 0 | 1 | 0 | 0 |
| Dune | 0 | 0 | 1 | 0 |
| Cyan | 0 | 0 | 0 | 1 |
Ví dụ
| Input | Transform | Inverse |
| Aqua | 1 | 0 | 0 | 0 | Aqua |
| Blue | 0 | 1 | 0 | 0 | Blue |
| Dune | 0 | 0 | 1 | 0 | Dune |
| Dune | 0 | 0 | 1 | 0 | Dune |
| Cyan | 0 | 0 | 0 | 1 | Cyan |
| Aqua | 1 | 0 | 0 | 0 | Aqua |
| Aqua | 1 | 0 | 0 | 0 | Aqua |
| Cyan | 0 | 0 | 0 | 1 | Cyan |
| Cyan | 0 | 0 | 0 | 1 | Cyan |
3. OrdinalEncoder (3.5 điểm)
Quy tắc chuyển đổi
(Sắp xếp các từ theo ký tự Alphabet)
Ví dụ
| Input | Aqua | Blue | Dune | Dune | Cyan | Aqua | Aqua | Cyan | Cyan |
| Transform | 0 | 1 | 3 | 3 | 2 | 0 | 0 | 2 | 2 |
| Inverse | Aqua | Blue | Dune | Dune | Cyan | Aqua | Aqua | Cyan | Cyan |