TypeError:mnb.fit()缺少1个必需的位置参数:“ y”

时间:2019-03-29 11:16:54

标签: python python-3.x pandas scikit-learn typeerror

我试图使用MultinomialNB运行朴素贝叶斯模型,然后预测电影评论的情绪。我运行以下代码:

from sklearn.feature_extraction.text import CountVectorizer
from nltk import RegexpTokenizer
from sklearn.model_selection import train_test_split
from sklearn.naive_bayes import MultinomialNB

movie_revs = pd.read_csv("film.tsv", sep='\t')

token = RegexpTokenizer(r'[a-zA-Z0-9]+')
vectorizer = CountVectorizer(lowercase=True, stop_words='english', ngram_range = (1,1), tokenizer = token.tokenize)

movie_revs_counts = vectorizer.fit_transform(movie_revs.Phrase)
movie_revs_x = movie_revs['Phrase']
movie_revs_y = movie_revs['Sentiment']

x_train, x_test, y_train, y_test = train_test_split(movie_revs_x, movie_revs_y, test_size = 0.3, random_state = 4)

y_train = y_train.astype('int')
x_traincv = vectorizer.fit_transform(x_train)
x_testcv = vectorizer.transform(x_test)

mnb.fit(x_traincv, y_train)

这时我遇到了错误:

"TypeError: fit() missing 1 required positional argument: 'y'"

但是我看不出问题出在哪里。感谢您的协助。

0 个答案:

没有答案