我在使用confusionMatrix
时收到错误但却失去了它的说法:
R:sort.list(y)出错:' x'必须是原子的
以下是我采取的步骤
# Cleaning the environment
rm(list = ls())
# Reading the data
hr <- read.csv('C:/HR_comma_sep.csv')
View(hr)
# load library randomForest
library(randomForest)
# Attaching the data
attach(hr)
head(hr)
left <- as.data.frame(unlist(hr$left))
set.seed(27)
rf <- randomForest(left~., data = hr, mtry = 4, ntree = 500, importance = T)
plot(rf)
varImpPlot(rf, sort = T, main = "Variable Importance", n.var = 5)
hr$predicted.response <- predict(rf, left)
library(lattice)
library(ggplot2)
library(caret)
library(e1071)
# Confusion matrix for accuracy calculation
confusionMatrix(data = hr$predicted.response, reference = left,positive ='yes')