爬取京东商城中指定商品下的用户评论,对数据预处理后基于SnowNLP的sentiment模块对文本进行情感分析。
- Mac OS X 兼容更低版本
- Python3.7
requirements.txt
- Pycharm
- 启动
jd_comment.py
,建议修改jd_comment.py
中变量user-agent为自己浏览器用户代理 - 输入京东商品完整URL
- 得到京东评论词云,存放于
jd_ciyun.jpg
(词云轮廓形状存放于jdicon.jpg
) - 得到京东评论数据,存放于
jd_comment.csv
- 准备正负语料集
online_shopping_10_cats.csv
,分别存入negative.txt和positive.txt - 启动
train.py
,新建文件sentiment.marshal
,存入训练后的模型 - 找到外部库中snownlp中sentiment模块,将训练得到的
sentiment.marshal.3
文件覆盖sentiment模块中自带的sentiment.marshal.3
- 启动
sentiment.analysis.py
- 开始对
jd_comment.csv
中评论进行数据处理,处理后文件存入processed_comment_data.csv
- sentiment模块根据
sentiment.marshal.3
对评论进行情感评分,评分结果存入result.csv
- 评分结果可视化,生成文件
fig.png
- 词云轮廓图