尝试使用 RandomForest 预测模型的准确性,但遇到以下错误。
错误:data和reference应该是水平相同的因素。
这是以下代码
rfModel <- randomForest(Churn ~., data = training)
print(rfModel)
pred_rf <- predict(rfModel, testing)
caret::confusionMatrix(pred_rf, testing$Churn)
testing$Churn
Run Code Online (Sandbox Code Playgroud)
训练和测试数据按 7:3 的比例分割
运行代码时也收到以下警告
Warning messages:
1: In get(results[[i]], pos = which(search() == packages[[i]])) :
restarting interrupted promise evaluation
2: In get(results[[i]], pos = which(search() == packages[[i]])) :
internal error -3 in R_decompress1
Run Code Online (Sandbox Code Playgroud)
测试数据结构
str(testing)
'data.frame': 999 obs. of 18 variables:
$ account_length : int 84 75 147 141 65 62 85 93 76 73 ... …Run Code Online (Sandbox Code Playgroud)