kNN distance score
Once the kNN distance matrix is available, the nearest neighbor distance score can be calculated by averaging the nearest neighbor distances for each point.
Large values of the distance score can be interpreted as indicating the presence of unusual or anomalous points.
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
Introduction to Anomaly Detection in R
คำแนะนำการฝึกหัด
- Calculate the k-nearest neighbor distance score using the
rowMeans()function. - Print the row index of the point with the largest distance score.
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# Calculate the 5 nearest neighbors distance
wine_nn <- get.knn(wine, k = 5)
# Create score by averaging distances
wine_nnd <- rowMeans(___)
# Print row index of the most anomalous point