首页 > 解决方案 > 数据集中列的网络分析和停用词的使用

问题描述

我一直在处理数据集,但是当我在其中插入代码时,我得到了所有单词,例如“in”“and”。我试图删除这些常用词。我知道我需要使用停用词功能,但我不确定在哪里输入以及在它之后使用什么命令?除了“in”“for”“what”之外,我想找到用于描述列表的最多词

网络分析图

nycab$name <- as.character((nycab$name))
nycab$name <- tolower(nycab$name)
    
corpus <- Corpus(VectorSource(nycab$name))

nycwords_dfm <- dfm(nycab$name)
head(nycwords_dfm)
wordcountnyc_dfm <- dfm_select(nycwords_dfm, pattern = topwordcount)
topwordcount <- names(topfeatures(wordcountnyc_dfm,50))
head(topwordcount)
nycword_fcm <-fcm(wordcountnyc_dfm)
head(nycword_fcm)
nycwordcount2_fcm <- fcm_select(nycword_fcm, pattern = topwordcount)
textplot_network(nycwordcount2_fcm, min_freq = 0.1, edge_alpha = 0.8, edge_size = 5)

万一有人需要的数据集-https://www.kaggle.com/dgomonov/new-york-city-airbnb-open-data

标签: r

解决方案


看起来你正在使用 quanteda,所以去掉代码中的 tm 部分,即语料库行。

您可以使用dfm_remove来摆脱停用词。

nycwords_dfm <- dfm(nycab$name)
# remove stopwords
nycwords_dfm <- dfm_remove(nycwords_dfm, stopwords("english"))

# rest of your code
... 

如果您需要删除更多内容,请先使用令牌:

# remove punctuation and stopwords via tokens
nycwords_toks <- tokens(nycab$name, remove_punct = TRUE)
nycwords_toks <- tokens_remove(nycwords_toks, stopwords("english"))
nycwords_dfm <- dfm(nycwords_toks)

# rest of your code
....

推荐阅读