我正在使用 caret 包来训练模型,并希望获得模型的准确性。我听说的一种常见方法是使用confusionMatrix。然而,当我运行下面的代码时,经过训练的模型给出了一些与confuseMatrix() 报告的精度值略有不同的精度值。所以我的问题是我应该使用什么精度?如何解释模型直接在控制台中给出的准确性?
ModelRF_ALL_b <- train(price~.,method="rf",data=datatraining_b)
ModelRF_ALL_b
控制台报告如下
Random Forest
8143 samples
8 predictor
2 classes: '0', '1'
No pre-processing
Resampling: Bootstrapped (25 reps)
Summary of sample sizes: 8143, 8143, 8143, 8143, 8143, 8143, ...
Resampling results across tuning parameters:
mtry Accuracy Kappa
2 0.9948108 0.9843501
4 0.9945824 0.9836512
7 0.9940732 0.9821099
Accuracy was used to select the optimal model using the largest value.
The final value used for the model was mtry = 2.
我还可以运行confusionMatrix()
confusionMatrix(datatraining_b$price,
predict(ModelRF_ALL_b,datatraining_b))
它的准确度为 1。
Confusion Matrix and Statistics
Reference
Prediction 0 1
0 6414 0
1 0 1729
Accuracy : 1
95% CI : (0.9995, 1)
No Information Rate : 0.7877
P-Value [Acc > NIR] : < 2.2e-16
Kappa : 1
Mcnemar's Test P-Value : NA
Sensitivity : 1.0000
Specificity : 1.0000
Pos Pred Value : 1.0000
Neg Pred Value : 1.0000
Prevalence : 0.7877
Detection Rate : 0.7877
Detection Prevalence : 0.7877
Balanced Accuracy : 1.0000
'Positive' Class : 0