Today, when dealing with textual regression, there is a problem that needs to be recorded.
Ranks <-read.csv ('/users/lvxubo/desktop/ml_for_hackers-master/06-regularization/data/oreilly.csv ', Stringsasfactors=false) Library (' TM ') documents <-data.frame (Text=ranks$long.desc.) Row.names (documents) <-1:nrow (documents) Corpus <-Corpus (Dataframesource (documents)) Corpus <-Tm_map ( Corpus,tolower) Corpus <-Tm_map (corpus,stripwhitespace) Corpus <-Tm_map (Corpus,removewords,stopwords (' 中文版))Corpus <-Tm_map (Corpus, Plaintextdocument)DTM <-Documenttermmatrix (Corpus)
If there is no marked code, you will get an error:
Error in Usemethod ("meta", X): "Meta" does not apply to the "character" target object in addition: Warning message:in mclapply (unname (content (x)), Termfreq, control): All scheduled cores encountered errors in user code
This is the solution on the StackOverflow:
It seems this would has worked just fine in and changes in seems to has tm 0.5.10
tm 0.6.0
broken it. The problem is, the functions tolower
and trim
won ' t necessarily return textdocuments (it looks like the older version May has automatically done the conversion). They instead return characters and the Documenttermmatrix isn ' t sure how to handle a corpus of characters.
So you could
corpus_clean <- tm_map(news_corpus, content_transformer(tolower))
Or You can run
corpus_clean <- tm_map(corpus_clean, PlainTextDocument)
After all of your non-standard transformations (those not in) is done and getTransformations()
just before you create the Documenttermma Trix. That should make sure all of your data are in plaintextdocument and should make Documenttermmatrix happy.
"Ml_for_hackers" [2]