'Train the intent classifier on a data set.
:param num_threads: number of threads used during training time'

def train(self, training_data, config, **kwargs):

    from sklearn.model_selection import GridSearchCV
    from sklearn.svm import SVC
    import numpy as np
    labels = [e.get(u'intent') for e in training_data.intent_examples]
    if (len(set(labels)) < 2):
        logger.warn((u'Can    not    train    an    intent    classifier.    Need    at    least    2    different    classes.    ' + u'Skipping    training    of    intent    classifier.'))
    else:
        y = self.transform_labels_str2num(labels)
        X = np.stack([example.get(u'text_features') for example in training_data.intent_examples])
        tuned_parameters = [{u'C': [1, 2, 5, 10, 20, 100], u'kernel': [str(u'linear')]}]
        cv_splits = max(2, min(MAX_CV_FOLDS, (np.min(np.bincount(y)) // 5)))
        self.clf = GridSearchCV(SVC(C=1, probability=True, class_weight=u'balanced'), param_grid=tuned_parameters, n_jobs=config[u'num_threads'], cv=cv_splits, scoring=u'f1_weighted', verbose=1)
        self.clf.fit(X, y)
