【问题标题】:document classification with r使用 r 进行文档分类
【发布时间】:2014-03-27 07:15:27
【问题描述】:

我一直在尝试使用 R 来跟踪 document classification tutorial on YouTube,这真的很有趣,但是当我尝试运行脚本的第一部分时,我不断收到此错误 Error in FUN(c("obama", "romney")[[1L]], ...) : could not find function "corpus"。我真的不知道为什么会这样,但我希望有人能帮我弄清楚。

这是脚本:

#init
libs <- c("tm", "plyr", "class")
lapply(libs, require, character.only = TRUE)

# set options
options(stringAsFactors = FALSE)

#set parameters
candidates <- c("obama","romney")
pathname <- "C:\\Users\\admin\\Documents\\speeches"

#clean text
  cleanCorpus <- function(corpus){
  corpus.tmp <- tm_map(corpus, removePunctuation)
  corpus.tmp <- tm_map(corpus.tmp, stripWhitespace)
  corpus.tmp <- tm_map(corpus.tmp, tolower)
  corpus.tmp <- tm_map(corpus, removeWords, stopWords("english"))
  return(corpus.tmp)
 }

#Build TDM
 generateTDM <- function(cand, path){
  s.dir <- sprintf("%s/%s", path, cand)
  s.cor <- corpus(DirSource(directory = s.dir, encoding = "ANSI"))
  s.cor.cl <- cleanCorpus(s.cor)
  s.tdm <-TermDocumentMatrix(s.cor.cl)

  s.tdm <- removeSparseTerms(s.tdm, 0.7)
  result <- list(name = cand,  tdm = s.tdm)
}

tdm <- lapply(candidates, generateTDM, path = pathname)

【问题讨论】:

  • 好吧,8:50Corpus,即大写的 C
  • Cc 很难与默认的 RStudio 字体区分开来。)
  • @jbaums 非常感谢,您的评论帮助解决了问题.... :)

标签: r classification


【解决方案1】:

你的路径名应该是

路径名

注意:路径名中有正斜杠

【讨论】:

  • OP 在他的代码中是正确的。 pathname 中的斜线不是问题。
猜你喜欢
  • 1970-01-01
  • 2015-11-20
  • 2011-12-10
  • 2017-04-11
  • 2011-07-29
  • 2016-03-20
  • 2020-05-29
  • 2013-06-21
  • 2016-11-30
相关资源
最近更新 更多