I want to predict the age of a parent using the ages of its children.

The problem is that in the data each parent has different numbers of children. How do I create a model that can take variable number of children ages as input?

For example

X1 = {1,5}             Y1 = 31
X2 = {18]              Y2 = 38
X3 = {1,3,3,7,10,15}   Y3 = 45

One thing I've thought of is to calculate the average and variance of the ages, and use that as input. But I feel that information is lost that way.


1 Answer 1


The way you suggested indeed results in some loss of data, but this is not necessarily a problem. You don't need the data itself, but rather their patterns, and at some cases the patterns are easier to emerge if you modify your data.

This is called feature engineering, the process of creating descriptive numerical features out of the existing data, and it is used both in situations like yours where the data do not have the required structure (another example is trying to fit an entire time series into a single row) and simply to create more features in order to improve accuracy.

If you calculate enough statistics it will probably still be able to learn enough. Don't just stay at mean and std. For example, the maximum age of the children as a feature would provide a pretty good way for the model to learn a lower boundary, significantly shortening the search space. Also the number of children itself (more children points to older parent).

Apart from simple statistics, you can also try with ratios (for example, the ratio of children with a small difference in age to the ratio of "outlier" children).

Another way would be even to train a separate model (something like an autoencoder) that takes the ages of children and returns a singular value that you can use as input to the final model, or even use it along with the rest of the statistics.

If you dumb this idea down, even simple one-hot encoding (where the columns would be age_1st_child, age_2nd_child would work with algorithms that can handle NaN values.

Your imagination is the limit, and I am sure you will be able to find a lot of stuff about feature engineering online.

  • 1
    $\begingroup$ in the same line as this answer - it is often good to take a step back first, and ask yourself (without messing with machine learning etc.) say "My friend has two children, age 14 and 18. How old do you think he is?" and follow through your own thought process. This would give you hint on how to tackle the problem. $\endgroup$
    – lpounng
    Jul 13, 2023 at 9:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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