def store_model_in_demisto(model_name, model_override, train_text_data,
                           train_tag_data, confusion_matrix):
    model = demisto_ml.train_text_classifier(train_text_data, train_tag_data,
                                             True)
    model_data = demisto_ml.encode_model(model)
    model_labels = demisto_ml.get_model_labels(model)

    res = demisto.executeCommand(
        'createMLModel', {
            'modelData': model_data,
            'modelName': model_name,
            'modelLabels': model_labels,
            'modelOverride': model_override
        })
    if is_error(res):
        return_error(get_error(res))
    confusion_matrix_no_all = {
        k: v
        for k, v in confusion_matrix.items() if k != 'All'
    }
    confusion_matrix_no_all = {
        k: {sub_k: sub_v
            for sub_k, sub_v in v.items() if sub_k != 'All'}
        for k, v in confusion_matrix_no_all.items()
    }
    res = demisto.executeCommand('evaluateMLModel', {
        'modelConfusionMatrix': confusion_matrix_no_all,
        'modelName': model_name
    })
    if is_error(res):
        return_error(get_error(res))
def store_model_in_demisto(model_name, model_override, X, y, confusion_matrix, threshold, y_test_true, y_test_pred,
                           y_test_pred_prob):
    model = demisto_ml.train_text_classifier(X, y, True)
    model_data = demisto_ml.encode_model(model)
    model_labels = demisto_ml.get_model_labels(model)

    res = demisto.executeCommand('createMLModel', {'modelData': model_data,
                                                   'modelName': model_name,
                                                   'modelLabels': model_labels,
                                                   'modelOverride': model_override,
                                                   'modelExtraInfo': {'threshold': threshold}
                                                   })
    if is_error(res):
        return_error(get_error(res))
    confusion_matrix_no_all = {k: v for k, v in confusion_matrix.items() if k != 'All'}
    confusion_matrix_no_all = {k: {sub_k: sub_v for sub_k, sub_v in v.items() if sub_k != 'All'}
                               for k, v in confusion_matrix_no_all.items()}
    res = demisto.executeCommand('evaluateMLModel',
                                 {'modelConfusionMatrix': confusion_matrix_no_all,
                                  'modelName': model_name,
                                  'modelEvaluationVectors': {'Ypred': y_test_pred,
                                                             'Ytrue': y_test_true,
                                                             'YpredProb': y_test_pred_prob
                                                             }
                                  })
    if is_error(res):
        return_error(get_error(res))