Rで学ぶ異常検知入門
Alastair Rushworth
Data Scientist
単一列のクラス
class(sat$V1)
"numeric"
全列のクラス
sapply(X = sat, FUN = class)
label V1 V2 V3 V4 V5 V6 high_low
"numeric" "numeric" "numeric" "numeric" "numeric" "numeric" "numeric" "character"
カテゴリ変数をfactorに変換
sat$high_low <- as.factor(sat$high_low)class(sat$high_low)
"factor"
isolation forestを学習
sat_for <- iForest(sat[, -1], nt = 100)
Gower距離 はカテゴリと数値の特徴が混在する点間距離を測定します
library(cluster)
sat_dist <- daisy(sat[, -1], metric = "gower")
sat_dist を lof に渡す
sat_lof <- lof(sat_dist, k = 10)
sat_distmat <- as.matrix(sat_dist)
range(sat_distmat)
0.0000000 0.8680774
Rで学ぶ異常検知入門