我使用相同的训练和测试集,但由于某种原因,每次运行时混淆矩阵和输出图都不同。每次迭代都实现两种精度:
fit_rpart <- train(goodbad~.,method='rpart',data=training, control = rpart.control(maxdepth = 30, minsplit=30, minbucket=1, cp=0.001))
fancyRpartPlot(fit_rpart$finalModel)
pred_rpart <- predict(fit_rpart, testing)
confusionMatrix(pred_rpart, testing$goodbad, positive = 'bad')
答案 0 :(得分:1)
rpart
使用随机抽样。在每次运行之前使用set.seed
,每次都应该获得相同的模型。
set.seed(100)
fit_rpart <- train(goodbad~.,method='rpart',data=training, control = rpart.control(maxdepth = 30, minsplit=30, minbucket=1, cp=0.001))
fancyRpartPlot(fit_rpart$finalModel)
pred_rpart <- predict(fit_rpart, testing)
confusionMatrix(pred_rpart, testing$goodbad, positive = 'bad')