结构主题模型(二)复现
程序员文章站
2022-06-04 09:07:46
...
简介:整理在复现论文(stm An R Package for Structural Topic Models)代码过程中的注意事项和报错信息
复现代码
下载代码及数据1
文件名 | 解释 |
---|---|
v091i02.R | stm代码 |
poliblogs2008.csv | 数据 |
results.rda | 模型训练结束后,保存的变量文件 |
导包
stm包依赖R(≥ 3.5.0)2
install.packages("stm")
导入数据
导入论文作者提供的csv文件后,总是报各种类型的错误
问题一:read.table()[^R_fx_xlsx]
Warning messages: 1: In read.table(file = file, header = header, sep = sep, quote = quote, : invalid input found on input connection 'data_preprocessing_test1a.csv'
2: In read.table(file = file, header = header, sep = sep, quote = quote, : incomplete final line found by readTableHeader on 'data_preprocessing_test1a.csv'
Error in read.table(file = file, header = header, sep = sep, quote = quote, : more columns than column names
问题三:EOF with quoted string5
In scan(file = file, what = what, sep = sep, quote = quote, dec = dec, : EOF within quoted string
问题四:对于中文文本,易因换行/n
等其他分隔符使得程序对csv文件解析错误6
导入.xlsx
或./xls
格式的数据就能避免和解决上述问题7
install.packages("readxl")
library(readxl)
data <- read_excel(path="data_preprocessing_test1a.xlsx", sheet="your_sheet_name", col_names= TRUE)
代码执行
问题一
system is computationally singular: reciprocal condition number = 1.06304e-19
存在矩阵不可逆,对于矩阵A而言,det(A)=/≈0都会使得A不可逆。
R中函数det()用于计算矩阵的行列式
matrix - System is computationally singular: reciprocal condition number in R - Stack Overflow
问题二
K=2 is equivalent to a unidimensional scaling model which you may prefer.
选择主题数时不宜选择等于或低于2的主题数,这样的话,结构主题模型就不能发挥较大的作用
问题三
Error in findThoughts(out.stm, topics = 27, texts = corpus$documents$texts, : Number of provided texts and number of documents modeled do not match
参考文章:
上一篇: 美国总统用iPhone呼吁:苹果应帮助当局解锁手机
下一篇: python进阶