0
$\begingroup$

I'm using predict on my random forest and nnet model and there will be a few values missing from the final predictions.

predict(psm_list_item$pmod, test_pac, type = 'prob')$yes

i=which(is.na(psm_pred))
return(data.frame(pred=psm_pred[-i], truth=psm_truth[-i]))

This does not work because the length of psm_pred is 6744 but the labels/truth is length 6748. I don't know if there's a way to match up the predicted probabilities with the truth this way, because it could be any 4 in the truth that could correspond to the missing predictions. Has anyone dealt with this?

$\endgroup$
0
$\begingroup$

I think nnet supports the all the standard na.action arguments. So, you can set na.action = na.exclude in the nnet call. Then predict will insert NAs into the predicted values at the appropriate places and your code should work.

Alternatively, you could try something like

i = which(is.na(df))
return(data.frame(pred=psm_pred,truth=psm_truth[-i])) 

(assuming I've read your code correctly) which would exclude the true values from rows with missing data, and leave only the predictions and truth from the complete cases.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.