예제 #1
0
 def classifyNB(self,listWord2classify):
     '''
     对给定的词组列表进行分类
     :param vec2classify:
     :return:
     '''
     vectorWord2classify=bagOfWords2VecMN(self.vocabList,listWord2classify)
     res=classifyNB(vectorWord2classify,self.p0V,self.p1V,self.pAb)
     return res
예제 #2
0
def testTrainNB():
    listOPosts,trainCategory=loadDataSet()
    vocabList=createVocabList(listOPosts)
    trainMat=[]
    for postinDoc in listOPosts:
        trainMat.append(setOfWords2Vec(vocabList,postinDoc))
    p0V,p1V,pAb=trainNB(trainMat,trainCategory)
    testEntry=['love','wang','xi','my','dalmation']
    vec2classify=array(setOfWords2Vec(vocabList,testEntry))
    print testEntry,'classify as:',classifyNB(vec2classify,p0V,p1V,pAb)