Python 如何通过解决此错误来训练多项式nb[ValueError:bad input shape(10,2)]

Python 如何通过解决此错误来训练多项式nb[ValueError:bad input shape(10,2)],python,scikit-learn,Python,Scikit Learn,这是数据,然后我使用countvectorizer,之后我使用多项式nb(),但我得到了错误。请告诉我它的正确语法 train = [('I love this sandwich.','pos'), ('This is an amazing place!', 'pos'), ('I feel very good about these beers.', 'pos'), ('This is my best work.', 'pos'),

这是数据,然后我使用countvectorizer,之后我使用多项式nb(),但我得到了错误。请告诉我它的正确语法

train = [('I love this sandwich.','pos'),
         ('This is an amazing place!', 'pos'),
         ('I feel very good about these beers.', 'pos'),
         ('This is my best work.', 'pos'),
         ('What an awesome view', 'pos'),
         ('I do not like this restaurant', 'neg'),
         ('I am tired of this stuff.', 'neg'),
         ("I can't deal with this.", 'neg'),
         ('He is my sworn enemy!.', 'neg'),
         ('My boss is horrible.', 'neg')
        ]

from sklearn.feature_extraction.text import CountVectorizer
cv = CountVectorizer()

text_train_cv = cv.fit_transform(list(zip(*train))[0])
print(text_train_cv.toarray())

from sklearn.feature_extraction.text import TfidfTransformer
tfidf_trans = TfidfTransformer()

text_train_tfidf = tfidf_trans.fit_transform(text_train_cv)
print(text_train_tfidf.toarray())



from sklearn.naive_bayes import MultinomialNB
clf = MultinomialNB().fit(text_train_tfidf , train)
这就是错误: ValueError:错误的输入形状(10,2)

使用
列表(zip(*train))[1]
代替多项式nb.fit()中的


fit()方法需要
y
的单个标签列表(或一维数组)。因此,您需要按照将列车传递给CountVectorizer时的方式更换列车。

请打印文本\u train\u tfidf和showo.k先生。我现在给你看。请检查一下,告诉我语法。。
MultinomialNB().fit(text_train_tfidf , list(zip(*train))[1])