首页 > 解决方案 > R中ROCR曲线的预测格式

问题描述

这是我第一次在 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 模型我完全没有问题......

标签: rpredictionpredictfactors

解决方案


我解决了。很容易。做就是了

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 <- 预测(predict_rf,test.5$si2014)

ROCRpred_rf <- 预测(as.numeric(predict_rf),as.numeric(train.4$si2014))


推荐阅读