nlp情感分析经典书籍推荐

A simple tutorial to analyse the sentiment of a book in Python

一个简单的教程,用Python分析一本书的情感

入门 (Getting Started)

In this tutorial, I will show you how to apply sentiment analysis to the text contained into a book through an Unsupervised Learning (UL) technique, based on the AFINN lexicon. This tutorial exploits the afinn Python package, which is available only for English and Danish. If your text is written into a different language, you could translate it before in English and use the afinn package.

在本教程中,我将向您展示如何基于AFINN词典通过无监督学习(UL)技术将情感分析应用于书中包含的文本。 本教程利用afinn Python软件包,该软件包仅适用于英语和丹麦语。 如果您的文字是用其他语言书写的,则可以先使用英语将其翻译,然后使用afinn软件包。

This notebook applies sentiment analysis the Saint Augustine Confessions, which can be downloaded from the Gutemberg Project Page. The masterpiece is split in 13 books (or chapters). We have stored each book into a different file, named number.text (e.g. 1.txt and 2.txt). Each line of every file contains just one sentence.

本笔记本对圣奥古斯丁自白进行了情感分析,可从Gutemberg Project Page下载。 杰作分为13本书(或章节)。 我们已经将每本书存储到一个名为number.text的不同文件中(例如1.txt和2.txt)。 每个文件的每一行仅包含一个句子。

You can download the code from my Github repository: https://github.com/alod83/papers/tree/master/aiucd2021

您可以从我的Github存储库下载代码: https : //github.com/alod83/papers/tree/master/aiucd2021

First of all import the Afinn class from the afinn package.

首先,从afinn包中导入Afinn类。

from afinn import Afinn

Then create a new Afinn object, by specifying the used language.

然后通过指定使用的语言来创建一个新的Afinn对象。

afinn = Afinn(language=’en’)

计算情绪 (Calculate the Sentiment)

使用Afinn给出的分数来计算情感 (Use the score give by Afinn to calculate the sentiment)

The afinn object contains a method, called score(), which receives a sentence as input and returns a score as output. The score may be either positive, negative or neutral. We calculate the score of a book, simply by summing all the scores of all the sentence of that book. We define three variables> pos, neg and neutral, which store respectively the sum of all the positive, negative and neutral scores of all the sentences of a book.

afinn对象包含一个名为score()的方法,该方法接收一个句子作为输入并返回一个分数作为输出。 分数可以是正面,负面或中性。 我们只需将一本书所有句子的所有分数相加即可计算出一本书的分数。 我们定义三个变量:pos,neg和neutral,它们分别存储一本书所有句子的所有正,负和中性分数的总和。

Firstly, we define three indexes, which will be used after.

首先,我们定义三个索引,之后将使用它们。

pos_index = []neg_index = []neutral_index = []

We open the file corresponding to each book through the open() function, we read all the lines through the function file.readlines() and for each line, we calculate the score.

我们通过open()函数open()与每本书对应的文件,通过函数file.readlines()读取所有行,并为每一行计算分数。

Then, we can define three indexes to calculate the sentiment of a book: the positive sentiment index (pi), the negative sentiment index (ni) and the neutral sentiment index (nui). The pi of a book corresponds to the number of positive sentences in a book divided per the total number of sentences of the book. Similarly, we can calculate the ni and nui of a book.

然后,我们可以定义三个指数来计算一本书的情绪:正情绪指数(pi),负情绪指数(ni)和中性情绪指数(nui)。 一本书的pi对应于一本书中肯定的句子数除以该书的句子总数。 同样,我们可以计算一本书的ni和nui。

for book in range(1,14):    file = open('sources/' + str(book) + '.txt')    lines = file.readlines()    pos = 0    neg = 0    neutral = 0    for line in lines:        score = int(afinn.score(line))        if score > 0:            pos += 1        elif score < 0:            neg += 1        else:            neutral += 1    n = len(lines)    pos_index.append(pos / n)    neg_index.append(neg / n)    neutral_index.append(neutral / n)

绘制结果 (Plot results)

用图形表示结果 (Give a graphical representation to results)

Finally, we can plot results, by using the matplotlib package.

最后,我们可以使用matplotlib软件包来绘制结果。

import matplotlib.pyplot as pltimport numpy as npX = np.arange(1,14)plt.plot(X,pos_index,'-.',label='pos')plt.plot(X,neg_index, '--',label='neg')plt.plot(X,neutral_index,'-',label='neu')plt.legend()plt.xticks(X)plt.xlabel('Libri')plt.ylabel('Indici')plt.grid()plt.savefig('plots/afinn-bsi.png')plt.show()

经验教训 (Learned Lessons)

In this tutorial, I have shown you a simple strategy to calculate the sentiment of the text contained into a book. This can be achieved through the afinn package provided by Python. You can follow the following steps:

在本教程中,我向您展示了一种简单的策略来计算书中包含的文本的情感。 这可以通过Python提供的afinn包来实现。 您可以按照以下步骤操作:

  • organise the text of the book in chapters and store each chapter into a separate file将本书的文本按章组织,并将每章存储在单独的文件中
  • split all the sentences of each chapter in different lines将每一章的所有句子分成不同的行
  • calculate the score of each sentence separately through the score() method provided by the Afinn class

    通过Afinn类提供的score()方法分别计算每个句子的score()

  • calculate the positive sentiment index, the negative sentiment index and the neutral sentiment index of each chapter计算每章的正面情绪指数,负面情绪指数和中立情绪指数
  • plot results.绘制结果。

If you want to apply Supervised Learning techniques to perform sentiment analysis, you can stay tuned :).

如果您想应用监督学习技术来进行情绪分析,请继续保持::。

翻译自: https://towardsdatascience.com/sentiment-analysis-of-a-book-through-unsupervised-learning-df876563dd1b

nlp情感分析经典书籍推荐


http://www.taodudu.cc/news/show-2526780.html

相关文章:

  • NL驱动表错误导致的性能问题
  • 利用FILTER特性优化SQL
  • Python基础学习笔记-第一章
  • nlp情感分析经典书籍推荐_通过监督学习对书籍进行情感分析
  • java方法执行jvm做了什么_JVM 方法到底如何执行
  • 使用SharePoint Framework开发webpart的一些技巧汇总
  • K-均值聚类算法和二分K-均值算法
  • arm开发板开发环境搭建
  • 基于ubuntu的ARM开发环境搭建
  • ARM芯片学习内容规划及ARM开发环境的搭建
  • 几种ARM编译器及IDE开发环境
  • Go语言程序开发之ARM开发环境搭建
  • ARM开发工具介绍
  • arm 开发环境搭建-基于QEMU和Docker
  • QT5.12.1 ARM开发环境搭建 并 移植到RK3399 ubuntu16.04系统运行【完整版】
  • ARM开发比51开发高级吗—嵌入式就业技能分类
  • ARM裸机开发篇1:Cortex-A7开发环境搭建
  • qemu 搭建 ARM Linux环境
  • ARM 开发软件
  • ARM开发软件ADS教程
  • ARM开发——常见仿真器
  • arm裸机开发
  • ARM开发工具
  • Golang语言移植-ARM开发环境搭建
  • eclipse 搭建ARM开发环境
  • ARM开发初级-Windows环境下的STM32开发环境搭建(包含missing compiler version 5的解决方法)-学习笔记02
  • 基于Ubuntu 18.04打造嵌入式arm开发环境
  • 用QEMU搭建arm开发环境之一:QEMU能干啥
  • ARM7开发软件安装步骤
  • 嵌入式系统开发与应用——ARM 开发环境搭建及GPIO控制LED实验

nlp情感分析经典书籍推荐_通过无监督学习对书籍进行情感分析相关推荐

  1. python数据可视化书籍推荐_数据可视化的优秀入门书籍有哪些?

    数据可视化方向 首先你需要考虑清楚"非常感兴趣的数据可视化"属于哪一类? 数据可视化是个非常宽泛的领域,大体可以分为"信息图Infographic"和" ...

  2. python国内书籍推荐_久等了,你要的 Python 书籍推荐,来了!

    前言 时不时有小伙伴私信问我有什么好一些的 Python 书籍推荐,想要学习学习. 那么今天就来给大伙说道说道,我会划分为以下几个分类,让不同阶段的朋友可以根据自身的情况,选择适合自己当下学习的 Py ...

  3. python树莓派经典书籍推荐_树莓派教程书籍推荐:带你玩转Raspberry Pi

    随着<星球大战><复仇者联盟><NASA>等科幻电影的热映,人工制作装置也更加受到人们关注,与这些电影有关的一切设备都显得非常有科技感,格调很高.本期树莓派教程书籍 ...

  4. python量化自学书籍推荐_量化投资学习推荐的书籍都有哪些?

    给大家简单推荐介绍3本书吧这些都是比较实用的,入门还是高手级别的都有. 1. 打开量化投资的黑箱 这本书的作者里什·纳兰(Rishi K. Narang)是华尔街顶级数量金融专家,资深对冲基金经理.& ...

  5. python可视化案例书籍推荐_我用python5年后,我发现学python编程必看的三本书!...

    非常喜欢python 我非常喜欢python,在前几年里,它一直是我热衷使用并不断研究的语言,迄今为止,python都非常友好并且易于学习! 它几乎可以做任何事,从简单的脚本创建.web,到数据可视化 ...

  6. python高分书籍推荐_如果只能推荐一本 Python 书,我一定 Pick 它

    前段时间,我偶然看到了一条推特: <流畅的Python>一书的作者发布了一条激动人心的消息:他正在写作第二版! 如果要票选最佳的 Python 进阶类书目,这本书肯定会是得票率最高的书籍之 ...

  7. python高分书籍推荐_如果只推荐一本 Python 书,我要 Pick 它!

    今年二月初,我偶然看到了一条推特: <流畅的Python>一书的作者发布了一条激动人心的消息:他正在写作第二版! 如果要票选最佳的 Python 进阶类书目,这本书肯定会是得票率最高的书籍 ...

  8. 珍藏书籍,人工智能书籍推荐--AI“圣经”/超详细计算机视觉书籍赠送

    导读:悟已往之不谏,知来者之可追 人工智能(英语:Artificial Intelligence,缩写为AI)亦称智械.机器智能,指由人制造出来的机器所表现出来的智能.通常人工智能是指通过普通计算机程 ...

  9. 人工智能必读书籍推荐—“花书”/计算机视觉/深度学习书籍

    导读:悟已往之不谏,知来者之可追 人工智能(英语:Artificial Intelligence,缩写为AI)亦称智械.机器智能,指由人制造出来的机器所表现出来的智能.通常人工智能是指通过普通计算机程 ...

  10. 家用电器用户行为分析与事件识别_数据产品指北:用户行为分析平台

    本篇主要介绍了一些在用户行为分析平台中应用最广的产品功能和分析方法,包括:用户分群.留存分析.转化分析.行为路径分析和事件分析,与大家分享,供大家一同参考和学习. 相比于传统行业,用户行为分析平台可能 ...

最新文章

  1. c语言错误的等式,C语言学习中几个常见典型错误分析.docx
  2. AJAX的post请求与上传文件
  3. linux shell数组动态在for中追加元素及其遍历
  4. 饶毅教授对非升即走的思考
  5. 集群系统服务器,Web集群服务器及管理系统
  6. Python3标准库:asyncio异步I/O、事件循环和并发工具
  7. android html footer 固定,前端小技巧之footer固定
  8. 多线程面试题c Linux,【多线程Linux面试题】面试问题:小伙用C语言熬… - 看准网...
  9. Java集合类学习总结
  10. 数字通信原理与TCP/IP
  11. xshell中文问号乱码
  12. 【车间调度】遗传算法求解柔性作业车间调度问题
  13. broadcom学习心得
  14. MySQL基础篇——存储过程和函数中的变量
  15. 谷歌插件数据爬取:基本信息采集
  16. 四大检索工具 和 论文查找网址大全
  17. python和java和c语言的区别-python和c语言的主要区别总结
  18. Html中几种特别分割线特效
  19. VBA小程序--针对所有已经打开的Excel文件_格式调整_针对所有工作表_冻结首行_无视所在位置
  20. kali中的firefox无法打开:your tab just crashed

热门文章

  1. 曾经的荣誉,偶然被唤醒
  2. ResourceManager HA 配置
  3. 为什么好多人说win8不好用?
  4. php制作国旗头像图片,不要再@微信官方了,自己动手一秒制作国旗头像
  5. 提问的力量四:提问的艺术-体验学习中提问的技巧
  6. 国家AAAAA级旅游景区数量统计
  7. arm跑操作系统的意义_上手一个具体而微的 ARM 操作系统
  8. ETF基金定投策略回测分析
  9. 北上杭是梦!“郑福贵”才是中国智慧城市的真相
  10. surfacepro3运行C语言,【微软 Surface PRO3使用总结】C面|D面|噪音|材质_摘要频道_什么值得买...