범주형 특성 다루기

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"
R로 시작하는 이상치 탐지 입문

Isolation Forest

범주형 특성을 factor로 인코딩

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

class(sat$high_low)
"factor"

Isolation Forest 학습

sat_for <- iForest(sat[, -1], nt = 100)
R로 시작하는 이상치 탐지 입문

요인과 함께 LOF

Gower 거리는 범주형·수치형 특성이 섞인 점들 간 거리를 측정합니다

 

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

sat_distlof에 전달

sat_lof <- lof(sat_dist, k = 10)

R로 시작하는 이상치 탐지 입문

Gower 거리 행렬 탐색

  • 객체를 행렬로 변환
sat_distmat <- as.matrix(sat_dist)

 

  • 점간 최대·최소 거리 구하기
range(sat_distmat)
0.0000000 0.8680774
R로 시작하는 이상치 탐지 입문

실습해 봅시다!

R로 시작하는 이상치 탐지 입문

Preparing Video For Download...