我正在尝试检测最好的 AUC
使用 genetic algorithm
在 R
.这是代码:
library(GA)
library(ROCR)
realResult <- sample( c(T,F), 350, replace=TRUE, prob=c( 0.5, 0.5) )
AUCfitness<-function(scores){
res<-prediction(scores, realResult, label.ordering = NULL)
auc.tmp <- performance(res,"auc");
auc <- as.numeric(auc.tmp@y.values)
# print(paste0("AUC is: ",auc))
auc
}
min <- 0.000654226
max <- 9433.873
GA <- ga(type = "real-valued", fitness = AUCfitness, min = min, max = max, monitor = FALSE,popSize = 350)
summary(GA)
但符合
ga
它提示: Error in prediction(scores, realResult, label.ordering = NULL) :
Number of predictions in each run must be equal to the number of labels for each run.
如您所见,我的大小为
realResult
如 350 和 popSize = 350
,所以我不应该面对这个错误
最佳答案
几分钟前遇到了这个问题。
似乎都是因为 NA。
我删除了与模型相关的所有 NA 案例,然后一切正常。
关于r - 每次运行的预测数必须等于每次运行的标签数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43272395/