@Z。张
reg.fitness = function(chr, parent,tr,te,res) {
try=as.factor(parent$data$classes[tr])
trd =
data.frame(parent$data$data[tr,as.numeric(chr)])
trm = nnet::nnet(try ~ ., data = cbind(trd,try=try),trace=F,
size = 3)
tey = as.factor(parent$data$classes[te])
ted =
data.frame(parent$data$data[te,as.numeric(chr)])
pred=predict(trm,newdata = cbind(ted,tey=tey),type = "raw")
if(res){
roc(tey,pred,levels=levels(tey),
direction = "<")$auc
}
else{
predict(trm,newdata=cbind(ted,tey=tey),type="class")
}
}
reg.bb = configBB.VarSel(data=t(data_set[,-ncol(data_set)]),
classes=data_set$y,
classification.method="user",
classification.userFitnessFunc=reg.fitness,
chromosomeSize=3, niches=1, maxSolutions=10,
goalFitness = 0.9, saveVariable="reg.bb",
saveFrequency=50, saveFile="reg.bb.Rdata",
main="Logistic")
blast(reg.bb)
这是我前 4 次迭代得到的输出
[Bb] Starting, Solutions=10
[Bb] #bb Sol Last Fitness %Fit Gen Time Elapsed Total Remaining
[e] Starting: Fitness Goal=0.9, Generations=(10 : 200)
[e] Elapsed Time Generation Fitness %Fit [Next Generations]
[e] 0h 0m 0s (m) 0 1 111.11% +GGGGGGGGGG
[e] 0h 0m 9s *** 11 1 111.11% FINISH: 1 2 1
[Bb] 1 1 Sol Ok 1 111.11% 11 9.33s 9s 10s 42s (0h 0m 42s )
[e] Starting: Fitness Goal=0.9, Generations=(10 : 200)
[e] Elapsed Time Generation Fitness %Fit [Next Generations]
[e] 0h 0m 0s (m) 0 1 111.11% +GGGGGGGGGG
[e] 0h 0m 10s *** 11 1 111.11% FINISH: 1 1 3
[Bb] 2 2 Sol Ok 1 111.11% 11 10.35s 20s 22s 50s (0h 0m 50s )
[e] Starting: Fitness Goal=0.9, Generations=(10 : 200)
[e] Elapsed Time Generation Fitness %Fit [Next Generations]
[e] 0h 0m 0s (m) 0 1 111.11% +GGGGGGGGGG
[e] 0h 0m 10s *** 11 1 111.11% FINISH: 3 1 1
[Bb] 3 3 Sol Ok 1 111.11% 11 9.93s 30s 34s 50s (0h 0m 50s )
[e] Starting: Fitness Goal=0.9, Generations=(10 : 200)
[e] Elapsed Time Generation Fitness %Fit [Next Generations]
[e] 0h 0m 0s (m) 0 1 111.11% +GGGGGGGGGG
[e] 0h 0m 10s *** 11 1 111.11% FINISH: 1 2 2
[Bb] 4 4 Sol Ok 1 111.11% 11 10s 40s 45s 45s (0h 0m 45)
绘制所有 1000 次迭代,其中它给出的适应度函数值与 1 相同