# Array of categorical variables vs one-hot encoding

I have some JSON data to be transformed to a machine-learning friendly format. Every object in my data, which will eventually become an instance in my dataset, has the exact same fields (in this case, foo, bar and array). The array field contains a variable number of sub-objects (from 0 to 10). Each of these sub-objects has one categorical field with a massive range and some other fields which can be safely ignored. All categorical fields in these sub-objects belong to the same range.

Example (massively simplified object):

{
"foo": 1
"bar": 0.5
"array" : [
{
"categorical": "Lorem"
"other": 34
"stuff": 56
},
{
"categorical": "Ipsum"
"other": 53
"stuff": 12
},
{
"categorical": "Dolore"
"other": 6
"stuff": 101
}
]
}


Obviously foo and bar are easily represented as numeric attributes. I would now like to represent this array (array) as one large one-hot (or several-hot) vector. Assuming I don't care about any other field of the sub-objects except for the category field categorical, here is my question:

Question

Is it valid and possible to set more than one bit in a one-hot vector (which would make it, I assume, a several-hot vector) to represent all categories present in this instance? If not, how could it be done?

• I am not sure I understand the data to answer intelligently. Each instance always has foo and bar and then n categorical variables? What do other and stuff represent? Can you make up a representative set of data for another domain? – CalZ May 24 '17 at 0:55
• Sure, I will clarify all of this in the post, thank you for pointing it out. Unfortunately I cannot divulge the real dataset, but my question is more conceptual than context-specific. – Paul Benn May 24 '17 at 10:52
• this is not a problem at all. Bag of words is a classic example of this. use a model that can handle sparse matrices ( to save memory) and use regularisation eg l2 or l1 to reduce impact of instances with very few examples – seanv507 Jul 23 '17 at 20:39