R

랜덤 포레스트를 이용한 위스콘신 유방암 데이터 분석

이부일 2017. 8. 29. 17:19

위스콘신 유방암 데이터(Wisconsin Breast Cancer Data)를 이용하여 암(악성, 양성)을 예측하는 것을 랜덤 포레스트(random forest)를 이용하여 분석하는 과정은 다음과 같다.


install.packages("randomForest")
install.packages("ROCR")
library(randomForest)
library(ROCR)


# 랜덤 포레스트
wdbc.random.forest <- randomForest::randomForest(class ~., data = train)
wdbc.random.forest


# 그래프 : 오차율 감소와 설명변수의 중요도
plot(wdbc.random.forest)
randomForest::varImpPlot(wdbc.random.forest)

자동 대체 텍스트를 사용할 수 없습니다.


자동 대체 텍스트를 사용할 수 없습니다.


# 모형평가
rf.Y.hat <- predict(wdbc.random.forest, newdata = validation, type = "prob")[ , "1"]
rf.prediction <- ROCR::prediction(rf.Y.hat, validation$class)
ROCR::performance(rf.prediction, "auc")@y.values[[1]]


[출처] 실리콘밸리 데이터과학자가 알려주는 따라 하며 배우는 데이터과학, 권재명 지음, 제이펍, p238~239