假新聞中的名詞用法
在這個練習中,給你一個名為 headlines 的 dataframe,裡面包含真假新聞的標題。你的任務是產生兩個新特徵 num_propn 和 num_noun,分別代表 headlines 的 title 特徵中所含的專有名詞數量與其他名詞數量。
接著,我們會分別計算真假新聞標題中專有名詞與其他名詞的平均數,並比較兩者。如果差異明顯,那麼在假新聞偵測器中使用 num_propn 與 num_noun 這兩個特徵,很可能能提升效能。
為了完成這個任務,你在前一個練習中建立的 proper_nouns 與 nouns 函式已經可以直接使用。
本練習屬於課程
Python 中文本特徵工程
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
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))