AI

K nearest neighbors

Exercise 1: T Shirt size

Height (cm) Weight (kg) T shirt size
15858M
15859M
15863M
16059M
16060M
16360M
16361M
16064L
16364L
16561L
16562L
16565L
16862L
16863L
16866L
17063L
17064L
17068L
Chú thích: Dữ liệu gồm các cặp Chiều cao (cm), Cân nặng (kg) và nhãn kích thước áo (M hoặc L).

Bài toán (KNN, K = 3, khoảng cách Euclid)

Sử dụng KNN với K = 3 để dự đoán kích thước áo cho 2 người sau. Hãy dùng khoảng cách Euclid (tổng giá trị tuyệt đối hiệu theo từng chiều):

  1. Một người có chiều cao 161 cm và cân nặng 61 kg.
  2. Một người có chiều cao 164 cm và cân nặng 59 kg.

Khoảng cách Euclid giữa điểm (h, w) và một mẫu (hi, wi) là:

$$d = \sqrt{(h - h_i)^2 + (w - w_i)^2}$$

Exercise 1: Predicting Body Class using KNN

Height (CM) Weight (KG) Class
16751Underweight
18262Normal
17669Normal
17364Normal
17265Normal
17456Underweight
16958Normal
17357Normal
17055Normal
170 57 ?

Exercise 3: KNN Loan Default Prediction

Consider the training examples shown in the following table for a binary classification. The table shows a training set for a problem of predicting whether a loan applicant will repay his/her loan obligation or defaulting on his/her loan.

Tid Home Owner Marital Status Annual Income Defaulted Borrower
1YesSingle125KNo
2NoMarried100KNo
3NoSingle70KNo
4YesMarried120KNo
5NoDivorced95KYes
6NoMarried60KNo
7YesDivorced220KNo
8NoSingle85KYes
9NoMarried75KNo
10NoSingle90KYes

Using the kNN approach that we discussed in the class, predict the class label for this test example,
X = (Home Owner = No, Marital Status = Married, Income = $120K).
Assume that k = 3 and distance is L2 norm.

Exercise 4: Predict qualified

ID Speed Weight Qualified
12.50600no
23.75800no
32.25550no
43.25825no
52.75750no
64.50500no
73.50525no
83.00325no
94.00400no
104.25375no
112.00200no
125.00250no
138.25850no
145.75875yes
154.75625yes
165.50675yes
175.25950yes
187.00425yes
197.50800yes
207.25575yes

Test instance: X = (Speed = 5.20, Weight = 500). Use Min-max normalization, then apply KNN with k = 3, 5. Distance metric: Euclidean (L2 norm).

Exercise 5: Predict Weight

ID Height Age Weight
154577
25.112647
35.63055
45.93459
54.84072
65.83660
75.31940
85.82860
95.52345
105.63258
115.538?