"Ml_for_hackers" [2]

Source: Internet
Author: User

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]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.