pontuação de distância k-nearest neighbors

Introduction to Anomaly Detection in R

Alastair Rushworth

Data Scientist

Dimensões de móveis

plot(Width ~ Height, data = furniture)

Introduction to Anomaly Detection in R

distância k-nearest neighbors (kNN)

Anomalias costumam ficar longe dos seus vizinhos

Introduction to Anomaly Detection in R

Entradas para calcular a matriz de distância

library(FNN)
furniture_knn <- get.knn(data = furniture, k = 5)

 

Argumentos

  • data: matriz de dados
  • k: número de vizinhos
Introduction to Anomaly Detection in R

Saída da matriz de distância

get.knn() retorna duas matrizes

names(furniture_knn)
"nn.index" "nn.dist" 

Matriz de distância

head(furniture_knn$nn.dist, 3)
         [,1]     [,2]     [,3]     [,4]     [,5]
[1,] 5.128300 5.367791 5.390801 5.740713 8.477025
[2,] 4.300093 5.367791 6.159139 7.091966 7.428176
[3,] 3.047502 3.545978 4.426266 5.006570 5.654202
Introduction to Anomaly Detection in R

pontuação de distância kNN

Distância média para os vizinhos mais próximos

furniture_score <- rowMeans(furniture_knn$nn.dist)

 

Maior pontuação?

which.max(furniture_score)
29
Introduction to Anomaly Detection in R

Vamos praticar!

Introduction to Anomaly Detection in R

Preparing Video For Download...