Reputation: 9
Following the example reported in the link below I have the following error:
Using nnet for prediction, am i doing it right?
Error in na.fail.default(list(y = c(0, 0.0998334166468282, 0.198669330795061, : missing values in object
To solve this error I use the condition na.action = na.omit
#Fit model
model <- train(y ~ x1 + x2, te, method='nnet', linout=TRUE, trace = FALSE,
#Grid of tuning parameters to try:
tuneGrid=expand.grid(.size=c(1,5,10),.decay=c(0,0.001,0.1)),
na.action = na.omit)
ps <- predict(model, te)
is.na(te)
nrow(te)
nrow(ps)
Is this condition the only way to proceed?
In fact the consequence is that the number of rows of the ps is different to the number of ps data.
Upvotes: 0
Views: 705
Reputation: 14316
Given that you are lagging the data, this is probably the best approach. Note that:
> sum(!complete.cases(te))
[1] 2
The model can't predict these which is why
> nrow(ps)
[1] 199
> nrow(te)
[1] 201
and this is because:
> formals(predict.train)$na.action
na.omit
(Note that this will probably be changed to na.fail
in the next version of the package)
Upvotes: 1