r - 将特征共现与重要共现进行比较
问题描述
我想了解以下案例的实际差异:
- 使用函数
fcm(objectname # generate feature co-occurrence matrix
计算绝对频率。最后用函数绘图textplot_network()
。 - 我阅读了 tidytextmining 之类的教程,或者使用 igraph 或 widyr 包的 Andreas Niekler 和 Gregor Wiedemann 编写的教程。我想绘制相关的词对。受使用 phi 系数的 tidytextmining 教程的启发,我将根据 lambda 系数绘制这种相关性。
我不知道如何用包 quanteda 绘制相关的词对。我的想法是(可能不是一种有效的方法)计算
textstat_collocations()
并将其转换为 tibble 对象并使用 widyr 包的功能对其进行绘制。我的未解决问题是:如何将列搭配拆分为两个单独的列,例如 item1 item2 并添加选择列 lambda 并将其保存并分配给 tibble 对象?
> head(sotu_collocations,1)
collocation count count_nested length lambda z
1 smart city 229 0 2 9.846542 51.78172
解决方案
像这样?select()
如果您希望保留所有列,请删除该命令。
library("quanteda")
## Package version: 2.1.2
colls <- textstat_collocations(data_corpus_inaugural[1:5], size = 2)
head(colls)
## collocation count count_nested length lambda z
## 1 of the 98 0 2 1.494207 11.89704
## 2 has been 9 0 2 5.691667 11.61596
## 3 i have 15 0 2 3.754144 11.51091
## 4 may be 14 0 2 4.072366 11.43632
## 5 have been 10 0 2 4.679873 10.94315
## 6 we have 9 0 2 4.458284 10.35023
as.data.frame(colls) %>%
tidyr::separate("collocation", into = c("word1", "word2"), sep = " ") %>%
dplyr::select(word1, word2, lambda) %>%
tibble::tibble()
## # A tibble: 678 x 3
## word1 word2 lambda
## <chr> <chr> <dbl>
## 1 of the 1.49
## 2 has been 5.69
## 3 i have 3.75
## 4 may be 4.07
## 5 have been 4.68
## 6 we have 4.46
## 7 foreign nations 6.32
## 8 it is 3.50
## 9 my country 4.49
## 10 united states 7.22
## # … with 668 more rows
推荐阅读
- python - AttributeError: 'list' 对象在 TF-IDF 中没有属性 'lower'
- forms - 我们如何在 Workfront 中发布来自多个类别的自定义字段
- node.js - MongoDb 基于数组元素的聚合条件
- c# - Linq to Entities - 在 lambda 表达式中转换数据类型
- flutter - 异步和等待任务花费太多时间
- spring-boot - 如何将spring boot java app指向子域?
- android - 如何设置 Flutter CameraPreview 大小“全屏”
- ios - 使用 Swift 在 ARKit 中显示白色图像素材
- ios - iOS 应用的状态栏完全透明而不是半透明(使用 WKWebView)
- python - python gui tkinter中的绑定函数有问题