天道酬勤,学无止境

proc-r-package

R 中的 SVM:“预测器必须是数字或有序的。”(SVM in R: “Predictor must be numeric or ordered.”)

问题 我是 R 的新手,遇到了这个问题:我想比较两种预测技术(支持向量机和神经网络)将它们应用于一些数据,我想比较它们的性能。 为此,我使用 ROC 曲线。 该代码应该计算 ROC 曲线下的面积,但它不起作用。 神经网络代码工作正常,但是当 SVM 部分执行时出现以下错误: > aucs <- auc((dtest$recid=="SI")*1, lr.pred) roc.default(response, predictor, auc = TRUE, ...) 中的错误:预测器必须是数字或有序的。 > obj.roc <- roc((dtest$recid=="SI")*1, lr.pred ) roc.default((dtest$recid == "SI") * 1, lr.pred) 中的错误:预测器必须是数字或有序的。 这是我的代码。 library(stats) library(pROC) library(nnet) library(e1071) library(rpart) data <- read.table("data.csv", header=T) set.seed(1234) ind <- sample(2, nrow(data), replace=TRUE, prob=c(0.8, 0.2)) dtrain <- data[ind==1,] dtest <-

2021-09-16 10:14:25    分类:技术分享    r   svm   roc   proc-r-package

SVM in R: “Predictor must be numeric or ordered.”

I'm new to R and I've ran into this problem: I want to compare two prediction techniques (Support Vector Machines and Neural Networks) applying them to some data and I would like to compare their performance. To do this, I use ROC curves. The code is supposed to compute the area under the ROC curve but it is not working. Neural networks code works fine, but when SVM part executes there was this error: > aucs <- auc((dtest$recid=="SI")*1, lr.pred) Error in roc.default(response, predictor, auc = TRUE, ...) : Predictor must be numeric or ordered. > obj.roc <- roc((dtest$recid=="SI")*1, lr.pred )

2021-06-24 07:32:17    分类:问答    r   svm   roc   proc-r-package

使用 ROCR 和 pROC (R) 计算平均 AUC 的差异(Difference in average AUC computation using ROCR and pROC (R))

问题 我正在处理来自使用caret包生成的 SVM-RFE 模型的交叉验证数据(10 倍重复 5 次)。 我知道在计算指标时caret包与pROC包一起使用,但我需要使用ROCR包才能获得平均 ROC。 但是,我注意到使用每个包时平均 AUC 值并不相同,所以我不确定是否应该模糊地使用这两个包。 我用来证明这一点的代码是: predictions_NG3<-list() labels_NG3<-list() optSize <- svmRFE_NG3$optsize resamples<-(split(svmRFE_NG3$pred,svmRFE_NG3$pred$Variables)) resamplesFOLD<-(split(resamples[[optSize]],resamples[[optSize]]$Resample)) auc_pROC <- vector() auc_ROCR <- vector() for (i in 1:50){ predictions_NG3[[i]]<-resamplesFOLD[[i]]$LUNG labels_NG3[[i]]<-resamplesFOLD[[i]]$obs #WITH pROC rocCurve <- roc(response = labels_NG3[[i]], predictor = predictions_NG3

2021-06-24 07:21:27    分类:技术分享    r   r-caret   roc   auc   proc-r-package

ROC function error “Predictor must be numeric or ordered.”

I am not able to get ROC function to work, I get the error "Predictor must be numeric or ordered". I've looked through other posts, but nothing solves my problem. Any help is highly appreciated. "Get data" flying=dget("https://www.math.ntnu.no/emner/TMA4268/2019v/data/flying.dd") ctrain=flying$ctrain ctest=flying$ctest library(MASS) fly_qda=qda(diabetes~., data=ctrain) #Test error is given below: predict_qda=predict(fly_qda, newdata=ctest, probability=TRUE) table_qda<-table(ctest$diabetes, predict_qda$class) error_qda<-1-sum(diag(table_qda))/sum(table_qda) error_qda "ROC curve and AUC" predict

2021-06-24 00:36:04    分类:问答    r   roc   proc-r-package

如何处理R(pROC程序包)中的多类ROC分析?(How to deal with multiple class ROC analysis in R (pROC package)?)

问题 例如,当我在R(pROC包)中使用multiclass.roc函数时,我通过随机森林训练了一个数据集,这是我的代码: # randomForest & pROC packages should be installed: # install.packages(c('randomForest', 'pROC')) data(iris) library(randomForest) library(pROC) set.seed(1000) # 3-class in response variable rf = randomForest(Species~., data = iris, ntree = 100) # predict(.., type = 'prob') returns a probability matrix multiclass.roc(iris$Species, predict(rf, iris, type = 'prob')) 结果是: Call: multiclass.roc.default(response = iris$Species, predictor = predict(rf, iris, type = "prob")) Data: predict(rf, iris, type = "prob") with 3 levels of iris

2021-05-24 14:59:05    分类:技术分享    r   data-mining   random-forest   roc   proc-r-package

Difference in average AUC computation using ROCR and pROC (R)

I am working with cross-validation data (10-fold repeated 5 times) from a SVM-RFE model generated with the caret package. I know that caret package works with pROC package when computing metrics but I need to use ROCR package in order to obtain the average ROC. However, I noticed that the average AUC values were not the same when using each package, so I am not sure if I should use both packages indistinctively. The code I used to prove that is: predictions_NG3<-list() labels_NG3<-list() optSize <- svmRFE_NG3$optsize resamples<-(split(svmRFE_NG3$pred,svmRFE_NG3$pred$Variables)) resamplesFOLD<-

2021-05-09 03:23:51    分类:问答    r   r-caret   roc   auc   proc-r-package

How to deal with multiple class ROC analysis in R (pROC package)?

When I use multiclass.roc function in R (pROC package), for instance, I trained a data set by random forest, here is my code: # randomForest & pROC packages should be installed: # install.packages(c('randomForest', 'pROC')) data(iris) library(randomForest) library(pROC) set.seed(1000) # 3-class in response variable rf = randomForest(Species~., data = iris, ntree = 100) # predict(.., type = 'prob') returns a probability matrix multiclass.roc(iris$Species, predict(rf, iris, type = 'prob')) And the result is: Call: multiclass.roc.default(response = iris$Species, predictor = predict(rf, iris, type

2021-04-19 05:47:39    分类:问答    r   data-mining   random-forest   roc   proc-r-package

pROC ROC曲线消除空白(pROC ROC curves remove empty space)

问题 我想用pRoC绘制ROC曲线。 但是由于某种原因,x轴的两侧都有多余的空白空间,因此我无法使用xlim将其删除。 一些示例代码: library(pROC) n = c(4, 3, 5) b = c(TRUE, FALSE, TRUE) df = data.frame(n, b) rocobj <- plot.roc(df$b, df$n, percent = TRUE, main="ROC", col="#1c61b6", add=FALSE) 我尝试了pROC帮助文件,但这并没有真正帮助我。 更让我感到困惑的是,Y轴看起来还不错... 非常感谢您的帮助! 回答1 确保绘图设备是方形的,并调整边距,以使顶部+底部==左侧+右侧: library(pROC) png("test.png", width = 480, height = 480) par(mar = c(4, 4, 4, 4)+.1) n = c(4, 3, 5) b = c(TRUE, FALSE, TRUE) rocobj <- plot.roc(b, n, percent = TRUE, main="ROC", col="#1c61b6", add=FALSE) dev.off() 回答2 如果您不介意使轴变形,则另一个答案是使用asp参数。 默认情况下将其设置为1

2021-04-16 05:19:43    分类:技术分享    axis-labels   roc   proc-r-package

pROC ROC curves remove empty space

I want to draw ROC curves with pRoC. However for some reason there is extra empty space on either side of the x-axis and I cannot remove it with xlim. Some example code: library(pROC) n = c(4, 3, 5) b = c(TRUE, FALSE, TRUE) df = data.frame(n, b) rocobj <- plot.roc(df$b, df$n, percent = TRUE, main="ROC", col="#1c61b6", add=FALSE) I tried the pROC help file, but that doesn't really help me. Even more puzzling is to me that the Y-axis is OK looking... I really appreciate your help!

2021-03-31 20:49:37    分类:问答    axis-labels   roc   proc-r-package