您好我在R和RTextTools中编程时遇到以下MSDN尝试运行此代码
# CREATE THE DOCUMENT-TERM MATRIX
doc_matrix <- create_matrix(USCongress$text,
language="english", removeNumbers=TRUE,
stemWords=TRUE, removeSparseTerms=.998)`
我收到此错误
as.matrix(textColumns)出错:对象&#39; USCongress&#39;没找到。
答案 0 :(得分:0)
尝试安装包maxent
,这是一个包含来自美国国会的标记账单的样本数据集。
install.packages("maxent")
library(maxent)
# Import data
USCongress <- read.csv(system.file("data/USCongress.csv.gz",package="maxent"))
doc_matrix <- create_matrix(USCongress$text, language="english", removeNumbers=TRUE,
stemWords=TRUE, removeSparseTerms=.998)
And output:
<<DocumentTermMatrix (documents: 4449, terms: 904)>>
Non-/sparse entries: 49528/3972368
Sparsity : 99%
Maximal term length: 14
Weighting : term frequency (tf)
答案 1 :(得分:0)
我在setmWords = TRUE上发现了问题,我对FALSE进行了更改,并且代码工作正常 `
library(maxent)
library(RTextTools)
library(tm)
# Import data
data(USCongress)
doc_matrix <- create_matrix(USCongress$text, language="english", removeNumbers=TRUE,
stemWords=FALSE, removeSparseTerms=.998)
container <- create_container(doc_matrix, USCongress$major, trainSize=1:4000,
testSize=4001:4449, virgin=FALSE)
SVM <- train_model(container,"SVM")
GLMNET <- train_model(container,"GLMNET")
MAXENT <- train_model(container,"MAXENT")
SLDA <- train_model(container,"SLDA")
BOOSTING <- train_model(container,"BOOSTING")
BAGGING <- train_model(container,"BAGGING")
RF <- train_model(container,"RF")
NNET <- train_model(container,"NNET")
TREE <- train_model(container,"TREE")
SVM_CLASSIFY <- classify_model(container, SVM)
GLMNET_CLASSIFY <- classify_model(container, GLMNET)
MAXENT_CLASSIFY <- classify_model(container, MAXENT)
SLDA_CLASSIFY <- classify_model(container, SLDA)
BOOSTING_CLASSIFY <- classify_model(container, BOOSTING)
BAGGING_CLASSIFY <- classify_model(container, BAGGING)
RF_CLASSIFY <- classify_model(container, RF)
NNET_CLASSIFY <- classify_model(container, NNET)
TREE_CLASSIFY <- classify_model(container, TREE)
analytics <- create_analytics(container,
cbind(SVM_CLASSIFY, SLDA_CLASSIFY,
BOOSTING_CLASSIFY, BAGGING_CLASSIFY,
RF_CLASSIFY, GLMNET_CLASSIFY,
NNET_CLASSIFY, TREE_CLASSIFY,
MAXENT_CLASSIFY))
topic_summary <- analytics@label_summary
SVM <- cross_validate(container, 4, "SVM")
` 知道我去使用阿拉伯语任何建议