Werken met categorische features

Introductie tot anomaliedetectie in R

Alastair Rushworth

Data Scientist

Kolomklassen controleren

Klasse van één kolom

class(sat$V1)
"numeric"

Klasse van alle kolommen

sapply(X = sat, FUN = class)
      label          V1          V2          V3         V4          V5          V6    high_low
  "numeric"   "numeric"   "numeric"   "numeric"  "numeric"   "numeric"   "numeric" "character"
Introductie tot anomaliedetectie in R

Isolation forest

Categorische features als factor encoderen

sat$high_low <- as.factor(sat$high_low)

class(sat$high_low)
"factor"

Isolation forest trainen

sat_for <- iForest(sat[, -1], nt = 100)
Introductie tot anomaliedetectie in R

LOF met factors

Gower-afstand meet afstand tussen punten met categorische en numerieke features

 

library(cluster)
sat_dist <- daisy(sat[, -1], metric = "gower")

Geef sat_dist door aan lof

sat_lof <- lof(sat_dist, k = 10)

Introductie tot anomaliedetectie in R

Gower-afstandsmatrix verkennen

  • Object omzetten naar matrix
sat_distmat <- as.matrix(sat_dist)

 

  • Max. en min. afstand tussen punten vinden
range(sat_distmat)
0.0000000 0.8680774
Introductie tot anomaliedetectie in R

Laten we oefenen!

Introductie tot anomaliedetectie in R

Preparing Video For Download...