import bayes
listPosts,listClasses = bayes.loadDataSet()
myVocabList = bayes.createVocabList(listPosts)
print(myVocabList)
print(bayes.setOfWords2Vec(myVocabList,listPosts[0]))
print(bayes.setOfWords2Vec(myVocabList,listPosts[1]))
bayes.testingNB()
['not', 'to', 'garbage', 'so', 'my', 'steak', 'flea', 'take', 'licks', 'problems', 'stupid', 'him', 'has', 'maybe', 'worthless', 'how', 'stop', 'buying', 'food', 'love', 'ate', 'dalmation', 'please', 'I', 'mr', 'dog', 'cute', 'quit', 'posting', 'park', 'is', 'help']
[0. 0. 0. 0. 1. 0. 1. 0. 0. 1. 0. 0. 1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 1. 0.
0. 1. 0. 0. 0. 0. 0. 1.]
[1. 1. 0. 0. 0. 0. 0. 1. 0. 0. 1. 1. 0. 1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
0. 1. 0. 0. 0. 1. 0. 0.]
['love', 'my', 'dalmation'] classified as: None
['stupid', 'garbage'] classified as: 1
参考博客:https://blog.youkuaiyun.com/moxigandashu/article/details/71480251?utm_source=blogxgwz0