2
$\begingroup$

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)
$\endgroup$
13
  • $\begingroup$ Could you give an example data of X and Y in order to make the code reproducible? $\endgroup$ – Carlos Mougan Jan 13 '20 at 8:35
  • $\begingroup$ sure, sorry. For example, X = "How to join amazon company ". Y = ["Career Advice", "Fresher "]. @CarlosMougan $\endgroup$ – Pratyush Rajawat Jan 13 '20 at 9:02
  • $\begingroup$ 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 $\endgroup$ – Carlos Mougan Jan 13 '20 at 9:39
  • $\begingroup$ 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 . $\endgroup$ – Pratyush Rajawat Jan 13 '20 at 9:46
  • 1
    $\begingroup$ 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 $\endgroup$ – Pratyush Rajawat Jan 13 '20 at 10:42
1
$\begingroup$

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)
```
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.