我有这个简单的代码:
library(rgp)
df1 <- data.frame(x=1:10, y=sin(1:10))
grp.model <- symbolicRegression(y ~ x, df1, functionSet=functionSet("sin"))
Run Code Online (Sandbox Code Playgroud)
当我执行时,我得到了错误
STARTING genetic programming evolution run (Age/Fitness/Complexity Pareto GP search-heuristic) ...
Error in mse(x, y) : Argument 's_y' is not a real vector.
Run Code Online (Sandbox Code Playgroud)
我已经尝试过https://cran.r-project.org/web/packages/rgp/vignettes/rgp_introduction.pdf中的示例,但所有示例都给出了无意义的常量函数.
我究竟做错了什么 ?
我使用R版本3.1.2与rgp_0.4-1.
干杯.
小智 6
我也得到同样的错误.错误输出函数mse的文档声明它的参数需要"数字向量或列表".
运行str命令查看数据帧的结构表明x是整数类型.
> str(df1)
'data.frame': 10 obs. of 2 variables:
$ x: int 1 2 3 4 5 6 7 8 9 10
$ y: num 0.841 0.909 0.141 -0.757 -0.959 ...
Run Code Online (Sandbox Code Playgroud)
尝试在x向量上使用as.numeric():
library(rgp)
df1 <- data.frame(x=as.numeric(1:10), y=sin(1:10))
grp.model <- symbolicRegression(y ~ x, df1, functionSet=functionSet("sin"))
Run Code Online (Sandbox Code Playgroud)