Introduktion till avvikelsedetektering i R
Alastair Rushworth
Data Scientist
Klass för en enskild kolumn
class(sat$V1)
"numeric"
Klass för alla kolumner
sapply(X = sat, FUN = class)
label V1 V2 V3 V4 V5 V6 high_low
"numeric" "numeric" "numeric" "numeric" "numeric" "numeric" "numeric" "character"
Koda kategoriska särdrag som faktor
sat$high_low <- as.factor(sat$high_low)class(sat$high_low)
"factor"
Träna isolation forest
sat_for <- iForest(sat[, -1], nt = 100)
Gower-avstånd mäter avstånd mellan punkter med kategoriska och numeriska särdrag
library(cluster)
sat_dist <- daisy(sat[, -1], metric = "gower")
Skicka sat_dist till lof
sat_lof <- lof(sat_dist, k = 10)
sat_distmat <- as.matrix(sat_dist)
range(sat_distmat)
0.0000000 0.8680774
Introduktion till avvikelsedetektering i R