Multilabel binarizer - getting the inverse transform

Viewed 4439

I am stuck on using the Multilabel binarizer and One-vs-all classifier in scikit-learn . My challenge is once I obtain the predictions, to obtain the original labels. (I trained and pickled the one-vs-rest classifier and vectorizer separately)

_labels = load_labels()
mlb = MultiLabelBinarizer()
mlb.fit_transform(_labels)
print mlb.classes_ # this prints the binarized labels

_clf,_vect = load_pickle('./pickles')

for q in queries:
    #query vector q
    X = vect.transform([q])            
    res = clf.predict_proba(X)
    print res #[[ 0.00164113  0.00706595  0.00683465 .... 0.00837984]]

    #this is where I am stuck on what to pass into the inverse_transform to obtain
    preds = mlb.inverse_transform(??)
    print preds

Thanks for your help in advance!

1 Answers

Output of mlb.fit_transform(_labels) will be the input to the inverse_transform.

More on it is here: Multilabel Binarizer

Related