这个自学一会就会了,给你一个模型,自己研究一下,没那么难。import jiebaimport utilfrom lassify import NaiveBayesClassifierfrom pus import namesdef word_feats(words): return dict([(word, True) for word in words])text1 = open(r"积极xt", "r")ad()seg_list = ut(text1)result1 = " "join(seg_list)text2 = open(r"消极xt", "r")ad()seg_list = ut(text2)result2 = " "join(seg_list)# 数据准备positive_vocab =result1negative_vocab =result2# 特征提取positive_features = [(word_feats(pos), 'pos') for pos in positive_vocab]negative_features = [(word_feats(neg), 'neg') for neg in negative_vocab]train_set = negative_features + positive_features# 训练模型classifier = NaiveBayesCain(train_set)# 实战测试neg = 0pos = 0sentence = input("请输入一句你喜欢的话:")sentence = lower()seg_list = ut(sentence)result1 = " "join(seg_list)words = split(" ")for word in words: classResult = lassify(word_feats(word)) if classResult == 'neg': neg = neg + 1 if classResult == 'pos': pos = pos + 1print('积极:' + str(float(pos) / len(words)))print('消极: ' + str(float(neg) / len(words)))