我有我的代码可以使用scikit学习库Naive bayes在下面的字符串中工作
bow_test = countVector.transform (['the phone bad ','the phone is bad but delivery very good','very nice but slow delivery'])
prediction['Multinomial'] = NB.predict(bow_test)
print ( prediction['Multinomial'])
输出
['negative' 'positive' 'positive']
但是在对熊猫进行测试时不起作用
c = 0
i = 0
for i in sentimentLa['review']:
print(i)
c+= 1
bow_comment = countVector.transform (['i'])
prediction['Multinomial'] = NB.predict(bow_comment)
score = (round(NB.predict_proba(bow_comment)[0][1],5))
sentimentLa.loc[c-1, 'sentiment'] = prediction['Multinomial']
sentimentLa.loc[c-1, 'score'] = score
print(prediction['Multinomial'])
print(score)
第一次审核应检测为阴性且得分应不同
review sentiment score
0 Sad to say the iPhone keeps rebooting even aft... [positive] 0.74839
1 great product, downside is the shipping with n... [positive] 0.74839
2 Very quick delivery! Under 24 hours! Product r... [positive] 0.74839
任何有助于体会到的地方:)