情感分析朴素贝叶斯

Millions of tweets are posted every second. It helps us know how the public is responding to a particular event. To get the sentiments of tweets, We can use the Naive Bayes classification algorithm, which is simply the application of Bayes rule.

每秒发布数百万条推文。 它可以帮助我们了解公众如何响应特定事件。 为了获得推文的情感,我们可以使用朴素贝叶斯分类算法,这只是贝叶斯规则的应用。

贝叶斯规则 (Bayes Rule)

Bayes rule is merely describing the probability of an event on prior knowledge of the occurrence of another event related to it.

贝叶斯规则仅是根据与之相关的另一个事件的发生的先验知识来描述事件的概率。

Then the probability of occurrence of event A given that event B has already occurred is

假设事件B已经发生,则事件A发生的概率为

And for the probability of occurrence of event B given that event A has already occurred is

对于事件B发生的概率,假设事件A已经发生,则为

Using both these equations, we can rewrite them collectively as

使用这两个等式,我们可以将它们统一重写为

Let’s take a look at tweets and how we are going to extract features from them

让我们看一下推文以及我们如何从中提取功能

We will be having two corpora of tweets, positive and negative tweets.

我们将有两种推文,正面和负面推文。

Positive tweets: ‘I am happy because I am learning NLP,’ ‘I am happy, not sad.’

积极的推文 :“我很高兴,因为我正在学习NLP”,“我很高兴,而不是悲伤”。

Negative tweets: ‘I am sad, I am not learning NLP,’ ‘I am sad, not happy.’

负面推文 :“我很难过,我没有学习NLP”,“我很难过,不开心”。

前处理 (Preprocessing)

We need to preprocess our data so that we can save a lot of memory and reduce the computational process.

我们需要对数据进行预处理,以便节省大量内存并减少计算过程。

  1. Lowercase: We will convert all the text to lower case. so, that the words like Learning and leaning can be taken as same words小写:我们将所有文本转换为小写。 因此,可以将像“学习”和“学习”之类的词视为同一词
  2. Removing punctuations, URLs, names: We will remove the punctuations URLs and names or hashtags because they don’t contribute to sentiment analysis of a tweet.删除标点符号,URL,名称:我们将删除标点符号URL,名称或主题标签,因为它们对推文的情绪分析没有帮助。
  3. Removing stopwords: The stopwords like ‘the’, ‘is’ don’t contribute in sentiment. Therefore these words have to be removed.删除停用词:诸如“ the”,“ is”之类的停用词不会助长情绪。 因此,必须删除这些单词。
  4. Stemming: The words like ‘took’, ‘taking’ are treated as the same words and are converted to there base words, here it is ‘take’. This saves a lot of memory and time.词干:“ took”,“ take”等词被视为相同的词,并转换为那里的基本词,此处为“ take”。 这样可以节省大量内存和时间。

概率方法: (Probabilistic approach:)

In order to get the probability stats for the words, we will be creating a dictionary of these words and counting the occurrence of each word in positive and negative tweets.

为了获得单词的概率统计信息,我们将创建这些单词的字典,并以正面和负面推文计算每个单词的出现次数。

Let’s see how these word counts are helpful in finding the probability of the word for both classes. Here the word ‘i’ occurred three times, and the total unique words in the positive corpus are 13. Therefore, the probability of occurrence of the word ‘i’ given that the tweet is positive will be

让我们看看这些单词计数对查找两个类中单词的概率有何帮助。 在这里,单词“ i”出现了3次,并且正语料库中的唯一词总数为13。因此,假设推文为肯定,则单词“ i”出现的概率为

freq denotes the frequency of occurrence of a word, class: {pos, neg}
freq表示单词出现的频率,类别:{pos,neg}

Doing this for all our words in our vocabulary, we will get a table like this:

对我们词汇表中的所有单词执行此操作,我们将获得一个如下表:

In the Naive Bayes, We will find how each word is contributing to the sentiment, which can be calculated by the ratio of the probability of occurrence of the word for positive and negative class. Let’s take an example; We can see that the probability of occurrence of the word ‘sad’ is more for negative than positive class. So, we will find the ratio of these probabilities for every word by the formula:

在朴素贝叶斯中,我们将发现每个单词如何对情感产生影响,可以通过正负两类单词出现的概率之比来计算。 让我们举个例子。 我们可以看到,“消极”一词出现的可能性在消极类别中比在积极类别中更大。 因此,我们将通过公式找到每个单词的这些概率之比:

This ratio is known as the likelihood, and its value lies between (0, ∞). The value tending to zero indicates that it has very low probability to occur in a positive tweet as compared to the probability to occur in a negative tweet and the ratio value tending to infinity shows that it has very low probability to occur in a negative tweet as compared to the probability to occur in a positive tweet. In other words, the high value of ratio implies positivity. Also, the ratio value 1 means that the name is neutral.

该比率称为似然,其值介于(0,∞)之间。 趋于零的值表示与在负面推文中出现的可能性相比,在正推文中发生的可能性非常低,并且比率值趋于无穷大表示在负推文中发生的可能性非常低,例如与出现正面推文的可能性相比。 换句话说,比率的高值表示阳性。 此外,比率值1表示名称是中性的。

拉普拉斯平滑 (Laplace Smoothing)

Some words might have occurred in any particular class only. The words which did not occur in the negative class will have probability 0 which makes the ratio undefined. So, we will use the Laplace smoothing technique to pursue this kind of situation. Let’s take on how equation changes on applying Laplace smoothing:

某些单词可能仅在任何特定类中出现过。 否定类中未出现的单词的概率为0,这使得比率不确定。 因此,我们将使用拉普拉斯平滑技术来解决这种情况。 让我们来看看在应用拉普拉斯平滑处理时方程如何变化:

By adding ‘1’ in the numerator makes the probability non zero. This factor is called alpha-factor and is between (0,1]; specifically, when we set this alpha-factor to 1, the smoothing is termed as Laplace smoothing. Also, the sum of probabilities will remain at 1.

通过在分子中加“ 1”,使概率非零。 该因子称为Alpha因子,介于(0,1]之间;具体来说,当我们将此Alpha因子设置为1时,平滑称为Laplace平滑,而且概率之和将保持为1。

Here in our example, the number of unique words is eight gives us V= 8.

在我们的示例中,唯一字的数量为8,因此我们得到V = 8。

After Laplace smoothing the table of the probability will look like this:

在拉普拉斯平滑之后,概率表将如下所示:

朴素贝叶斯: (Naive Bayes:)

To estimate the sentiment of a tweet, we will take the product of the probability ratio of each word occurred in the tweet. Note, the words which are not present in our vocabulary will not contribute and will be taken as neutral. The equation for naive Bayes in our application will be like this:

要估算推文的情绪,我们将采用推文中每个单词出现的概率比的乘积。 请注意,我们词汇表中不存在的单词将不会有帮助,并将被视为中立的。 在我们的应用程序中,朴素贝叶斯方程将如下所示:

m = number of words in a tweet, w = set of words in a tweet
m =一条推文中的单词数,w =一条推文中的单词集

Since the data can be imbalanced and can cause biased results for a particular class, we multiply the above equation with a prior factor, which is the ratio of the probability of positive tweets to the probability of negative tweets.

由于数据可能不平衡,并且可能导致特定类别的结果有偏差,因此我们将上述方程式与先验因子相乘,这是正面推文的概率与负面推文的概率之比。

complete equation of Naive Bayes
朴素贝叶斯的完整方程

Since we are taking the product of all these ratios, we can end up with a number too large or too small to be stored on our device, so here comes the concept of log-likelihood. We take the log over our equation of Naive Bayes.

由于我们采用了所有这些比率的乘积,因此最终得出的数字太大或太小而无法存储在设备中,因此出现了对数似然的概念。 我们将日志记录在朴素贝叶斯方程上。

After taking the log of the likelihood equation, the scale will be changed as follows:

取似然方程的对数后,比例将如下更改:

Let’s see an example. Tweet: ‘I am happy because I am learning.

让我们来看一个例子。 推文:“我很高兴,因为我正在学习。

This is the overall log-likelihood for our tweet.
这是我们的推文的总体对数可能性。

Hence, the value of the overall log-likelihood of the tweet is greater than zero, which implies that the tweet is positive.

因此,该推文的总体对数似然值大于零,这表示该推文为正。

缺点: (Drawbacks:)

  1. Naive Bayes algorithm assumes that the words are independent of each other.朴素贝叶斯算法假设单词彼此独立。
  2. Relative frequencies in the corpus: Some times the people blocks particular type of tweets which might be offensive, etc. which leads to an imbalance of data语料库中的相对频率:有时人们会阻止可能令人反感的特定类型的推文,这会导致数据不平衡
  3. Word order: By changing the order of words, the sentiment might change, but with Naive Bayes, we can not encounter that.单词顺序:通过更改单词顺序,可能会改变情绪,但是对于朴素贝叶斯,我们无法做到这一点。
  4. Removal of punctuations: Remember in data preprocessing, we removed punctuations, which might change the sentiment of the tweet. Here is an example: ‘My beloved grandmother :( ’删除标点符号:请记住,在数据预处理中,我们删除了标点符号,这可能会改变推文的情绪。 这是一个例子:'我亲爱的祖母:('

结论: (Conclusion:)

The Naive Bayes is a straightforward and powerful algorithm, knowing the data one can preprocess the data accordingly. Naive Bayes algorithm is also used in many aspects of society like spam classification, Loan approval, etc.

朴素贝叶斯算法是一种简单而强大的算法,它知道数据可以相应地进行预处理。 朴素贝叶斯算法还被用于社会的许多方面,例如垃圾邮件分类,贷款批准等。

翻译自: https://towardsdatascience.com/sentiment-analysis-of-a-tweet-with-naive-bayes-ff9bdb2949c7

情感分析朴素贝叶斯


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

相关文章:

  • 梯度下降优化方法'原理_优化梯度下降的新方法
  • DengAI —数据预处理
  • k 最近邻_k最近邻与维数的诅咒
  • 使用Pytorch进行密集视频字幕
  • 5g与edge ai_使用OpenVINO部署AI Edge应用
  • 法庭上认可零和博弈的理论吗_从零开始的本征理论
  • 极限学习机和支持向量机_极限学习机I
  • 如何在不亏本的情况下构建道德数据科学系统?
  • ann人工神经网络_深度学习-人工神经网络(ANN)
  • 唐宇迪机器学习课程数据集_最受欢迎的数据科学和机器学习课程-2020年8月
  • r中如何求变量的对数转换_对数转换以求阳性。
  • 美团脱颖而出的经验_使数据科学项目脱颖而出的6种方法
  • aws rds同步_将数据从Python同步到AWS RDS
  • 扫描二维码读取文档_使用深度学习读取和分类扫描的文档
  • 电路分析导论_生存分析导论
  • 强化学习-第3部分
  • 范数在机器学习中的作用_设计在机器学习中的作用
  • 贝叶斯深度神经网络_深度学习为何胜过贝叶斯神经网络
  • 模型监控psi_PSI和CSI:前2个模型监控指标
  • flask渲染图像_用于图像推荐的Flask应用
  • pytorch贝叶斯网络_贝叶斯神经网络:2个在TensorFlow和Pytorch中完全连接
  • 稀疏组套索_Python中的稀疏组套索
  • deepin中zz_如何解决R中的FizzBu​​zz问题
  • 图像生成对抗生成网络gan_GAN生成汽车图像
  • 生成模型和判别模型_生成模型和判别模型简介
  • 机器学习算法 拟合曲线_制定学习曲线以检测机器学习算法中的错误
  • 重拾强化学习的核心概念_强化学习的核心概念
  • gpt 语言模型_您可以使用语言模型构建的事物的列表-不仅仅是GPT-3
  • 廉价raid_如何查找80行代码中的廉价航班
  • 深度学习数据集制作工作_创建我的第一个深度学习+数据科学工作站

情感分析朴素贝叶斯_朴素贝叶斯推文的情感分析相关推荐

  1. 基于sklearn的朴素贝叶斯_朴素贝叶斯分类实战:对文档进行分类

    朴素贝叶斯分类最适合的场景就是文本分类.情感分析和垃圾邮件识别.其中情感分析和垃圾邮件识别都是通过文本来进行判断.所以朴素贝叶斯也常用于自然语言处理 NLP 的工具. sklearn 机器学习包 sk ...

  2. python推荐系统算法朴素贝叶斯_朴素贝叶斯算法在人才盘点中的应用(之一)

    一.识别人才首先是处理不确定性问题 做招聘面试的HR应该会认同这样的经历. 打开应聘者简历,赫然写着TOP10名学毕业.抬头一瞧,小伙长得一表人才,精神抖擞,朝气蓬勃.HR兴趣大增. 再一看,研究方向 ...

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

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

  4. 特朗普推文的文本分析

    导言 通常不会发布关于政治的信息(我对投票不是特别精明,这是数据科学对政治产生最大影响的地方),但本周末我看到了一个关于唐纳德特朗普的推特账户的假设,这个假设只是被要求调查有数据: 当特朗普祝奥运队好 ...

  5. java 朴素贝叶斯_朴素贝叶斯分类器和一般的贝叶斯分类器有什么区别?

    我根据自己理解,给出朴素贝叶斯分类算法的核心,在里面会有通俗详细的解释,希望对你有帮助~ 贝叶斯分类是一类分类算法的总称,这类算法均以贝叶斯定理为基础,故统称为贝叶斯分类.而朴素朴素贝叶斯分类是贝叶斯 ...

  6. sklearn朴素贝叶斯分类器_朴素贝叶斯原理

    贝叶斯分类算法是统计学是一种概率分类方法,朴素贝叶斯分类时贝叶斯分类中最简单的一种.利用贝叶斯公式根据某特征的先验概率计算出其后延概率,然后选择具有最大后延概率的类作为该特征所属的类.朴素贝叶斯,称之 ...

  7. gitstack连接詹金斯_詹金斯的Maven报告

    gitstack连接詹金斯 代码质量是一个敏感的话题. 它会影响您的维护成本以及客户满意度. 更不用说您的开发人员使用代码的动力. 谁想要修复难看的代码,对吗? 讨论代码质量总是需要事实和数字! 因此 ...

  8. python 布莱克舒尔斯_布莱克-舒尔斯-墨顿期权定价模型

    1. 布莱克-舒尔斯-墨顿期权定价模型(Black–Scholes–Merton Option Pricing Model) 布莱克-舒尔斯-墨顿模型(Black–Scholes–Merton mod ...

  9. python 布莱克舒尔斯_布莱克—舒尔斯期权定价模型

    布莱克-舒尔斯期权定价模型.ppt Neokodama |  2011-09-23 17:37 21页 | 220KB | 2次下载 | (3人评价) 举报 | 用手机看文档 扫一扫,手机看文档 布莱 ...

最新文章

  1. 基于Tkinter利用python实现颜色空间转换程序
  2. 互联网协议 — D-IP(确定性的)网络架构
  3. 【转】深入理解JavaScript闭包(closure)
  4. SPOJ D-query(莫队算法模板)
  5. 随想录(中间件接口的定义方法)
  6. 做csdn图片水印中最亮的崽
  7. 从0到1打造一款react-native App(二)Navigation+Redux
  8. php mysql修复_php简单备份与还原MySql的方法 | 瑕疵学院 – 学习无瑕疵,成就有保障...
  9. John the Ripper 著名密码破解工具
  10. c# json 汉字乱码_C# 读取Json内的数据,中文乱码,怎么解决
  11. 微信小程序中字符串转JSON
  12. Skyscrapers (hard version)
  13. 无线承载根据承载的内容不同分为SRB和DRB EPS承载根据用户业务需求和Qos的不同可以分为GBR/ Non-GBR 承载...
  14. 搭建智能语音助手思路整理
  15. java开灯问题_算法入门之开灯问题
  16. 线性丢番图方程的C++实现
  17. 高德地图H5 定位失败报错 geolocation time out. Get ipLocation failed解决方案
  18. download file with c++
  19. “盘古”走向产业山峦,打开了一串AI落地的新脑洞
  20. Linux的命令行无法粘贴

热门文章

  1. RSS 没有死亡 而是无所不在
  2. 关于java中的数组
  3. [转]各种字符集和编码详解
  4. jQuery教程2---隐藏p标签内容-按钮
  5. oracle备份磁盘头,oracle asm 磁盘头数据以及备份与恢复基础篇(2)
  6. python怎么定义全局字典_一种Python全局配置规范以及其魔改
  7. java 搭建企业应用框架_java培训一般要学多久
  8. 细胞自动机 通用计算机,细胞自动机
  9. r语言 断轴 画图_R语言作图——Density plot
  10. maven snapshot依赖 打包_Maven教程2:Maven项目构建过程练习