欢迎!

Python 中的情感分析

Violeta Misheva

Data Scientist

什么是情感分析?

 

情感分析是理解作者对某一主题的看法的过程。

Python 中的情感分析

情感分析系统包含哪些要素?

第一要素:观点/情绪

  • 观点(极性):正、 中性、 负

正面、中性和负面极性

 

  • 情绪

不同情绪示例

Python 中的情感分析

情感分析系统包含哪些要素?

第二要素:主题

  • 讨论主题:在谈什么

这款手机的相机很好,但电池续航有些令人失望。

第三要素:观点持有者

  • 观点持有者(实体):谁说的
Python 中的情感分析

为何进行情感分析?

  • 社交媒体监测
    • 不仅看谈论的内容,还要看表达的方式
    • 情感也可来自论坛、博客、新闻
  • 品牌监测
  • 客户服务
  • 产品分析
  • 市场研究与分析
Python 中的情感分析

看看电影评论!

data.head()

IMDB 电影评论数据集的前 5 行

Python 中的情感分析

正面与负面评论各有多少?

data.label.value_counts()
0    3782
1    3719
Name: label, dtype: int64
Python 中的情感分析

正负面评论的百分比

data.label.value_counts() / len(data)
0    0.504199
1    0.495801
Name: label, dtype: float64
Python 中的情感分析

最长的评论有多长?

length_reviews = data.review.str.len()
type(length_reviews)
pandas.core.series.Series
# Finding the review with max length
max(length_reviews)
0    667
1    2982
2    669
3    1087
....
Python 中的情感分析

最短的评论有多短?

length_reviews = data.review.str.len()
# Finding the review with min length
min(length_reviews)
0    667
1    2982
2    669
3    1087
4    724
....
Python 中的情感分析

让我们来练习!

Python 中的情感分析

Preparing Video For Download...