바이너리 예/아니오 클래스 응답이있는 데이터가 있습니다. RF 모델을 실행하기 위해 다음 코드를 사용합니다. 나는 혼란 행렬 결과를 얻는데 문제가있다.R 캐럿의 임의 포리스트에 대한 혼용 행렬
dataR <- read_excel("*:/*.xlsx")
Train <- createDataPartition(dataR$Class, p=0.7, list=FALSE)
training <- dataR[ Train, ]
testing <- dataR[ -Train, ]
model_rf <- train( Class~., tuneLength=3, data = training, method =
"rf", importance=TRUE, trControl = trainControl (method = "cv", number =
5))
결과 :
Random Forest
3006 samples
82 predictor
2 classes: 'NO', 'YES'
No pre-processing
Resampling: Cross-Validated (5 fold)
Summary of sample sizes: 2405, 2406, 2405, 2404, 2404
Addtional sampling using SMOTE
Resampling results across tuning parameters:
mtry Accuracy Kappa
2 0.7870921 0.2750655
44 0.7787721 0.2419762
87 0.7767760 0.2524898
Accuracy was used to select the optimal model using the largest value.
The final value used for the model was mtry = 2.
지금까지 좋은,하지만이 코드를 실행하면 내가 경우 감사
Error in model_rf[, 1] : incorrect number of dimensions
:
# Apply threshold of 0.50: p_class
class_log <- ifelse(model_rf[,1] > 0.50, "YES", "NO")
# Create confusion matrix
p <-confusionMatrix(class_log, testing[["Class"]])
##gives the accuracy
p$overall[1]
을 나는이 오류 친구들이 혼란 행렬 결과를 얻도록 도와 줄 수 있습니다.
'model_rf [, 1]'을 콘솔에 출력하고 살펴 봅니다. – jsb
질문에 [최소 재현 가능한 예] (https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)를 포함하면 도움이 될 것입니다. – jsb