# How to handle a feature vector that could be variable length?

I would like to train a machine learning model with several features as input as X[] and with one output as Y. For example Every sample has a Data frame like this: X[0], X[1], X[2], X[3], X[4], Y

Let's say One sample the followings Data is only one value: X[0], X[1], X[2], X[4], Y This is normal machine training problem.

But now, if I would like to set X[3] multiple values for example sample 1 Data is:

X[0] | X[1] | X[2] |         X[3]         | X[4] | Y
10  |  5   |   6  | [10, 20, 30, 40, 50] |  7   | 90


Data in sample 2 is:

X[0] | X[1] | X[2] |         X[3]         | X[4] | Y
11  |  7   |   5  | [20, 30, 40, 50, 60] |  3   | 80


Is this possible to follow the normal machine training process and got a model which could calculate a sample with other example with Data like:

X[0]   | X[1] |  X[2]  |         X[3]         | X[4] | Y
10.5  |  6   |   5.5  | [15, 25, 35, 45, 55] |  5   | ???


If the length for each X[3] is not long, it is possible to divide the X[3] into multiple new features, but if the length of X[3] is very long (len > 1000) with different distribution, making binary is also lead to too many new features. Is there any way to treat the X[3] directly without adding new features?

Really appreciate for your help.

• Basically, it looks like you want to encode feature X[3] in some way; i.e. generate some other features based on it. For example - the mean, min and max of values in it (reducing the >1000 to 3). The exact way to do it depends on the nature of X[3]... – Itamar Mushkin Jul 13 '20 at 10:38
• Thank you for your answer, just to confirm that your answer means it is not possible to directly use an "multiple value feature". Anyway have to transfer X[3] into multiple features. Am i understand right? – Crazy9 Jul 14 '20 at 2:52
• Yes, in my opinion. – Itamar Mushkin Jul 14 '20 at 6:00
• Does this answer your question? How to deal with categorical feature of very high cardinality? – 10xAI Jul 14 '20 at 7:36
• @10xAI that question deals with categorical features; OP's question is about a feature that is itself a vector. Can you elaborate on why are the two equivalent? – Itamar Mushkin Jul 15 '20 at 6:26