# Classification models with multi-class allowed for each record

I am training a multi-class classification model. Each record can belong to one or more classes. (actually can I still call it a classification model? or should it be a topic model or something else?)

The training data looks like this (format_A)

record_id, f_1 , f_2, f_3, ... , f_n, output_A, output_B, output_C
1,  0.1, 0.2, 0.3, ... , 1.2,        1,        0,        1
2,  0.3, 1.2, 0.5, ... , 2.1,        1,        0,        0
3,  0.2, 3.2, 1.3, ... , 0.4,        1,        1,        0
4,  1.1, 0.1, 0.7, ... , 0.5,        0,        0,        1
5,  2.1, 0.5, 0.8, ... , 1.9,        0,        1,        1
6,  0.5, 0.4, 0.2, ... , 0.8,        1,        1,        1
:
:


Right now, I am using the sklearn logistic regression with multi-class. I preprocess the above training data such that there is only one target per record. For record with more than 1 output, I duplicated the records. That is, the above training data becomes below (format_B):

record_id, f_1 , f_2, f_3, ... , f_n,    target
1,  0.1, 0.2, 0.3, ... , 1.2,  output_A
1,  0.1, 0.2, 0.3, ... , 1.2,  output_C
2,  0.3, 1.2, 0.5, ... , 2.1,  output_A
3,  0.2, 3.2, 1.3, ... , 0.4,  output_A
3,  0.2, 3.2, 1.3, ... , 0.4,  output_B
4,  1.1, 0.1, 0.7, ... , 0.5,  output_C
5,  2.1, 0.5, 0.8, ... , 1.9,  output_B
5,  2.1, 0.5, 0.8, ... , 1.9,  output_C
6,  0.5, 0.4, 0.2, ... , 0.8,  output_A
6,  0.5, 0.4, 0.2, ... , 0.8,  output_B
6,  0.5, 0.4, 0.2, ... , 0.8,  output_C
:
:


I use format_B to train a multi-class logistic regression model. The model then predicts the probability of each category, and I set my own threshold to decide the final outputs.

While I have done the above, I am wondering would it possible to use format_A as the input of sklearn logistic regression with multi-class directly?

Or is there any package/library actually takes format_A as input? Or any other kind of models actually more suitable for this type of problem?

Thank you!

• You might also want to look into the ClassifierChain class within sklearn. – dsaxton Aug 18 '18 at 0:23

The task is called multilabel modelling. Many libraries in sklearn support this -http://scikit-learn.org/stable/modules/multiclass.html.