附代码 基于NLP的COVID-19虚假新闻检测( 二 )
polarity_length.py

文章插图
图三
数据集中的大多数文章少于1000个单词 。不过 , 有少数文章超过4000个单词 。
当我们按标签区分时 , 就文章的长度而言 , 真实新闻和虚假新闻之间没有明显的区别 , 尽管在数据集中大多数真实新闻似乎都比虚假新闻短一些 。
1. fig = px.histogram(df, x="text_len", y="text", color="label",2.marginal="box",3.hover_data=https://www.isolves.com/it/cxkf/cxy/2020-07-05/df.columns, nbins=100)4. fig.update_layout(title_text='Distribution of article length', template="plotly_white")5. fig.show()text_len_hist.py
文章插图
图四
为了显示不同新闻的文本长度的概率密度 , 我们使用小提琴图(violin plot)表示:
1. fig = px.violin(df, y='text_len', color='label',2.violinmode='overlay',3.hover_data=https://www.isolves.com/it/cxkf/cxy/2020-07-05/df.columns, template='plotly_white')4. fig.show()text_len_violin.py
文章插图
图五
- Facebook vs. Harvard
1. df_new = df.loc[(df['source'] == 'Facebook') | (df['source'] == 'https://www.health.harvard.edu/')]2.3. fig = px.histogram(df_new, x="text_len", y="text", color='source',4.marginal="box",5.hover_data=https://www.isolves.com/it/cxkf/cxy/2020-07-05/df_new.columns, nbins=100)6. fig.update_layout(title_text='Distribution of article length of two sources', template="plotly_white")7. fig.show()facebook_harvard_textlen_hist.py
文章插图
图六
我们也可以使用小提琴图(violin plot)来呈现:
1. fig = px.violin(df_new, y='text_len', color='source', 2. violinmode='overlay', 3. hover_data=https://www.isolves.com/it/cxkf/cxy/2020-07-05/df_new.columns, template='plotly_white') 4. fig.show() facebook_harvard_textlen_violin.py
文章插图
图七
也许我们大家都很熟悉 , Facebook虚假帖子的内容往往更短 。发表文章的人试图通过试探法而非说服力来说服读者 。
- 情感极性
1. x1 = df.loc[df['label']=='TRUE']['polarity']2. x2 = df.loc[df['label'] == 'FAKE']['polarity']3.4. group_labels = ['TRUE', 'FAKE']5.6. colors = ['rgb(0, 0, 100)', 'rgb(0, 200, 200)']7.8. fig = ff.create_distplot(9.[x1, x2], group_labels,colors=colors)10.11. fig.update_layout(title_text='polarity', template="plotly_white")12. fig.show()label_polarity.py
文章插图
图八
真实新闻与虚假新闻在情感方面没有明显差异 , 我们可以使用小提琴图(violin plot)来证实:
1. fig = p.violin(df, y='polarity', color="label", 2.violinmode='overlay',3.template='plotly_white')4. fig.show()polarity_violin.py
文章插图
图九
当我们比较这四个来源之间的情绪极性时 , 我们可以看到《纽约时报》和《自然新闻》的情绪分布比哈佛健康新闻和Facebook的情绪分布要窄得多 。
1. x1 = df.loc[df['source']=='Facebook']['polarity']2. x2 = df.loc[df['source'] == 'https://www.health.harvard.edu/']['polarity'] 3. x3 = df.loc[df['source'] == 'https://www.nytimes.com/']['polarity'] 4. x4 = df.loc[df['source'] == 'https://www.naturalnews.com/']['polarity'] 5. group_labels = ['Facebook', 'Harvard', 'nytimes', 'naturalnews'] 6. 7. colors = ['rgb(0, 0, 100)', 'rgb(0, 200, 200)', 'rgb(100, 0, 0)', 'rgb(200, 0, 200)'] 8. 9. # Create distplot with custom bin_size 10. fig = ff.create_distplot( 11. [x1, x2, x3, x4], group_labels,colors=colors) 12. 13. fig.update_layout(title_text='polarity', template="plotly_white") 14. fig.show()
推荐阅读
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 含完整源代码和开发文档 人工智能图像识别绘本阅读方案
- 如何基于TCP/IP协议进行MFC Socket网络通讯编程
- 500以下无线键盘简评,附高斯GS87D体验总结
- Python量化工具之“k线波幅加速”算法跟踪止盈,仅需一行代码
- 基于XML描述的可编程函数式ETL实现
- 教你如何用android mvp分层架构优雅写代码
- 一行代码搞定百度文库VIP功能
- 带你读懂信息安全中的恶意代码、病毒、木马、蠕虫......
- 常见分布式锁实现方式
- 恶意代码分析之Office宏代码分析
