NA impact in Caret Train


Following the example reported in the link below I have the following error:

Using nnet for prediction, am i doing it right?

Error in = 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:
               na.action = na.omit) 
ps <- predict(model, te)

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.


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

(Note that this will probably be changed to in the next version of the package)

Answered By – topepo

Answer Checked By – Mildred Charles (AngularFixing Admin)

Leave a Reply

Your email address will not be published.