文本分析--情感分析
来源:互联网 发布:淘宝客学生采集群 编辑:程序博客网 时间:2024/04/19 08:23
文本分析–情感分析
自然语言处理(NLP)
• 将自然语言(文本)转化为计算机程序更容易理解的形式
• 预处理得到的字符串 -> 向量化
简单的情感分析
自己构造 情感字典
- 人工构造一个字典,如
like -> 1, good -> 2, bad -> -1, terrible -2
- 根据关键词匹配
问题:
遇到新词,特殊词等,扩展性较差
使用机器学习模型,nltk.classify
import nltkfrom nltk.stem import WordNetLemmatizerfrom nltk.corpus import stopwordsfrom nltk.classify import NaiveBayesClassifiertext1 = 'I like the movie so much!'text2 = 'That is a good movie.'text3 = 'This is a great one.'text4 = 'That is a really bad movie.'text5 = 'This is a terrible movie.'def proc_text(text): """ 预处处理文本 """ # 分词 raw_words = nltk.word_tokenize(text) # 词形归一化 wordnet_lematizer = WordNetLemmatizer() words = [wordnet_lematizer.lemmatize(raw_word) for raw_word in raw_words] # 去除停用词 filtered_words = [word for word in words if word not in stopwords.words('english')] # True 表示该词在文本中,为了使用nltk中的分类器 return {word: True for word in filtered_words}# 构造训练样本train_data = [[proc_text(text1), 1], [proc_text(text2), 1], [proc_text(text3), 1], [proc_text(text4), 0], [proc_text(text5), 0]]print(train_data)"""[[{'I': True, 'much': True, 'movie': True, 'like': True, '!': True}, 1], [{'good': True, '.': True, 'That': True, 'movie': True}, 1], [{'This': True, 'great': True, 'one': True, '.': True}, 1], [{'really': True, '.': True, 'That': True, 'movie': True, 'bad': True}, 0], [{'This': True, 'terrible': True, '.': True, 'movie': True}, 0]]"""# 训练模型nb_model = NaiveBayesClassifier.train(train_data)# 测试模型text6 = 'That is a bad one.'print(nb_model.classify(proc_text(text5)))#0
阅读全文
0 0
- 文本分析--情感分析
- 文本情感分析
- 文本情感分析
- 互联网文本情感分析
- 【nlp】文本情感分析
- snownlp文本情感分析使用
- 文本情感分析(一)
- TensorFlow RNN 文本情感分析
- Python 文本挖掘:使用情感词典进行情感分析
- 基于情感字典的文本情感极性分析
- 干货:完全基于情感词典的文本情感分析
- 微博文本情感分析-开篇
- R文本情感分析(3)
- 【R语言】文本挖掘-情感分析
- R文本挖掘之五情感分析
- CNN情感分析(文本分类)
- lstm 做 文本的情感分析
- 神经网络之文本情感分析(一)
- 深度理解链式前向星
- Python中的*arg和**kwarg
- 关于raw_input( )和sys.stdin.readline( )的区别
- X Chen笔记---Centos网卡设置混杂模式的方法
- 剑指Offer—41—和为S的连续正数序列
- 文本分析--情感分析
- 文章标题
- const修饰符,以及指针常量,常量指针的理解
- python 细数class中的 __**__
- 物联网专用网络商用在即——LoRa离我们不远了
- HDOJ1711 KMP模板程序
- MySQL高可用介绍2-heartbeat测试
- 全面介绍Android的MVVM框架
- 深入分析ClassLoader