随机森林----评论情感分析系统

本文介绍了使用随机森林模型对京东评论进行情感分析的过程,包括数据预处理、向量化、模型训练与评估。实验结果显示,模型在训练集上的准确率为100%,测试集上为97.12%。尽管预测准确度高,但训练时间较长,效率有待提升。文章还展示了部分预测结果,验证了模型的预测能力。
摘要由CSDN通过智能技术生成

京东评论情感分析----随机森林

上次实现了朴素贝叶斯算法实现的评论情感分析,这次使用随机森林模型来对京东评论内容进行分析

Step1: 读取数据集

从文件中读取京东网评论的10000条评论,其中好评6000条,差评4000条(数据来源请见此)

from sklearn.ensemble import RandomForestClassifier          #导入sklearn包下的随机森林分类器
import numpy as np
import pandas as pd
import csv

#输入文件名参数, 返回numpy类型的数据集
def getDataSet(file_name):
    dataset = []                                             #定义数据集
        
    with open(file_name, 'r', encoding='UTF-8') as fp:
        reader = csv.reader(fp)                              #读取csv文件
        dataset = np.array([x for x in reader])             #获得数据集

    return dataset                                          #返回

Step2: 分词、去停用词、生成词典

从文本文件中读取停用词信息,以列表的方式返回

#获取停用词列表
def getStopWords(file_name):
    stop_words = []                                       #定义停用词表

    with open(file_name, 'r', encoding='UTF-8') as fp:
        stop_words = fp.read().split('\n')                #读取所有停用词,并存放到列表中
        
    return stop_words                                    #返回停用词列表

对所有评论信息进行分词,并去除停用词

import jieba

#去处停用词,并返回评论切分后的评论列表,每个元素均为一个词语列表
def removeStopWords(X, stop_words):
    all_words = []                                        #定义存放评论的列表,评论均以词典列表形式存在
    
    for sentence in X:                                    #遍历评论列表
        words = []                                        #存放每个评论词语的列表
        
        for word in jieba.lcut(sentence):                 #遍历评论分词后的列表
            
            if word not in stop_words:                    #该词语未在停用词表中
                words.append(word)                         #追加到words中,实现去停用词
                
        all_words.append(words)                            #总评论列表追加该评论分词列表
    
    return all_words                                      #返回结果
    

遍历所有评论信息,统计词典

#生成词典,存放评论中所有出现过的词语,待统计词频
def getDictionary(X):
    dictionary = []                                        #定义词典,存放所有出现过的词语
    
    for sentence in X:
        for word in sentence:
            if word not in dictionary:                    #遍历所有评论的词语,若未在词典中存在
                dictionary.append(word)                    #添加
    
    return dictionary                                     #返回结果
    

Step3: 将评论 转化为 向量

词袋模型,将所有评论信息通过字典映射,转化为向量,最后返回向量列表

#通过词袋模型将每条评论均转换为对应的向量,返回
def word_2_vec(X, dictionary):
    n = len(dictionary)                                   #词典长度
    
    word_vecs = []                                        #存放所有向量的列表
    
    for sentence in X:                                    #遍历评论列表
        word_vec = np.zeros(n)                            #生成 (1,n)维的 0向量
        for word in sentence:                             #遍历评论中的所有词语
            if word in dictionary:                        #若该词语在字典中
                loc = dictionary.index(word)              #找到在词典中的位置
                word_vec[loc] += 1                        #为向量的此位置累加1
            
        word_vecs.append(word_vec)                      #评论列表累加向量
        
    return np.array(word_vecs)                                     #返回结果

Step4: 拆分数据集为训练集、测试集

评估随机森林模型的执行效率与预测准确度

from sklearn.ensemble import RandomForestClassifier, GradientBoostingClassifier
from sklearn.model_selection import train_test_split
import time


dataset = getDataSet('./datasets/comments.csv')           #读取文件, 返回数据集, 0代表好评, 1代表差评
stop_words = getStopWords('./file/cn-stopwords.txt')      #读取停用词表,返回列表

X = dataset[:, 0]                                         #取出所有评论信息
y = dataset[:, 1]                                         #取出所有标签信息

X = removeStopWords(X, stop_words)                        #对所有评论语句进行分词并去除停用词

dictionary = getDictionary(X)                             #构建词典

X = word_2_vec(X, dictionary)                             #将评论内容通过词袋模型转化为向量

X_train, X_test, y_train, y_test = train_test_split(X, y)              #拆分数据集为训练集、测试集


Step5: 训练模型、评估模型

评估随机森林模型的预测准确度与效率

train_start_time = time.time()                             #定义模型开始训练时间

forest = RandomForestClassifier(n_estimators=100)                     #构造随机森林,共存在100棵树
forest.fit(X_train, y_train)                                            #训练数据

train_end_time = time.time()                              #模型训练结束时间


predict_start_time = time.time()                          #预测开始时间

res01 = forest.score(X_train, y_train)                    #评估训练集的准确度
res02 = forest.score(X_test, y_test)                      #评估测试集的准确度

predict_end_time = time.time()                            #预测结束时间


print('The training: {}'.format(res01))
print('The test: {}'.format(res02))                       #输出结果

print('train time(s):', train_end_time-train_start_time)     #训练时间
print('test time(s):',predict_end_time-predict_start_time)   #预测时间
The training: 1.0
The test: 0.9712
train time(s): 44.56601166725159
test time(s): 2.159437417984009

可见,随机森林模型对于训练集的预测准确度为100%,对于测试集的预测准确度为97.12%,也较为不错

但是随机森林模型的训练时间较长,效率有待提高

Step6: 预测评论情感,输出分类结果

以下代码预测100条评论的情绪类别,并输出预测准确率

import random

dic_len = len(dictionary)

start = random.randint(100,2400)

#从测试集中随机抽取50条数据,准备测试
X_data = X_test[start:start+100]
y_data = y_test[start:start+100]

success_test = 0

#对 50条评论信息进行预测
for sequence_index in range(len(X_data)):
    
    #找到该 评论语句 切分后的词组对应的位置,返回一个数组
    locs = np.where(X_data[sequence_index] == 1)
    
    #输出切分、分词后的评论内容
    for loc in locs[0]:
        print(dictionary[loc] ,end='/')
    
    print('\n')
    
    res = forest.predict([X_data[sequence_index]])                #使用随机森林进行预测
    

    #0 代表好评, 1代表差评
    if res == '0':
        result = '0'                     #输出好评
        print('Predict result : 好评', end='\t')
    else:
        result = '1'                     #否则输出差评
        print('Predict result : 差评', end='\t')
    
    #实际该评论的结果
    if y_data[sequence_index] == '0':
        print('Actual results: 好评', end='\t')
    else:   
        print('Actual results: 差评', end='\t')
        
    #判断是否预测正确
    if result == y_data[sequence_index]:
        print('Predict success!', end='\t')
        success_test += 1
    else:
        print('Predict fail!', end='\t')


    print('\n\n')

print('本次测试预测准确度为: {}'.format(success_test/100))
好看/屏幕/效果/显示/外形/银色/程度/真的/特别/电脑/很棒/携带/设计/金属/1080p/

Predict result : 好评	Actual results: 好评	Predict success!	


屏幕/第一次/位置/摄像头/垃圾/语/正视/

Predict result : 差评	Actual results: 差评	Predict success!	


性能/外观/屏幕/散热/运行/速度/效果/外形/银色/程度/很快/清晰/炫酷/特色/金属/机身/便捷/点赞/国产/

Predict result : 好评	Actual results: 好评	Predict success!	


不错/做/真的/特别/16/性价比/超高/活动/划算/价格便宜/导购/

Predict result : 好评	Actual results: 好评	Predict success!	


外观/屏幕/散热/感觉/做/好评/运行/速度/效果/外形/轻薄/程度/笔记本/清晰/满意/感受/这款/选择/整体/优秀/花/软件/颜值/台式机/场景/香/回来/那种/新机/综合/快快/1.5/国货/两/荣耀/坚定/室内设计/三维/w/

Predict result : 好评	Actual results: 好评	Predict success!	


流畅/运行/速度/效果/很快/挺/高/清晰/喜欢/刷新率/整洁/配送/电脑配置/反应速度快/桌面/

Predict result : 好评	Actual results: 好评	Predict success!	


速度/稳定/原因/网络/wifi/网络连接/较卡/

Predict result : 好评	Actual results: 差评	Predict fail!	


屏幕/运行/速度/效果/外形/程度/很快/秒/送到/漂亮/够用/开机/订单/上午/傍晚/

Predict result : 好评	Actual results: 好评	Predict success!	


电脑/品牌/主流/喷/说太多/爱国人士/总结经验/

Predict result : 差评	Actual results: 差评	Predict success!	


电量/不到/电池/电脑包/买/送/太快/鼠标/便宜/一周/完/费/好几百/

Predict result : 差评	Actual results: 差评	Predict success!	


分辨率/电脑/体验/购物/显示屏/开箱/愉快/联网/提示/处/退换/欠佳/

Predict result : 差评	Actual results: 差评	Predict success!	


第二天/日常/卡/买回来/速度慢/

Predict result : 差评	Actual results: 差评	Predict success!	


屏幕/不错/感觉/质量/很快/包装/终于/发货/素质/收到/货/时间/第一/拆/比较慢/好久好久/运送/

Predict result : 好评	Actual results: 好评	Predict success!	


屏幕/质量/电脑/刚买/闪/三次/

Predict result : 差评	Actual results: 差评	Predict success!	


性能/流畅/速度/效果/外形/程度/合适/不到/价格/时尚/买/特色/设计/热/开机/打游戏/大屏/一分钟/

Predict result : 好评	Actual results: 好评	Predict success!	


屏幕/不错/速度/很快/质感/清晰/值得/接口/机身/推荐/拎/全金属/身形/

Predict result : 好评	Actual results: 好评	Predict success!	


不错/运行/外形/程度/很快/很棒/清晰/喜欢/特色/处理器/热/整体/英特尔/比较满意/装包里/用久/全金属/不重/微微/有点儿/一点儿/

Predict result : 好评	Actual results: 好评	Predict success!	


性能/外观/流畅/屏幕/散热/速度/效果/外形/灰/轻薄/程度/丝滑/Ps/刚刚/简约/够用/过热/平台/手机/压力/帧/120hz/宽/单手/2k/放在/表面/配色/可选/Lr/率/开阔/浅灰/金属光泽/清爽/握持/两部/

Predict result : 好评	Actual results: 好评	Predict success!	


流畅/屏幕/不错/入手/舒服/高/笔记本/价格/买/太/总体/设计/第一个/很赞/本子/边框/窄/联想/弟弟/做表/Pro16/睿/小键盘/酷/迪/

Predict result : 好评	Actual results: 好评	Predict success!	


性能/办公/非常适合/好评/特别/包装/发货/服务态度/学习/618/日常/便宜/严实/客服/拉满/商品质量/专柜/

Predict result : 好评	Actual results: 好评	Predict success!	


屏幕/不错/感觉/c/做工/力/16/处理器/收到/货/够用/接口/面/10/高刷/完整/方向键/十二代/

Predict result : 好评	Actual results: 好评	Predict success!	


系统/说/14/降价/不行/联想/小新/别买/

Predict result : 差评	Actual results: 差评	Predict success!	


屏幕/运行/速度/效果/外形/轻薄/程度/真的/很漂亮/特色/画面/想象/心/满满的/滴/超轻薄/少女/中薄/粉粉/

Predict result : 好评	Actual results: 好评	Predict success!	


屏幕/舒适/京东/自营/物流/速度/电脑/快递/视频/服务态度/员/正版/官方/宽大/

Predict result : 好评	Actual results: 好评	Predict success!	


质量/电脑/发/C/残次品/面有/凹坑/

Predict result : 差评	Actual results: 差评	Predict success!	


PS/不错/键盘/办公/好评/笔记本/一代/适合/日常/心/烫/我选/追剧/打字/不发/少女/粉色/

Predict result : 好评	Actual results: 好评	Predict success!	


性能/外观/薄/散热/运行/速度/效果/外形/轻薄/程度/很大/高/好用/特色/低调/内涵/分辩率/

Predict result : 好评	Actual results: 好评	Predict success!	


好看/苹果/速度/高/做工/完美/产品/喜欢/MacBook/Air/iPhone/Pro/颜值/太好/iPad/帅气/pencil/watch/凑齐/

Predict result : 好评	Actual results: 好评	Predict success!	


外观/不错/分辨率/质量/物流/轻薄/很快/高/电脑/终于/很漂亮/质感/携带/清晰/收到/货/够用/接口/画质/久/金属/满满的/大小/适中/

Predict result : 好评	Actual results: 好评	Predict success!	


外观/屏幕/很大/色彩/太棒了/很久/划算/高分辨率/强劲/CPU/关注/全金属/新一代/气/一位/首发/助手/价买/办工/

Predict result : 好评	Actual results: 好评	Predict success!	


颜色/高/电脑/携带/收到/货/开/颜值/好好/机会/贼/指导/步骤/康/

Predict result : 好评	Actual results: 好评	Predict success!	


第一次/质量/价格/专卖店/喜欢/优惠/期待/没想到/凑/单买/中奖/土豪/玩意/村里/骄傲/

Predict result : 好评	Actual results: 好评	Predict success!	


买来/性能/外观/散热/物流/运行/速度/外形/轻薄/程度/很快/超薄/喜欢/本来/小巧/孩子/收到/美观大方/上网/疫情/两天/原因/课用/上海/运送/迟迟/收不到/

Predict result : 好评	Actual results: 好评	Predict success!	


京东/换/两次/痕迹/

Predict result : 差评	Actual results: 差评	Predict success!	


买/说/两个/天/降价/块/20/京豆/400/搞笑/赔偿/

Predict result : 差评	Actual results: 差评	Predict success!	


外观/不错/耐用/运行/速度/很快/电池/笔记本/几天/漂亮/轻/评价/整体/特地/

Predict result : 好评	Actual results: 好评	Predict success!	


 /买/降价/想/佩服/500/吐血/5300/

Predict result : 差评	Actual results: 差评	Predict success!	


京东/做工/产品/接口/态度/不好/申请/找/位置/差/电源线/机构/粗糙/

Predict result : 差评	Actual results: 差评	Predict success!	


办公/很快/适合/服务/简单/开机/软件/热情/自带/客服/流程/新手/小狸/

Predict result : 好评	Actual results: 好评	Predict success!	


不错/棒棒/升级/手机/哒/希望/大屏/投屏/联网/笔电/

Predict result : 好评	Actual results: 好评	Predict success!	


外观/好看/不错/特别/高/电脑/购买/质感/值得/性价比/开盖/单手/180/ordm/

Predict result : 好评	Actual results: 好评	Predict success!	


打开/卡/浏览器/黑屏/意外/退出/

Predict result : 差评	Actual results: 差评	Predict success!	


不错/键盘/效果/轻薄/价格/超级/喜欢/漂亮/晚上/收到/学习/手感/接口/屏幕显示/划算/五星/机子/总额/好清/

Predict result : 好评	Actual results: 好评	Predict success!	


外观/薄/散热/音质/办公/效果/棒/外形/轻薄/程度/很快/风扇/声/挺/高/完美/解答/款/质感/机器/说/感受/音效/特色/还好/重量/代/评价/视频/热/ldquo/rdquo/要用/软件/打游戏/久/情况/好久/亮度/卡/机身/12/送货/赞/更新/售前/耐心/疫情/这台/客服/联想/评测/里/观感/一句/话/符合/套/解决/轻度/全金属/手里/i5/纠结/轻微/雾面/k/2.5/驱动/释放/杜比/刷屏/解封/坚定/顿感/导购/03/bios/以内/特别感谢/想法/也眈误/2kg/借用/知名/博主/中正/

Predict result : 好评	Actual results: 好评	Predict success!	


屏幕/办公/轻薄/特别/笔记本/携带方便/携带/一段时间/充电/头/上网/课/手机/那种/不像/功能齐全/

Predict result : 好评	Actual results: 好评	Predict success!	


外观/好看/音质/第一次/物流/运行/购买/清晰/笔记本电脑/挺快/这款/视频/性价比/服务/轻便/设计/操作/耐心/色域/态度/边框/客服/眼睛/参考/手里/很窄/问/电视剧/不累/摄像头/提示/回复/挺大/一步步/隐藏/

Predict result : 好评	Actual results: 好评	Predict success!	


键盘/保障/物流/很快/高/电脑/棒棒/性价比/适合/品质/超高/犹豫/指纹/耐心/哒/客服/负责/学生/背光/登录/解决问题/

Predict result : 好评	Actual results: 好评	Predict success!	


耐用/高级/轻薄/质感/买/适合/开机/品质/家人/按键/几款/敏锐/两/三秒/码字/wifi/

Predict result : 好评	Actual results: 好评	Predict success!	


性能/屏幕/不错/散热/办公/京东/运行/速度/效果/很快/声音/电影/挺/清晰/买/第二天/值得/信赖/适合/开机/品牌/当天/到货/办公室/放在/几秒/

Predict result : 好评	Actual results: 好评	Predict success!	


好看/效果/外形/高级/真的/清晰/买/本来/吸引/没想到/冲着/胃口/

Predict result : 好评	Actual results: 好评	Predict success!	


键盘/很快/特别/高/电脑/购买/值得/性价比/收到/手感/大小/

Predict result : 好评	Actual results: 好评	Predict success!	


外观/薄/屏幕/运行/速度/效果/外形/轻薄/程度/很快/清晰/买/轻便/开机/开/软件/美观/能力/金属/机身/架子/提高/男女/底下/垫个/

Predict result : 好评	Actual results: 好评	Predict success!	


屏幕/不错/ /高/电脑/接受/新/品控/平时/观感/售后/差评/2.8/k/通病/90Hz/刷屏/控/奔/6000/这品/恭维/能换/个例/

Predict result : 差评	Actual results: 差评	Predict success!	


性能/外观/好看/颜色/分辨率/运行/速度/效果/显示/外形/程度/很快/风扇/一点/声音/秒/高/做工/配置/清晰/特色/开/软件/不卡/一会/烫/超/中等/

Predict result : 好评	Actual results: 好评	Predict success!	


性能/屏幕/散热/办公/效果/外形/轻薄/程度/风扇/听到/提升/特色/评价/视频/不用/工作/M1/兼容/软件/绝佳/剪/压力/出差/运转/高负荷/

Predict result : 好评	Actual results: 好评	Predict success!	


月/死机/俩个/

Predict result : 差评	Actual results: 差评	Predict success!	


外观/好看/屏幕/效果/外形/高/特色/颜值/

Predict result : 好评	Actual results: 好评	Predict success!	


性能/散热/质量/显示/风扇/很大/高/体验/清晰/噪音/画面/不用/适合/屏/选择/硬盘/续航/功耗/接口/情况/亮度/日常/机身/一年/售后服务/全/升级/明亮/后期/出色/负载/观感/测试/性强/CPU/坞/释放/插电/可达/上门/400nit/军标/Thinkbook14/高达/50W/自主/依赖/中等水平/

Predict result : 好评	Actual results: 好评	Predict success!	


价格/产品/体验/双十/一买/购物/到手/消费者/差/直降/大半夜/抢货/

Predict result : 差评	Actual results: 差评	Predict success!	


速度/太快/评论/所说/待机时间/长度/下电/

Predict result : 差评	Actual results: 差评	Predict success!	


流畅/屏幕/散热/键盘/运行/ /几天/体验/清晰/太/总体/轻/想象/素质/游戏/工作/手感/情况/稳定/期/惊喜/品控/影响/沉/测试/人脸识别/坏点/来评/偏黄/hhhh/守望/先锋/60fps/强迫症/蜜月/

Predict result : 好评	Actual results: 好评	Predict success!	


好评/默认/填写内容/

Predict result : 差评	Actual results: 差评	Predict success!	


开机/指纹/死机/差/卡机/

Predict result : 差评	Actual results: 差评	Predict success!	


真的/死机/黑屏/服/垃圾/重装系统/

Predict result : 差评	Actual results: 差评	Predict success!	


感觉/真人/上当/态度恶劣/

Predict result : 差评	Actual results: 差评	Predict success!	


屏幕/苹果/运行/速度/很快/真/说/看着/广告/开心/弹窗/产品质量/舒心/杂七杂八/

Predict result : 好评	Actual results: 好评	Predict success!	


外观/流畅/屏幕/舒适/运行/细腻/很爽/高级/真的/做工/系统/太/16/14/感/时间/发现/满满的/一台/瑕疵/点/小新/买过/大屏幕/看久/Air14/W11/thinkbook16/

Predict result : 好评	Actual results: 好评	Predict success!	


质量/ /说/服务/开/品牌/高端/跑/客户/激活/第二次/机子/退/跟不上/国产/良心/维修/上门/中心/机了/修/

Predict result : 差评	Actual results: 差评	Predict success!	


京东/买/说/关机/触摸板/鼠标/换货/失灵/两天/处理速度/找/没用/回去/差评/方式/寄/速度慢/费劲/提交/

Predict result : 差评	Actual results: 差评	Predict success!	


外观/屏幕/爱/物流/运行/速度/效果/外形/很帅/轻薄/程度/高/包装/下单/携带/触感/快递/送/不卡顿/保护/反正/绝子/越来越/清晰度/态度/支持/客服/色差/贼/惠普/嘻嘻/鼠标垫/代言/代言人/发展/模糊/吖/啰/沉重/出货/找坤坤/

Predict result : 好评	Actual results: 好评	Predict success!	


价格/购买/时/样子/鼠标/解决/成/找/元/价值/不合理/119/3699/4089/此事/机制/

Predict result : 差评	Actual results: 差评	Predict success!	


第一台/终于/选/好久/想/犹豫/越来越/拿下/希望/这天/三四年/换来/换取/

Predict result : 好评	Actual results: 好评	Predict success!	


鼠标/不配/差评/

Predict result : 差评	Actual results: 差评	Predict success!	


薄/屏幕/打开/终于/轻/感/金属/摸上去/冰冰凉凉/尺寸/迫不及待/一点点/旁边/整机/15.6/thinkpad/小一/

Predict result : 好评	Actual results: 好评	Predict success!	


性能/外观/散热/运行/速度/外形/轻薄/程度/很快/大气/热/开机/功能/OK/行/放在/详细/指导/桌子/

Predict result : 好评	Actual results: 好评	Predict success!	


速度/机器/送到/喜欢/17/感谢/疫情/期间/送达/预计/原本/隔/老爸/23/

Predict result : 好评	Actual results: 好评	Predict success!	


颜色/屏幕/散热/运行/速度/效果/高/机器/清晰/买/时/值得/性价比/太快/灵敏/推荐/款式/同事/耐看/发烫/明/

Predict result : 好评	Actual results: 好评	Predict success!	


性能/外观/薄/不错/运行/速度/外形/轻薄/程度/声音/很漂亮/清晰/特色/适合/便携/整体/看得/大学生/粉粉/

Predict result : 好评	Actual results: 好评	Predict success!	


外观/办公/运行/舒服/安静/风扇/声音/购买/算是/做工/精细/16/漂亮/总体/寸/值得/重量/适合/轻便/处理器/硬盘/工作/够用/开机/16G/kg/日常/内存/颜值/看着/金属/本子/压力/算/ps/高分辨率/高刷/介绍/在线/USB/i5/详细/扩展/大屏幕/人脸识别/网游/高色域/玩玩/良心/三面/妹子/隐藏式/板载/1.8/导购/预留/全能/守门员/07/ACD/听不懂/走心/位可供/

Predict result : 好评	Actual results: 好评	Predict success!	


挺/电脑/安装/情况/品控/联想/现象/工程师/有没有/差/拿来/闪屏/意见/驱动器/

Predict result : 差评	Actual results: 差评	Predict success!	


性能/外观/屏幕/散热/运行/速度/效果/外形/轻薄/程度/特色/性价比/优秀/超高/

Predict result : 好评	Actual results: 好评	Predict success!	


好看/颜色/运行/速度/外形/轻薄/真的/赶紧/下单/电脑/好用/犹豫/小伙伴/好好看/奥/

Predict result : 好评	Actual results: 好评	Predict success!	


性能/外观/薄/屏幕/散热/办公/运行/速度/效果/很爽/外形/轻薄/程度/重/电脑/超快/音效/特色/玩游戏/哈哈哈/太棒了/全金属/这高/清屏/值钱/没热过/

Predict result : 好评	Actual results: 好评	Predict success!	


京东/自营/物流/速度/打开/秒/包装/太/超快/惊艳/不用/完好/开机/开/推荐/好多年/够/卖/一顺间/纤溥/

Predict result : 好评	Actual results: 好评	Predict success!	


电脑/买/电子/两台/备注/纸质/开发票/

Predict result : 差评	Actual results: 差评	Predict success!	


京东/到货/没收/拖死/

Predict result : 差评	Actual results: 差评	Predict success!	


散热/做/特别/声音/很大/电脑/热/失望/几个/表格/差/排风扇/

Predict result : 差评	Actual results: 差评	Predict success!	


喜欢/颜值/爱住/

Predict result : 好评	Actual results: 好评	Predict success!	


不错/键盘/高/电脑/几天/发货/完好/收到/颜值/耐心/到货/客服/亮点/细致/友好/回答/有问必答/背光/盒子/两层/可控/内层/试运行/

Predict result : 好评	Actual results: 好评	Predict success!	


超级/买/实物/介绍/差/不符/千万别/骗/

Predict result : 差评	Actual results: 差评	Predict success!	


说/2022/2021/

Predict result : 差评	Actual results: 差评	Predict success!	


性能/外观/屏幕/散热/入手/苹果/耐用/运行/速度/效果/外形/电池/电脑/提升/体验/款/买/漂亮/年/情况/果断/能力/推荐/联想/第一款/2011/G460/空间/经济/许可/

Predict result : 好评	Actual results: 好评	Predict success!	


屏幕/不错/键盘/做工/质感/习惯/操作/摸/好大/符合/电源/外壳/用料/扎实/

Predict result : 好评	Actual results: 好评	Predict success!	


打开/电脑/买/太/后悔/文件/还卡/转圈圈/七八年/

Predict result : 差评	Actual results: 差评	Predict success!	


两个/客服/解决/黑屏/星期/莫名其妙/

Predict result : 差评	Actual results: 差评	Predict success!	


电脑包/送/鼠标/服/不送/算了/

Predict result : 差评	Actual results: 差评	Predict success!	


性能/强大/屏幕/分辨率/风扇/质感/说/16/寸/屏/稳定/检查/发现/便宜/这块/联想/70/图片/入/测试/收货/解决/开启/文本/家/60/打折/外接/健康/额外/异响/室内/荣耀/1080/U/相比之下/dlss/3050/轴/失真/红厂/添头/2077/图能/飙到/这不比/隔壁/小新香/

Predict result : 好评	Actual results: 好评	Predict success!	


性能/打开/说/强劲/三个/垃圾/cad/崩/妈/

Predict result : 差评	Actual results: 差评	Predict success!	


键盘/一点/换/反正/新/退回去/那么回事/

Predict result : 差评	Actual results: 差评	Predict success!	


好看/速度/下单/笔记本/第二天/喜欢/晚上/孩子/收到/上网/上午/课用/

Predict result : 好评	Actual results: 好评	Predict success!	


本次测试预测准确度为: 0.99

小结

通过和朴素贝叶斯模型实现的评论情感分析进行对比,可发现随机森林模型的预测准确度明显提高,稳定性也更强

但美中不足的是随机森林模型训练时间较长,实际开发中可能对系统效率有所影响。

  • 7
    点赞
  • 54
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Gaolw1102

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值