I am not able to find an answer to how I should classify a varying number of sequence of binary flags + other features. My data looks like this (these are events, so the order is important and I may have other features in addition to sequence):

ID Flag 1 Flag 2 Flag 3 Other Feature
A 1 1 0 0.1
A 0 1 0 0.3
A 0 0 1 3.1
B 0 1 0 1.1
B 1 1 0 0.0

Notice that ID:B does not have the same number of entries (only 2). Any suggestion on how I should organize this data and what should I use to classify? How do I better capture the sequence of Flags? During inference, I will provide the sequence of flags [[1,1,0],[0,1,0],[0,0,1]] OR [[0,1,0],[1,1,0]] and "other feature" to get the label since the order of sequence makes up the positive or negative label.

  • $\begingroup$ Can you please put your specific question in the title? Thanks. "Classify sequence of flags" is not really a question. $\endgroup$
    – nbro
    Jun 1, 2023 at 8:35

1 Answer 1


You have a classification problem over a time-series, basically. You need to group all the events with the same ID under a single sequence, like [A, A, A] (is one sample) and [B,B] (is another).

Your targets ($y$) will be the class label, for each sequence and each element of the sequence. Then the $x$ will comprise the three flags and "other feature(s)" you have.

You can tackle the problem with three kinds of neural networks: 1D CNNs (convolutional nets), RNNs (recurrent nets), and even transformers (i.e. attention-based models).

  • Since you have sequences of the kind $(B,T,N)$ - where $B$ is the batch size, $T$ the num of events with same ID (you may need to zero-pad), and $N$ the number of features - and have a target for each $t\in T$, you need to predict the class label for each timestep $T$, and each sequence in $B$.
  • So you're output won't be a single value for one input sequence but a sequence of values of size $T$.
  • $\begingroup$ Thanks for your answer - much appreciated. So, let me elaborate this a bit. If I take data as a sequence and because I don't know the number of entries ahead of time, I will always zero pad and truncate to get a fixed length of sequence (for the above example, sample "A" would look like: [1,1,0,0.1, 0,1,0,0.3, 0,0,1,3.1] and "B" would look like: [1,1,0,0.1, 0,1,0,0.3, 0,0,0,0.0]). Is this correct? In that case, I can also use something simple like XGBoost etc.? $\endgroup$
    – Zaba
    Jun 1, 2023 at 20:28
  • $\begingroup$ You can do that, but I was thinking about representing A as [[1, 1, 0, 0.1], [0, 1, 0, 0.3], [0,0,1,3.1]] so as a (1,3, 4) tensor, and B (with zero-pad) as [[1,1,0,0.1], [0,1,0,0.3], [0,0,0,0.0]]. You transform your dataset accordingly, then train a RNN by sampling $N$ of such sequences to build a mini-batch, and repeat that until convergence. Actually, if you provide masks to the RNN is as if having varying-length sequences. For example, the mask for B should be 1,1,0. To not consider the last timestep. $\endgroup$ Jun 2, 2023 at 10:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .