我正在尝试创建一个评分函数(称为evalFunc
)。为了获得分数,我试图计算生成模型的R平方值。我如何知道如何将值传递给' evalFunc'来自rbga.bin
函数?
library(genalg)
library(ggplot2)
set.seed(1)
df_factored<-data.frame(colA=runif(30),colB=runif(30),colC=runif(30),colD=runif(30))
dataset <- colnames(df_factored)[2:length(df_factored)]
chromosome = sample(c(0,1),length(dataset),replace=T)
#dataset[chromosome == 1]
evalFunc <- function(x) {
#My end goal is to have the values passed into evalFunc be evaluated as the IV's in a linear model
res<-summary(lm(as.numeric(colA)~x,
data=df_factored))$r.squared
return(res)
}
iter = 10
GAmodel <- rbga.bin(size = 2, popSize = 200, iters = iter, mutationChance = 0.01, elitism = T, evalFunc = evalFunc)
cat(summary(GAmodel))
答案 0 :(得分:1)
您可以通过键入 $sql = "SELECT * FROM uk_postcodes";
$result = mysqli_query($connection, $sql) or die("Error " . mysqli_error($connection));
$dname_list = array();
while($row = mysqli_fetch_array($result))
{
// [ { label: "Choice1", value: "value1" }, { label: "Choice2", value: "value2" } ]
$dname_list[] = "{label:".$row['postcode'].","."value:".$row['town']."}";
}
header('Content-Type: application/json');
echo json_encode($dname_list);
来查看来源,但最好是运行rbga.bin
,然后在下次调用该功能时,它允许您单步执行该功能。在这种情况下,第一次进入函数就在这一行(大约是函数的第82行):
debug(rbga.bin)
此时, evalVals[object] = evalFunc(population[object,
])
是由0和1组成的200x2矩阵:
population
而head(population)
# [1,] 0 1
# [2,] 0 1
# [3,] 0 1
# [4,] 1 0
# [5,] 0 1
# [6,] 1 0
是数字1,因此object
是向量population[object,]
。
完成c(0,1)
后,您可debug
,并且每次拨打undebug(rbga.bin)
时都不会进入调试模式。