我有三个模型概率预测mod.p1, mod.p2, mod.p3
require(Runuran)
mod.p1<- urnorm(n = 1000, mean = 0.2, sd = 0.35, lb = 0, ub = 1)
mod.p2<- urnorm(n = 1000, mean = 0.23, sd = 0.37, lb = 0, ub = 1)
mod.p3 = urnorm(n = 1000, mean = 0.19, sd = 0.39, lb = 0, ub = 1)
最终结果在判决中给出(是,否)
Verdict <- sample( c("yes","No"), 1000, replace=TRUE, prob=c(0.2,0.8) )
我为每个模型设置了三个权重
i1=0.3
i2=0.3
i3=0.4
创建集成预测并计算 auc
Ensemble=i1*mod.p1+i2*mod.p2+i3*mod.p3
require(ROCR)
Ensemble.pred = prediction(Ensemble, Verdict)
Ensemble.auc = as.numeric(performance(Ensemble.pred, "auc")@y.values)
Ensemble.auc # 0.52
现在我如何编写一个 for 循环来尝试不同的值i1 , i2 and i3
,并返回i1 , i2 and i3
给我最大 AUC 的最佳可能值。