# Spark 1.5.1: Train many binary classifiers, save them, then use them on new data

I have a DataFrame representing an annotated dataset with 300 labels.

The DataFrame looks like follow (the first row is just to explain the columns):

binary Vector column for labeling, feature column
[0, 1, 1, 0, 0 , 0.... ], featureVec
[0, 0, 1, 0, 1 , 0.... ], featureVec
......


The labelling column, represent the presence or the absence of each label as an annotation of a feature vector (which we can see in the second column).

Please correct me if I am wrong: I can't train one multi-class classifier because the labels are not exclusives, so I would like to train one binary classifier per label.

As I have 300 labels, then I need to train and optimise 300 classifier (say logistic regression classifier for example).

What is the best way and best practices to train my classifiers with N-cross validation for parameter optimisation? any example code or reference is highly appreciated.

Once the classifiers are optimised, what is the best way and best practices to save the best models and use them to classify the new data?

• This is not a good approach and here is there reason why. Nov 4 '15 at 22:05
• Thanks Elisha, even though I don't agree with some points in the link you provided. I would appreciate if you can elaborate more your answer and provide a good approach. Thanks
– Rami
Nov 4 '15 at 22:32
• I agree that that explanation is not entirely relevant (particularly if you scale your input for the whole dataset at once and use appropriate sampling/weighting schemes). But it might still be hard to train that many classifiers. You might consider a multiple regression with your output as 0s and 1s for each label. You can then apply a threshold to your prediction to get a binary vector of labels. This also has limitations, but you get to use all your data instead of having to oversample for each individual classifier Nov 5 '15 at 4:06
• thanks @jamesmf, this what I am trying to do now, and actually a binary output is not a most in my case, the order of the predicted categories is what I will be looking at. I am just wondering if applying a random forest is more relevant for that scale of problems?
– Rami
Nov 5 '15 at 8:28
• If it's just an order, then regression is even more applicable. If you wanted to train 300 models, you could use random forest. If you wanted one 300 dimensional output, you might try a regression (or a neural net can do this). The applicability of a random forest (and decision trees in general) probably depends on the nature of your feature space. Nov 5 '15 at 16:16