这是我第一次接近R中的ROCR曲线并使用
#ROCR Curve
library(ROCR)
predict_rf <- predict(Model_RF, type = 'response')
ROCRpred_rf <- prediction(predict_rf, test.5$si2014)
ROCRperf_rf <- performance(ROCRpred_rf, 'tpr','fpr')
plot(ROCRperf_rf, colorize = TRUE, text.adj = c(train-0.2,1.7))
我得到了
> #ROCR Curve
> library(ROCR)
>
> predict_rf <- predict(Model_RF, type = 'response')
>
> ROCRpred_rf <- prediction(predict_rf, test.5$si2014)
Error in prediction(predict_rf, test.5$si2014) :
Format of predictions is invalid.
我使用RandomForest模型来预测因子变量(si2014)。 这是我用于预测的数据集。
> sapply(test.5, class)
spesa_tot n_visite importo sesso eta_abbonati
"numeric" "numeric" "numeric" "factor" "numeric"
si2014 mesi_tot Residenza cluster
"numeric" "integer" "factor" "factor"
问题是什么?使用SVM模型我完全没有问题....
答案 0 :(得分:0)
我解决了。 很容易。只是做
predict_rf <- predict(Model_RF, type = 'response')
predict_rf
ROCRpred_rf <- prediction(as.numeric(predict_rf), as.numeric(train.4$si2014))
ROCRperf_rf <- performance(ROCRpred_rf, 'tpr','fpr')
plot(ROCRperf_rf, colorize = TRUE, text.adj = c(train.4-0.2,1.7))
我修改了
ROCRpred_rf&lt; - 预测(predict_rf,test.5 $ si2014)
带
ROCRpred_rf&lt; - 预测(as.numeric(predict_rf),as.numeric(train.4 $ si2014))