本文介绍了术语中的错误.formula(formula):'.'在公式中,没有“数据"参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用神经网络进行预测.

I'm tring to use neuralnet for prediction.

创建一些X:

x <- cbind(seq(1, 50, 1), seq(51, 100, 1))

创建Y:

y <- x[,1]*x[,2]

给他们起个名字

colnames(x) <- c('x1', 'x2')
names(y) <- 'y'

制作data.frame:

Make data.frame:

dt <- data.frame(x, y)

现在,我遇到了错误

model <- neuralnet(y~., dt, hidden=10, threshold=0.01)

例如,在lm(线性模型)中,此方法有效.

For example, in lm(linear model) this is worked.

推荐答案

正如我的评论所述,这看起来像是非导出函数neuralnet:::generate.initial.variables中的错误.解决方法是,只需根据dt的名称构建一个长公式,但不包括y,例如

As my comment states, this looks like a bug in the non-exported function neuralnet:::generate.initial.variables. As a work around, just build a long formula from the names of dt, excluding y, e.g.

n <- names(dt)
f <- as.formula(paste("y ~", paste(n[!n %in% "y"], collapse = " + ")))
f

## gives
> f
y ~ x1 + x2

## fit model using `f`
model <- neuralnet(f, data = dt, hidden=10, threshold=0.01)

> model
Call: neuralnet(formula = f, data = dt, hidden = 10, threshold = 0.01)

1 repetition was calculated.

        Error Reached Threshold Steps
1 53975276.25     0.00857558698  1967

这篇关于术语中的错误.formula(formula):'.'在公式中,没有“数据"参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 07:57