# UAS — Machine Learning (CSA) (2024/2025)

> Final Exam · Even Semester 2024/2025 · Universitas Gadjah Mada
> Source is a **3-page photo set** (`UAS_ML_2025(1).jpg`, `(2).jpg`, `(3).jpg`) of a single printed paper, merged here into one transcript.

| Field | Value |
|---|---|
| **Course** | Machine Learning — CSA |
| **Exam type** | Ujian Akhir Semester (UAS) / Final Examination |
| **Semester** | Semester II, Academic Year 2024/2025 |
| **Day, date** | Wednesday, 11 June 2025 |
| **Time** | 07.30 – 09.20 (110 minutes) |
| **Lecturer** | Afiahayati, M.Cs., Ph.D. |
| **Exam type (mode)** | Open 1 sheet of A4 hand-written notes, Open Calculator, Closed Book, Gadget OFF, Laptop OFF, Internet OFF |
| **Weight** | This final exam contributes **35 %** of the final grade |

**Institution:** University Elephant Mada · Faculty of Mathematics and Natural Sciences · Department of Computer Science and Electronics · IUP Computer Science

**Instructions:**
1. This final exam contributes 35% of your final grade
2. Please submit your A4 handwritten notes together with the answer sheet

---

*PLO2; CO-2: Students are able to understand data preparation and performance evaluation in machine learning (score: 10%).*

**1.** Please answer the questions below!

**a.** Look at Figure 1. Please write the output of the python code below, if the total number of data from the dataset is 500! *(score: 2%)*

```python
[ ] from sklearn.model_selection import train_test_split

X_train, X_test, y_train, y_test = train_test_split(X, y, train_size = 0.7)

[ ] print("Banyak data latih setelah dilakukan Train-Test Split: ", len(X_train))
    print("Banyak data uji setelah dilakukan Train-Test Split: ", len(X_test))
```

*Figure 1. Code Snippets of Data preparation*

**b.** Please explain about k-fold cross validation! When should we use k-fold cross validation? *(score: 3%)*

**c.** Look at Table 1. Table 1 represents the target and prediction results of a classification model. There are 2 classes, namely the YES class and the NO class. Create a Confusion Matrix from the classification results, then calculate the accuracy, sensitivity / recall, precision and F1-measure! *(score: 5%)*

*Table 1. Classification results table*

| No. | Target | Classification Results |
|---|---|---|
| 1 | NO | NO |
| 2 | NO | YES |
| 3 | YES | YES |
| 4 | YES | NO |
| 5 | YES | YES |
| 6 | NO | NO |
| 7 | NO | NO |
| 8 | YES | NO |
| 9 | YES | YES |
| 10 | YES | NO |
| 11 | YES | NO |
| 12 | YES | YES |

> *Worked check (not part of the source).* Reading rows against (Target, Prediction):
> TN = rows 1, 6, 7 → **3**; FP = row 2 → **1**; TP = rows 3, 5, 9, 12 → **4**; FN = rows 4, 8, 10, 11 → **4**. Total n = 12.
> Accuracy = (TP+TN)/n = 7/12 = **58.33 %**; Sensitivity/Recall = TP/(TP+FN) = 4/8 = **50 %**; Precision = TP/(TP+FP) = 4/5 = **80 %**; F1 = 2PR/(P+R) = **61.54 %**.

---

*PLO3; CO-5: Students are able to understand k-NN and apply it to solve a case (score: 4%).*

**2.** Determine whether the following statements are correct or wrong and give the reason

**a.** K-NN is more suitable used on large datasets because its high speed for prediction. *(score: 2%)*

**b.** K-NN must use the Euclidian Distance formula *(score 2%)*

---

*PLO3; CO-6: Students are able to understand Naive Bayes Model and apply it to solve a case (score: 5%).*

**3.** Given data as following (Table 2)

*Table 2. Play Tennis Data*

**PlayTennis: training examples**

| Day | Outlook | Temperature | Humidity | Wind | PlayTennis |
|---|---|---|---|---|---|
| D1 | Sunny | Hot | High | Weak | No |
| D2 | Sunny | Hot | High | Strong | No |
| D3 | Overcast | Hot | High | Weak | Yes |
| D4 | Rain | Mild | High | Weak | Yes |
| D5 | Rain | Cool | Normal | Weak | Yes |
| D6 | Rain | Cool | Normal | Strong | No |
| D7 | Overcast | Cool | Normal | Strong | Yes |
| D8 | Sunny | Mild | High | Weak | No |
| D9 | Sunny | Cool | Normal | Weak | Yes |
| D10 | Rain | Mild | Normal | Weak | Yes |
| D11 | Sunny | Mild | Normal | Strong | Yes |
| D12 | Overcast | Mild | High | Strong | Yes |
| D13 | Overcast | Hot | Normal | Weak | Yes |
| D14 | Rain | Mild | High | Strong | No |

**a.** Create a probability table from the playtennis data above. Then use the Naive Bayes Model to determine whether on days D15 and D16 it is advisable to play tennis or not with the following weather. *(Score: 3,5%)*

> D15: Outlook = Rain, Temperature = Mild, Humidity = Normal, Wind = Weak

**b.** In the beginning, Naïve bayes is designed for the categorical data. But Naïve bayes model also can be implemented for numerical data. Please explain, how is Naïve bayes implemented for numerical data? *(Score: 1,5%)*

> ⚠️ **Source defect:** the stem asks about **days D15 *and* D16**, but the weather specification line supplies **only D15**. D16's attribute values are absent from the paper, so the second half of the question is unanswerable as printed.

---

*PLO3; CO-7: Student are able to understand ensemble learning and apply it to solve a case (score 10%)*

**4. a.** Please explain the algorithms of bagging, boosting and stacking! Please also explain the diffencess! *(score: 3%)*

**b.** Look at Figure 2. Please explain what is the meaning of base classifier, n_estimators and learning rate! *(score: 2%)*

```python
adaboost_classifier = AdaBoostClassifier(
    base_classifier, n_estimators=50, learning_rate=1.0, random_state=42
)

adaboost_classifier.fit(X_train, y_train)
```

*Figure 2. Code Snippets of Adaboost*

**c.** Please pay attention to the following data. Please implement the Bagging algorithm for the data. Please use only 3 bootstrappings/single models! Please write the final prediction and calculate the accuracy! *(score: 5%)*

*Table 3. Data for Bagging Algorithm*

| Source Dataset | x | 2,4 | 3,1 | 3,7 | 4,4 | 5,2 | 5,8 | 6,4 |
|---|---|---|---|---|---|---|---|---|
| | y | 1 | 1 | 1 | -1 | -1 | -1 | -1 |

> **Note on decimal separator:** the `x` values are printed with **commas** as decimal marks (`2,4` … `6,4`), i.e. 2.4, 3.1, 3.7, 4.4, 5.2, 5.8, 6.4. The `y` values use a minus sign (ASCII hyphen) for −1.

---

*PLO3; CO-7: Student are able to understand clustering and apply it to solve a case (score 6%)*

**5. a.** Please explain what is the difference between clustering and classification? *(score: 3%)*

**b.** Please explain how to determine the optimal value of k in k-means clustering. Please loot at Figure 3. Based on the figure 3, please determine the optimal value of k! *(score: 3%)*

*Figure 3. Elbow method for optimal k*

**Elbow Method For Optimal k**

| Number of Clusters (k) | Sum_of_squared_distances *(read off the plot)* |
|---|---|
| 2 | 3000 |
| 3 | ~1700 |
| 4 | ~1450 |
| 5 | ~1220 |
| 6 | ~1050 |
| 7 | ~950 |
| 8 | ~880 |
| 9 | ~850 |

> The plot has **no printed data labels**; the values above are read off the gridlines and are approximate. There are **8 markers, at k = 2 … 9** (the x-axis is *labelled* only at 2, 4, 6 and 8). The axes are `Sum_of_squared_distances` (y, ticked 1000–3000) and `Number of Clusters (k)` (x). The elbow sits at **k = 3**, where the curve's steep initial drop (~3000 → ~1700) flattens sharply.

---

-- No effort will be vain --

## Transcription notes

- **Source:** `UAS_ML_2025(1).jpg` + `UAS_ML_2025(2).jpg` + `UAS_ML_2025(3).jpg` — three photographs of one printed paper, read visually and merged into a single transcript. Page boundaries fall mid-question: Q1c and its Table 1 are on page 1, Q2–Q4b on page 2, Q4c–Q5b on page 3.
- **Header quirk:** the paper prints **"UNIVERSITY ELEPHANT MADA"** — a literal English rendering of *Universitas Gadjah Mada* (*gadjah* = elephant) — rather than the usual "Universitas Gadjah Mada". Transcribed as printed.
- **Handwritten annotations are student workings, not question text** and have been excluded from the body. They include: the confusion-matrix tallies beside Table 1 (`TN = 3`, `FP = 1`, `TP = 4`, `FN = 4`, then per-row `TP`/`TN`/`FN` ticks), the class counts beside Table 2 (`k = 8`, `mild = 6`, `rain = 5`, `normal = 7`, `yes = 9`, `no = 5`), and the `bagging 1 / 2 / 3` jottings beside Table 3. These tallies are correct and are reproduced as a worked check under Q1c.
- **Tick marks** (✓) precede several sub-questions (1a, 1c, 2a, 2b, 3, 4a, 5a); these are marker/student annotations, not part of the printed text.
- **Q3a is defective:** it asks about "days D15 and D16" but only D15's weather is supplied.
- **Typos preserved as printed:** *"diffencess"* (Q4a), *"loot at"* (Q5b), *"Euclidian"* (Q2b), *"Naïve bayes"* (Q3b). Marked here rather than silently corrected.
- **Figure 3 values are estimated** — the chart carries no numeric data labels.
- **The worked arithmetic under Q1c is mine, not the source's**, and is included to verify the recorded table; the source supplies only the raw Target/Result rows.
- **Numbering oddity:** sub-questions `a`/`b`/`c` are used at Q1, then reused at Q4 and Q5, while Q2 and Q3 use `a`/`b` only. This is as printed.
