问题描述
我开始在RStudio中进行线性回归,但是我无法弄清楚如何声明我假装使用的GA软件包中所需的适应度函数。
根据以下重复出现的错误,表明问题与函数的类对象有关:
(函数(cl,name,valueClass)中的错误: 对于“ ga”类的对象,“ list”类的对象的分配对@“ fitness”无效; is(value,“ numericOrNA”)不为真
但是,我已经尝试更改train_set的类型,但没有成功。我真的不知道问题是否与所使用的两个自变量的正确管理有关。
这是我正在尝试的:
library(GA)
#from train,which is a list of 4 variables(total columns) and 80 lines
#Let's take the first 4 lines to exemplify
i j k oil_cumulative_production
12 10 1 2201.7
15 14 1 2192.6
13 5 1 2190.1
9 4 1 2185.3
15 11 1 2193.1
train_set <- data.frame(y1 = train$oil_cumulative_production,x1 = train$i,x2 = train$j)
f <- function(x1,x2) { lmNp <- lm(y1 ~ x1 + x2,data = train_set)}
GA <- ga(type = "real-valued",fitness = function(x) f(x[1],x[2]),lower = c(1,1),upper = c(20,20),popSize = 50,maxiter = 100,optim = TRUE)
有什么想法吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)