r - 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 模型我完全没有问题......
解决方案
我解决了。很容易。做就是了
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))
推荐阅读
- java - 从具有所有 java 依赖项的 JavaFX 文件 Maven 创建一个 .jar
- database - 导入到 phpMyAdmin
- r - 范围字符串到单个拆分
- python - 将索引为数组的 3d numpy 数组切片并重塑
- python - 使用 AWS Lambda 从 HTML 创建 PDF 并使用 Python 使用 S3 存储桶中的 imgs
- python - 尽管尺寸正确,但 Numpy 不会乘以矩阵
- c# - 已部署的 ASP.NET Core MVC 应用程序的运行时错误;在 VS '19 中调试期间不会发生
- node.js - Express:4.17:将变量传递给下一个函数返回未定义(中间件)
- mysql - 获取第二列中所有行的总和到第三列
- url - 如何将此按钮链接到 URL?引导程序 4