ML之NB:基于NB朴素贝叶斯算法训练20类新闻文本数据集进行多分类预测

ML之NB:基于NB朴素贝叶斯算法训练20类新闻文本数据集进行多分类预测


输出结果

设计思路

核心代码

vec = CountVectorizer()
X_train = vec.fit_transform(X_train)
X_test = vec.transform(X_test)

mnb = MultinomialNB()
mnb.fit(X_train, y_train)
y_predict = mnb.predict(X_test)  

print('The accuracy of Naive Bayes Classifier is', mnb.score(X_test, y_test))
(0)

相关推荐