# Multiclassification Error: NotFittedError: This MultiLabelBinarizer instance is not fitted yet

After picking the model, when I try to use it, I am getting error -

"NotFittedError: This MultiLabelBinarizer instance is not fitted yet. Call 'fit' with appropriate arguments before using this estimator."

X = <training_data>
y = <training_labels>

# Perform multi-label classification on class labels.
mlb = MultiLabelBinarizer()
multilabel_y = mlb.fit_transform(y)

p = Pipeline([
('vect', CountVectorizer(min_df=min_df, ngram_range=ngram_range)),
('tfidf', TfidfTransformer()),
('clf', OneVsRestClassifier(clf))
])

# Use multilabel classes to fit the pipeline.
p.fit(X, multilabel_y)

• Could you give an example data of X and Y in order to make the code reproducible? – Carlos Mougan Jan 13 '20 at 8:35
• sure, sorry. For example, X = "How to join amazon company ". Y = ["Career Advice", "Fresher "]. @CarlosMougan – Pratyush Rajawat Jan 13 '20 at 9:02
• Try to make the question reproducible, so if we copy paste we can debug the same code that you have. Per example there are somethings that you dont´t have defined such as mind_df, ngram_range, clf and the class imports – Carlos Mougan Jan 13 '20 at 9:39
• link, This code has assisted me a lot, my model is working fine, The only problem I am facing is that after I pickle the model and try to use it again, I get the error I have mentioned in the question above. I only want to know, how "" multilabel_binarizer.inverse_transform() "" function will work after pickling the model. May be I am not able to pickle this funtion. Apart from this there is no other problem. @CarlosMougan . – Pratyush Rajawat Jan 13 '20 at 9:46
• NO, there are no errors, thank you so much Sir, I was stuck in this part for more than 3 days. But now it is all good. And all thanks to you. Logistic regression did multiclassification for me. I cannot stop thanking you. @CarlosMougan – Pratyush Rajawat Jan 13 '20 at 10:42

This code will work. Just let sklearn.linear_model.LogisticRegression handle the multiclassification for you.

from sklearn.pipeline import Pipeline
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.feature_extraction.text import TfidfTransformer
from sklearn.multiclass import OneVsRestClassifier
from sklearn.linear_model import LogisticRegression

X = ["How to join amazon company ","How to join google ",'Stay home']
y = ["Career Advice", "Fresher",'Other' ]

# Perform multi-label classification on class labels.

clf = LogisticRegression()

p = Pipeline([
('vect', CountVectorizer()),
('tfidf', TfidfTransformer()),
('clf', OneVsRestClassifier(clf))
])

# Use multilabel classes to fit the pipeline.
p.fit(X, y);
p.predict(X)
$$$$
`