I have a panel data of students from 2000 to 2005. I want to predict the exam grades (continuous variable) of the students with random forest algorithm. I want to use past years' exam grades as an input variable. However, past years' exam grades are missing if (1) the student was transferred from another school, (2) the student didn't agree to share the exam results, (3) the student didn't take the exam.

I impute these missings with 0 but I also create a categorical variable that includes these 3 situations above to indicate the reason for missing values.

I'm not sure if this solution for the missing variables makes sense in random forest setting and if the algorithm can capture this interaction.


If student transferred ==> 0 score. That interaction is basically the definition of how a tree learns so of course it can capture this interaction if the tree goes deep enough or there are enough of those 0s. If it is only a handful out of millions it might not ever come up as a possible split because of more useful splits preceding it. What might be better is to just pre-process these out though, why leave it up to chance if there is a flag for these three possibilities and you can predict them with 100% accuracy.

  • $\begingroup$ Thank you for your answer Tyler. I'm not actually trying to predict the exam scores when they are missing (or 0 in my example). But as I use past exam scores to estimate the current exam scores, I sometimes have 0 values in my input variable. I add a categorical variable indicating the reason for that value being 0 and I'm not sure if random forest can capture this interaction with 0s and the categorical variable. Or maybe there is another better way to handle these missing input variable values. Thank you! $\endgroup$ – adamsalenushka May 24 at 18:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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