R 랜덤 포레스트

Jmnote (토론 | 기여)님의 2020년 5월 9일 (토) 00:08 판 (새 문서: ==개요== ;R Random Forest ;R 랜덤 포레스트 <source lang='r' run> set.seed(42) # 랜덤값 고정 library(rpart) # stagec df = stagec df = na.omit(df) # 결측치 제거 #...)
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

1 개요

R Random Forest
R 랜덤 포레스트
set.seed(42) # 랜덤값 고정
library(rpart) # stagec
df = stagec
df = na.omit(df) # 결측치 제거

# 데이터 분할
library(caret, quietly=T)
idx = createDataPartition(df$ploidy, p=0.7, list=FALSE)
trainData = df[ idx,]
testData  = df[-idx,]

# 모델 적
library(randomForest)
model = randomForest(ploidy ~ ., trainData, ntree=100, proximity=T)

options(echo=T)
# 모델 정보
model
model$importance

# 시각화
plot(model)

# 테스트
pred = predict(model, testData)
# 분류표
table(pred, testData$ploidy)
# 정분류율
sum(pred==testData$ploidy)/nrow(testData)


2 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}