我正在使用R插入符号交叉验证恶意软件系列。我现在正在尝试生成混淆矩阵,并且我不断收到以下错误:
Error in confusionMatrix.default(crossval[[3]][[1]], data_train[, 1]) :
The data contain levels not found in the data.
这是我的代码:
#setwd("Malware/")
library(caret)
library(klaR)
library(randomForest)
# load the iris dataset
malware <- read.table('C:/Users/awais/Desktop/Malware/1.csv',sep=",",header=TRUE)
malware = na.omit(malware)
malware$labels <- as.factor(malware$labels)
# define an 80%/20% train/test split of the dataset
split=0.80
trainIndex <- createDataPartition(malware$labels, p=split, list=FALSE)
data_train <- malware[ trainIndex,]
data_test <- malware[-trainIndex,]
# Perform Cross Validation
crossval <- rfcv(data_train[,2:1025],data_train[,1],cv.fold=2, do.trace=TRUE, ntree=100)
# print out OOB error result for number of features
print(crossval[[2]])
# get the resulting confusion matrix for the cross validation
results <- confusionMatrix(crossval[[3]][[1]],data_train[,1])
write.table(results[[2]],file="predict_crossval.csv",sep=",")