J'ai des données avec la réponse binaire YES/NO Class. Utilisation du code suivant pour l'exécution du modèle RF. J'ai un problème pour obtenir le résultat de la matrice de confusion.Matrice de confusion pour la forêt aléatoire dans R Caret
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))
Résultats:
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.
Jusqu'à présent, très bien, mais quand je lance ce code:
# 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]
Je reçois cette erreur:
Error in model_rf[, 1] : incorrect number of dimensions
J'apprécie si vous les gars peuvent m'aider à obtenir le résultat de la matrice de confusion.
Imprime 'model_rf [, 1]' sur la console et regarde-la. – jsb
Si vous incluez un [exemple reproductible minimal] (https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) dans votre question, il serait plus facile de vous aider. – jsb