假新闻中的名词使用
在本练习中,您将获得一个名为 headlines 的数据框,包含真假新闻的标题。您的任务是生成两个新特征 num_propn 和 num_noun,分别表示 headlines 的 title 特征中专有名词和其他名词的数量。
接下来,我们将分别计算真假新闻标题中专有名词和其他名词的平均数量,并进行比较。如果差异明显,那么在假新闻检测器中使用 num_propn 和 num_noun 这两个特征很可能会提升性能。
为完成该任务,您在上一个练习中构建的函数 proper_nouns 和 nouns 已为您准备好。
本练习是课程的一部分
Python 中的 NLP 特征工程
交互式实操练习
通过完成这段示例代码来试试这个练习。
headlines[____] = headlines['title'].apply(____)
# Compute mean of proper nouns
real_propn = headlines[headlines['label'] == 'REAL']['num_propn'].mean()
fake_propn = headlines[headlines['label'] == 'FAKE']['num_propn'].____
# Print results
print("Mean no. of proper nouns in real and fake headlines are %.2f and %.2f respectively"%(real_propn, fake_propn))