多分类错误:NotFittedError:尚未安装此 MultiLabelBinarizer 实例

数据挖掘 机器学习 Python 多类分类 数据科学模型 多标签分类
2022-02-24 18:12:26

选择模型后,当我尝试使用它时,我收到错误 -

“NotFittedError:尚未安装此 MultiLabelBinarizer 实例。在使用此估算器之前,请使用适当的参数调用 'fit'。”

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)
1个回答

此代码将起作用。让我们sklearn.linear_model.LogisticRegression为您处理多分类。

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)
```