请选择 进入手机版 | 继续访问电脑版
楼主: Nicolle
4438 34

Hands-On Data Science with R Text Mining [推广有奖]

巨擘

0%

还不是VIP/贵宾

-

TA的文库  其他...

Python(Must-Read Books)

SAS Programming

Must-Read Books

威望
16
论坛币
12402323 个
通用积分
1620.7415
学术水平
3305 点
热心指数
3329 点
信用等级
3095 点
经验
477211 点
帖子
23879
精华
91
在线时间
9878 小时
注册时间
2005-4-23
最后登录
2022-3-6

Nicolle 学生认证  发表于 2015-6-13 07:35:00 |显示全部楼层 |坛友微信交流群
提示: 作者被禁止或删除 内容自动屏蔽

本帖被以下文库推荐

kankan

使用道具

oujhovo 发表于 2015-6-13 07:48:18 |显示全部楼层 |坛友微信交流群
好书,文本挖掘

使用道具

hplcdadong 发表于 2015-6-13 07:50:04 |显示全部楼层 |坛友微信交流群
Thanks

使用道具

Lisrelchen 发表于 2015-6-13 08:01:02 |显示全部楼层 |坛友微信交流群
  1. ## ----module, echo=FALSE, results="asis"----------------------------------
  2. Module <- "TextMiningO"
  3. cat(paste0("\\newcommand{\\Module}{", Module, "}"))
  4. set.seed(42)


  5. ## ----setup, child="mycourse.Rnw"-----------------------------------------

  6. ## ----setup_options, include=FALSE----------------------------------------
  7. library(knitr)
  8. library(xtable)

  9. opts_chunk$set(cache=FALSE)

  10. opts_chunk$set(out.width='0.8\\textwidth')
  11. opts_chunk$set(fig.align='center')

  12. opts_chunk$set(src.top=NULL)
  13. opts_chunk$set(src.bot=NULL)
  14. opts_chunk$set(out.lines=4)
  15. opts_chunk$set(out.truncate=80)

  16. opts_chunk$set(fig.path=sprintf("figures/%s/", Module))
  17. opts_chunk$set(cache.path=sprintf("cache/%s/", Module))
  18. opts_chunk$set(bib.file=paste0(Module, ".bib"))

  19. opts_chunk$set(background='#E7E7E7')

  20. # Leave code as I have formatted it.

  21. opts_chunk$set(tidy=FALSE)

  22. # Hooks

  23. # Allow auto crop of base graphics plots when crop=TRUE.

  24. knit_hooks$set(crop=hook_pdfcrop)

  25. # Truncate long lines and long output

  26. hook_output <- knit_hooks$get("output")
  27. hook_source <- knit_hooks$get("source")
  28. knit_hooks$set(output=function(x, options)
  29. {
  30.   if (options$results != "asis")
  31.   {
  32.     # Split string into separate lines.
  33.     x <- unlist(stringr::str_split(x, "\n"))
  34.     # Trim to the number of lines specified.
  35.     if (!is.null(n <- options$out.lines))
  36.     {
  37.       if (length(x) > n)
  38.       {
  39.         # Truncate the output.
  40.         x <- c(head(x, n), "....\n")
  41.       }
  42.     }
  43.     # Truncate each line to length specified.
  44.     if (!is.null(m <- options$out.truncate))
  45.     {
  46.       len <- nchar(x)
  47.       x[len>m] <- paste0(substr(x[len>m], 0, m-3), "...")
  48.     }
  49.     # Paste lines back together.
  50.     x <- paste(x, collapse="\n")
  51.     # Replace ' = ' with '=' - my preference. Hopefully won't
  52.     # affect things inappropriately.
  53.     x <- gsub(" = ", "=", x)
  54.   }
  55.   hook_output(x, options)
  56. },
  57. source=function(x, options)
  58. {
  59.   # Split string into separate lines.
  60.   x <- unlist(stringr::str_split(x, "\n"))
  61.   # Trim to the number of lines specified.
  62.   if (!is.null(n <- options$src.top))
  63.   {
  64.     if (length(x) > n)
  65.     {
  66.       # Truncate the output.
  67.       if (is.null(m <-options$src.bot)) m <- 0
  68.       x <- c(head(x, n+1), "\n....\n", tail(x, m+2))
  69.    }
  70.   }
  71.   # Paste lines back together.
  72.   x <- paste(x, collapse="\n")
  73.   hook_source(x, options)
  74. })

  75. # Optionally allow R Code chunks to be environments so we can refer to them.

  76. knit_hooks$set(rcode=function(before, options, envir)
  77. {
  78.   if (before)
  79.     sprintf('\\begin{rcode}\\label{%s}\\hfill{}', options$label)
  80.   else
  81.     '\\end{rcode}'
  82. })



  83. ## ----load_packages, message=FALSE----------------------------------------
  84. library(tm)              # Framework for text mining.
  85. library(SnowballC)       # Provides wordStem() for stemming.
  86. library(qdap)            # Quantitative discourse analysis of transcripts.
  87. library(qdapDictionaries)
  88. library(dplyr)           # Data preparation and pipes %>%.
  89. library(RColorBrewer)    # Generate palette of colours for plots.
  90. library(ggplot2)         # Plot word frequencies.
  91. library(scales)          # Include commas in numbers.
  92. library(Rgraphviz)       # Correlation plots.


  93. ## ----additional_dependent_pacakges, echo=FALSE, message=FALSE------------
  94. # These are dependencies that would otherwise be loaded as required.

  95. library(magrittr)         #
  96. library(stringr)


  97. ## ----child-demo, child="documentation.Rnw", eval=TRUE--------------------


  98. ## ----help_library, eval=FALSE, tidy=FALSE--------------------------------
  99. ## ?read.csv


  100. ## ----help_package, eval=FALSE--------------------------------------------
  101. ## library(help=rattle)


  102. ## ----child-bib, child='generatebib.Rnw', eval=TRUE-----------------------

  103. ## ----record_start_time, echo=FALSE---------------------------------------
  104. start.time <- proc.time()


  105. ## ----generate_bib, echo=FALSE, message=FALSE, warning=FALSE--------------
  106. # Write all packages in the current session to a bib file
  107. if (is.null(opts_chunk$get("bib.file"))) opts_chunk$set(bib.file="Course.bib")
  108. write_bib(sub("^.*/", "", grep("^/", searchpaths(), value=TRUE)),
  109.           file=opts_chunk$get("bib.file"))
  110. system(paste("cat extra.bib >>", opts_chunk$get("bib.file")))
  111. # Fix up specific issues.
  112. # R-earth
  113. system(paste("perl -pi -e 's|. Derived from .*$|},|'",
  114.              opts_chunk$get("bib.file")))
  115. # R-randomForest
  116. system(paste("perl -pi -e 's|Fortran original by Leo Breiman",
  117.              "and Adele Cutler and R port by|Leo Breiman and",
  118.              "Adele Cutler and|'", opts_chunk$get("bib.file")))
  119. # R-C50
  120. system(paste("perl -pi -e 's|. C code for C5.0 by R. Quinlan|",
  121.              " and J. Ross Quinlan|'", opts_chunk$get("bib.file")))
  122. # R-caret
  123. system(paste("perl -pi -e 's|. Contributions from|",
  124.              " and|'", opts_chunk$get("bib.file")))
  125. # Me
  126. system(paste("perl -pi -e 's|Graham Williams|",
  127.              "Graham J Williams|'", opts_chunk$get("bib.file")))





  128. ## ----cli_convert_pdf, eval=FALSE-----------------------------------------
  129. ## system("for f in *.pdf; do pdftotext -enc ASCII7 -nopgbrk $f; done")


  130. ## ----cli_convert_doc, eval=FALSE-----------------------------------------
  131. ## system("for f in *.doc; do antiword $f; done")


  132. ## ----list_sources--------------------------------------------------------
  133. getSources()


  134. ## ----list_readers, out.lines=NULL----------------------------------------
  135. getReaders()


  136. ## ----location_of_txt_docs------------------------------------------------
  137. cname <- file.path(".", "corpus", "txt")
  138. cname


  139. ## ----folder_of_txt_docs--------------------------------------------------
  140. length(dir(cname))
  141. dir(cname)


  142. ## ----load_corpus---------------------------------------------------------
  143. library(tm)
  144. docs <- Corpus(DirSource(cname))
  145. docs
  146. class(docs)
  147. class(docs[[1]])
  148. summary(docs)


  149. ## ----read_pdf, eval=FALSE------------------------------------------------
  150. ## docs <- Corpus(DirSource(cname), readerControl=list(reader=readPDF))


  151. ## ----read_doc, eval=FALSE------------------------------------------------
  152. ## docs <- Corpus(DirSource(cname), readerControl=list(reader=readDOC))


  153. ## ----read_doc_options, eval=FALSE----------------------------------------
  154. ## docs <- Corpus(DirSource(cname), readerControl=list(reader=readDOC("-r -s")))


  155. ## ----out.lines=26--------------------------------------------------------
  156. inspect(docs[16])


  157. ## ------------------------------------------------------------------------
  158. getTransformations()


  159. ## ----transform_slash-----------------------------------------------------
  160. toSpace <- content_transformer(function(x, pattern) gsub(pattern, " ", x))
  161. docs <- tm_map(docs, toSpace, "/")
  162. docs <- tm_map(docs, toSpace, "@")
  163. docs <- tm_map(docs, toSpace, "\\|")


  164. ## ----eval=FALSE----------------------------------------------------------
  165. ## docs <- tm_map(docs, toSpace, "/|@|\\|")
  166. ##


  167. ## ----out.lines=26--------------------------------------------------------
  168. inspect(docs[16])


  169. ## ------------------------------------------------------------------------
  170. docs <- tm_map(docs, content_transformer(tolower))


  171. ## ----out.lines=26--------------------------------------------------------
  172. inspect(docs[16])


  173. ## ------------------------------------------------------------------------
  174. docs <- tm_map(docs, removeNumbers)


  175. ## ----out.lines=26--------------------------------------------------------
  176. inspect(docs[16])


  177. ## ------------------------------------------------------------------------
  178. docs <- tm_map(docs, removePunctuation)


  179. ## ----out.lines=26--------------------------------------------------------
  180. inspect(docs[16])


  181. ## ------------------------------------------------------------------------
  182. docs <- tm_map(docs, removeWords, stopwords("english"))


  183. ## ----out.lines=26--------------------------------------------------------
  184. inspect(docs[16])


  185. ## ----list_stopwords------------------------------------------------------
  186. length(stopwords("english"))
  187. stopwords("english")


  188. ## ----remove_own_stopwords------------------------------------------------
  189. docs <- tm_map(docs, removeWords, c("department", "email"))


  190. ## ----out.lines=26--------------------------------------------------------
  191. inspect(docs[16])


  192. ## ------------------------------------------------------------------------
  193. docs <- tm_map(docs, stripWhitespace)


  194. ## ----out.lines=26--------------------------------------------------------
  195. inspect(docs[16])


  196. ## ----specific_transforms-------------------------------------------------
  197. toString <- content_transformer(function(x, from, to) gsub(from, to, x))
  198. docs <- tm_map(docs, toString, "harbin institute technology", "HIT")
  199. docs <- tm_map(docs, toString, "shenzhen institutes advanced technology", "SIAT")
  200. docs <- tm_map(docs, toString, "chinese academy sciences", "CAS")


  201. ## ----out.lines=26--------------------------------------------------------
  202. inspect(docs[16])


  203. ## ------------------------------------------------------------------------
  204. library(SnowballC)
  205. docs <- tm_map(docs, stemDocument)


  206. ## ----out.lines=26--------------------------------------------------------
  207. inspect(docs[16])


  208. ## ----create_document_term_matrix, out.lines=20---------------------------
  209. dtm <- DocumentTermMatrix(docs)
  210. dtm


  211. ## ----inspect_dtm---------------------------------------------------------
  212. inspect(dtm[1:5, 1000:1005])


  213. ## ----dtm_matrix----------------------------------------------------------
  214. class(dtm)
  215. dim(dtm)


  216. ## ----create_term_document_matrix, out.lines=20---------------------------
  217. tdm <- TermDocumentMatrix(docs)
  218. tdm


  219. ## ------------------------------------------------------------------------
  220. freq <- colSums(as.matrix(dtm))
  221. length(freq)


  222. ## ----out.lines=10--------------------------------------------------------
  223. ord <- order(freq)

  224. # Least frequent terms
  225. freq[head(ord)]


  226. ## ------------------------------------------------------------------------
  227. # Most frequent terms
  228. freq[tail(ord)]


  229. ## ------------------------------------------------------------------------
  230. # Frequency of frequencies.
  231. head(table(freq), 15)
  232. tail(table(freq), 15)


  233. ## ----dtm_to_m------------------------------------------------------------
  234. m <- as.matrix(dtm)
  235. dim(m)


  236. ## ----save_csv, eval=FALSE------------------------------------------------
  237. ## write.csv(m, file="dtm.csv")


  238. ## ----remove_sparse_terms-------------------------------------------------
  239. dim(dtm)
  240. dtms <- removeSparseTerms(dtm, 0.1)
  241. dim(dtms)


  242. ## ------------------------------------------------------------------------
  243. inspect(dtms)


  244. ## ------------------------------------------------------------------------
  245. freq <- colSums(as.matrix(dtms))
  246. freq
  247. table(freq)


  248. ## ----freq_terms_1000-----------------------------------------------------
  249. findFreqTerms(dtm, lowfreq=1000)


  250. ## ----freq_terms_100------------------------------------------------------
  251. findFreqTerms(dtm, lowfreq=100)


  252. ## ----assoc---------------------------------------------------------------
  253. findAssocs(dtm, "data", corlimit=0.6)


  254. ## ----plot_correlations, echo=FALSE, out.width="\\textwidth", warning=FALSE, message=FALSE----
  255. plot(dtm,
  256.      terms=findFreqTerms(dtm, lowfreq=100)[1:50],
  257.      corThreshold=0.5)


  258. ## ----plot_correlations, eval=FALSE---------------------------------------
  259. ## plot(dtm,
  260. ##      terms=findFreqTerms(dtm, lowfreq=100)[1:50],
  261. ##      corThreshold=0.5)


  262. ## ----plot_correlations_optoins, echo=FALSE, out.width="\\textwidth", warning=FALSE----
  263. plot(dtm,
  264.      terms=findFreqTerms(dtm, lowfreq=100)[1:50],
  265.      corThreshold=0.5,
  266.      weighting=TRUE)


  267. ## ----plot_correlations, eval=FALSE---------------------------------------
  268. ## plot(dtm,
  269. ##      terms=findFreqTerms(dtm, lowfreq=100)[1:50],
  270. ##      corThreshold=0.5)
复制代码

使用道具

Lisrelchen 发表于 2015-6-13 08:01:35 |显示全部楼层 |坛友微信交流群
  1. ## ----word_count----------------------------------------------------------
  2. freq <- sort(colSums(as.matrix(dtm)), decreasing=TRUE)
  3. head(freq, 14)
  4. wf   <- data.frame(word=names(freq), freq=freq)
  5. head(wf)


  6. ## ----plot_freq, fig.width=12, out.width="\\textwidth"--------------------
  7. library(ggplot2)
  8. subset(wf, freq>500)                                                  %>%
  9.   ggplot(aes(word, freq))                                              +
  10.   geom_bar(stat="identity")                                            +
  11.   theme(axis.text.x=element_text(angle=45, hjust=1))


  12. ## ----wordcloud, echo=FALSE, warning=FALSE, message=FALSE, out.width="0.75\\textwidth", crop=TRUE----
  13. library(wordcloud)
  14. set.seed(123)
  15. wordcloud(names(freq), freq, min.freq=40)


  16. ## ----wordcloud, eval=FALSE-----------------------------------------------
  17. ## library(wordcloud)
  18. ## set.seed(123)
  19. ## wordcloud(names(freq), freq, min.freq=40)


  20. ## ----wordcloud_max_words, echo=FALSE, out.width="0.75\\textwidth", crop=TRUE----
  21. set.seed(142)
  22. wordcloud(names(freq), freq, max.words=100)


  23. ## ----wordcloud_max_words, eval=FALSE-------------------------------------
  24. ## set.seed(142)
  25. ## wordcloud(names(freq), freq, max.words=100)


  26. ## ----wordcloud_higher_freq, echo=FALSE, out.width="0.75\\textwidth", crop=TRUE----
  27. set.seed(142)
  28. wordcloud(names(freq), freq, min.freq=100)


  29. ## ----wordcloud_higher_freq, eval=FALSE-----------------------------------
  30. ## set.seed(142)
  31. ## wordcloud(names(freq), freq, min.freq=100)


  32. ## ----wordcloud_colour, echo=FALSE, out.width="0.75\\textwidth", crop=TRUE----
  33. set.seed(142)
  34. wordcloud(names(freq), freq, min.freq=100, colors=brewer.pal(6, "Dark2"))


  35. ## ----wordcloud_colour, eval=FALSE----------------------------------------
  36. ## set.seed(142)
  37. ## wordcloud(names(freq), freq, min.freq=100, colors=brewer.pal(6, "Dark2"))


  38. ## ----wordcloud_scale, echo=FALSE, warning=FALSE, out.width="0.75\\textwidth", crop=TRUE----
  39. set.seed(142)
  40. wordcloud(names(freq), freq, min.freq=100, scale=c(5, .1), colors=brewer.pal(6, "Dark2"))


  41. ## ----wordcloud_scale, eval=FALSE-----------------------------------------
  42. ## set.seed(142)
  43. ## wordcloud(names(freq), freq, min.freq=100, scale=c(5, .1), colors=brewer.pal(6, "Dark2"))


  44. ## ----wordcloud_rotate, echo=FALSE, warning=FALSE, out.width="0.75\\textwidth", crop=TRUE----
  45. set.seed(142)
  46. dark2 <- brewer.pal(6, "Dark2")
  47. wordcloud(names(freq), freq, min.freq=100, rot.per=0.2, colors=dark2)


  48. ## ----wordcloud_rotate, eval=FALSE----------------------------------------
  49. ## set.seed(142)
  50. ## dark2 <- brewer.pal(6, "Dark2")
  51. ## wordcloud(names(freq), freq, min.freq=100, rot.per=0.2, colors=dark2)


  52. ## ----library_qdap, echo=FALSE, messages=FALSE----------------------------
  53. library(qdap)


  54. ## ----qdap_create_word_list-----------------------------------------------
  55. words <- dtm                                                          %>%
  56.   as.matrix                                                           %>%
  57.   colnames                                                            %>%
  58.   (function(x) x[nchar(x) < 20])


  59. ## ----qdap_word_length, out.lines=11--------------------------------------
  60. length(words)
  61. head(words, 15)
  62. summary(nchar(words))
  63. table(nchar(words))
  64. dist_tab(nchar(words))


  65. ## ----qdap_word_length_plot, echo=FALSE, fig.height=4---------------------
  66. data.frame(nletters=nchar(words))                                     %>%
  67.   ggplot(aes(x=nletters))                                              +
  68.   geom_histogram(binwidth=1)                                           +
  69.   geom_vline(xintercept=mean(nchar(words)),
  70.              colour="green", size=1, alpha=.5)                         +
  71.   labs(x="Number of Letters", y="Number of Words")


  72. ## ----qdap_word_length_plot, eval=FALSE-----------------------------------
  73. ## data.frame(nletters=nchar(words))                                     %>%
  74. ##   ggplot(aes(x=nletters))                                              +
  75. ##   geom_histogram(binwidth=1)                                           +
  76. ##   geom_vline(xintercept=mean(nchar(words)),
  77. ##              colour="green", size=1, alpha=.5)                         +
  78. ##   labs(x="Number of Letters", y="Number of Words")


  79. ## ----qdap_letter_freq_plot, echo=FALSE, fig.height=4---------------------
  80. library(dplyr)
  81. library(stringr)

  82. words                                                        %>%
  83.   str_split("")                                                       %>%
  84.   sapply(function(x) x[-1])                                           %>%
  85.   unlist                                                              %>%
  86.   dist_tab                                                            %>%
  87.   mutate(Letter=factor(toupper(interval),
  88.                        levels=toupper(interval[order(freq)])))        %>%
  89.   ggplot(aes(Letter, weight=percent))                                  +
  90.   geom_bar()                                                           +
  91.   coord_flip()                                                         +
  92.   ylab("Proportion")                                                   +
  93.   scale_y_continuous(breaks=seq(0, 12, 2),
  94.                      label=function(x) paste0(x, "%"),
  95.                      expand=c(0,0), limits=c(0,12))


  96. ## ----qdap_letter_freq_plot, eval=FALSE-----------------------------------
  97. ## library(dplyr)
  98. ## library(stringr)
  99. ##
  100. ## words                                                        %>%
  101. ##   str_split("")                                                       %>%
  102. ##   sapply(function(x) x[-1])                                           %>%
  103. ##   unlist                                                              %>%
  104. ##   dist_tab                                                            %>%
  105. ##   mutate(Letter=factor(toupper(interval),
  106. ##                        levels=toupper(interval[order(freq)])))        %>%
  107. ##   ggplot(aes(Letter, weight=percent))                                  +
  108. ##   geom_bar()                                                           +
  109. ##   coord_flip()                                                         +
  110. ##   ylab("Proportion")                                                   +
  111. ##   scale_y_continuous(breaks=seq(0, 12, 2),
  112. ##                      label=function(x) paste0(x, "%"),
  113. ##                      expand=c(0,0), limits=c(0,12))


  114. ## ----qdap_count_position_plot, echo=FALSE, fig.height=7, fig.width=9-----
  115. words                                                                 %>%
  116.   lapply(function(x) sapply(letters, gregexpr, x, fixed=TRUE))        %>%
  117.   unlist                                                              %>%
  118.   (function(x) x[x!=-1])                                              %>%
  119.   (function(x) setNames(x, gsub("\\d", "", names(x))))                %>%
  120.   (function(x) apply(table(data.frame(letter=toupper(names(x)),
  121.                                       position=unname(x))),
  122.                      1, function(y) y/length(x)))                     %>%
  123.   qheat(high="green", low="yellow", by.column=NULL,
  124.         values=TRUE, digits=3, plot=FALSE)                             +
  125.   ylab("Letter")                                                       +
  126.   xlab("Position")                                                     +
  127.   theme(axis.text.x=element_text(angle=0))                             +
  128.   guides(fill=guide_legend(title="Proportion"))


  129. ## ----qdap_count_position_plot, eval=FALSE--------------------------------
  130. ## words                                                                 %>%
  131. ##   lapply(function(x) sapply(letters, gregexpr, x, fixed=TRUE))        %>%
  132. ##   unlist                                                              %>%
  133. ##   (function(x) x[x!=-1])                                              %>%
  134. ##   (function(x) setNames(x, gsub("\\d", "", names(x))))                %>%
  135. ##   (function(x) apply(table(data.frame(letter=toupper(names(x)),
  136. ##                                       position=unname(x))),
  137. ##                      1, function(y) y/length(x)))                     %>%
  138. ##   qheat(high="green", low="yellow", by.column=NULL,
  139. ##         values=TRUE, digits=3, plot=FALSE)                             +
  140. ##   ylab("Letter")                                                       +
  141. ##   xlab("Position")                                                     +
  142. ##   theme(axis.text.x=element_text(angle=0))                             +
  143. ##   guides(fill=guide_legend(title="Proportion"))


  144. ## ----eval=FALSE----------------------------------------------------------
  145. ## devtools::install_github("lmullen/gender-data-pkg")


  146. ## ------------------------------------------------------------------------
  147. name2sex(qcv(graham, frank, leslie, james, jacqui, jack, kerry, kerrie))


  148. ## ----review_prepare_corpus, eval=FALSE-----------------------------------
  149. ## # Required packages
  150. ##
  151. ## library(tm)
  152. ## library(wordcloud)
  153. ##
  154. ## # Locate and load the Corpus.
  155. ##
  156. ## cname <- file.path(".", "corpus", "txt")
  157. ## docs <- Corpus(DirSource(cname))
  158. ##
  159. ## docs
  160. ## summary(docs)
  161. ## inspect(docs[1])
  162. ##
  163. ## # Transforms
  164. ##
  165. ## toSpace <- content_transformer(function(x, pattern) gsub(pattern, " ", x))
  166. ## docs <- tm_map(docs, toSpace, "/|@|\\|")
  167. ##
  168. ## docs <- tm_map(docs, content_transformer(tolower))
  169. ## docs <- tm_map(docs, removeNumbers)
  170. ## docs <- tm_map(docs, removePunctuation)
  171. ## docs <- tm_map(docs, removeWords, stopwords("english"))
  172. ## docs <- tm_map(docs, removeWords, c("own", "stop", "words"))
  173. ## docs <- tm_map(docs, stripWhitespace)
  174. ##
  175. ## toString <- content_transformer(function(x, from, to) gsub(from, to, x))
  176. ## docs <- tm_map(docs, toString, "specific transform", "ST")
  177. ## docs <- tm_map(docs, toString, "other specific transform", "OST")
  178. ##
  179. ## docs <- tm_map(docs, stemDocument)
  180. ##


  181. ## ----review_analyse_corpus, eval=FALSE-----------------------------------
  182. ## # Document term matrix.
  183. ##
  184. ## dtm <- DocumentTermMatrix(docs)
  185. ## inspect(dtm[1:5, 1000:1005])
  186. ##
  187. ## # Explore the corpus.
  188. ##
  189. ## findFreqTerms(dtm, lowfreq=100)
  190. ## findAssocs(dtm, "data", corlimit=0.6)
  191. ##
  192. ## freq <- sort(colSums(as.matrix(dtm)), decreasing=TRUE)
  193. ## wf   <- data.frame(word=names(freq), freq=freq)
  194. ##
  195. ## library(ggplot2)
  196. ##
  197. ## p <- ggplot(subset(wf, freq>500), aes(word, freq))
  198. ## p <- p + geom_bar(stat="identity")
  199. ## p <- p + theme(axis.text.x=element_text(angle=45, hjust=1))
  200. ##
  201. ## # Generate a word cloud
  202. ##
  203. ## library(wordcloud)
  204. ## wordcloud(names(freq), freq, min.freq=100, colors=brewer.pal(6, "Dark2"))


  205. ## ----common_outtro, child="finale.Rnw", eval=TRUE------------------------


  206. ## ----syinfo, child="sysinfo.Rnw", eval=TRUE------------------------------

  207. ## ----echo=FALSE, message=FALSE-------------------------------------------
  208. require(Hmisc)
  209. pkg <- "knitr"
  210. pkg.version <- installed.packages()[pkg, 'Version']
  211. pkg.date <- installed.packages(fields="Date")[pkg, 'Date']
  212. pkg.info <- paste(pkg, pkg.version, pkg.date)

  213. rev <- system("bzr revno", intern=TRUE)
  214. cpu <- system(paste("cat /proc/cpuinfo | grep 'model name' |",
  215.                     "head -n 1 | cut -d':' -f2"), intern=TRUE)
  216. ram <- system("cat /proc/meminfo | grep MemTotal: | awk '{print $2}'",
  217.               intern=TRUE)
  218. ram <- paste0(round(as.integer(ram)/1e6, 1), "GB")
  219. user <- Sys.getenv("LOGNAME")
  220. node <- Sys.info()[["nodename"]]
  221. user.node <- paste0(user, "@", node)
  222. gcc.version <- system("g++ -v 2>&1 | grep 'gcc version' | cut -d' ' -f1-3",
  223.                       intern=TRUE)
  224. os <- system("lsb_release -d | cut -d: -f2 | sed 's/^[ \t]*//'", intern=TRUE)
复制代码

使用道具

hsiaoyan 发表于 2015-6-13 08:15:30 |显示全部楼层 |坛友微信交流群
thanks

使用道具

fengyg 企业认证  发表于 2015-6-13 08:32:54 |显示全部楼层 |坛友微信交流群
kankan

使用道具

bocm 发表于 2015-6-13 09:12:38 |显示全部楼层 |坛友微信交流群
thanks for sharing

使用道具

cql1086 发表于 2015-6-13 09:20:37 |显示全部楼层 |坛友微信交流群
目测是好书

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-3-29 19:14