I'd like to use a random forest for predicting how long a person will stay a customer of our company. One feature I'd like to use is the average age of the customer's kids.

The problem is some customers don't have kids so I can't compute an average. Moreover I can't put 0 because this value means something else: the customer just had his first kid.

How could I handle these missing values in random Forest?

Does it make sense to substitute with a impossible value like -1? If yes is it even better to use a big negative values like - 500?

  • 4
    $\begingroup$ Put 0 and make a second feature that is a binary indicator for whether or not the customer has kids. Feature scaling is irrelevant in RF since it just looks for cutpoints, not at the range of values. $\endgroup$
    – Sycorax
    Jul 24, 2015 at 17:18
  • 3
    $\begingroup$ As feature scaling is indeed irrelevant, could you not code the missing values with -1 and leave the zeros as is? $\endgroup$
    – Wouter
    Jul 24, 2015 at 17:47

1 Answer 1


In your case I would start with some feature engineering. As mentioned by @user777, start with creating a new variable that indicates whether or not a customer has kids. Then I would look into more details, maybe an indicator with the number of kids. If you have the age of the kids, look into creating age range buckets, or check if a polynomial of age has any relevance.


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.