Verschillende frequentiecriteria

Text mining met bag-of-words in R

Ted Kwartler

Instructor

Termwegingen

  • Standaard termfrequentie = simpel woordtellen
  • Veelvoorkomende woorden kunnen inzichten verbergen
  • Pas termweging aan met TfIdf
  • Woorden die in veel documenten staan worden afgestraft

wordcloud2.png

Text mining met bag-of-words in R

Termwegingen

# Standard term weighting
tf_tdm <- TermDocumentMatrix(text_corp)
tf_tdm_m <- as.matrix(tf_dtm)
tf_tdm_m[505:510, 5:10]

tdf.png

# TfIdf weighting
tf_idf_tdm <- TermDocumentMatrix(text_corp, 
    control = list(weighting = weightTfIdf))
tf_idf_tdm_m <- as.matrix(tf_idf_dtm)
tf_tdm_m <- as.matrix(tf_dtm)

tfidf.png

Text mining met bag-of-words in R

Documentmetadata behouden

# Ensure the first 2 columns are doc_id & text
names(tweets)[1:2] <- c('doc_id','text')

# Create VCorpus including metadata
test_corpus <- VCorpus(DataframeSource(tweets))
# Clean and view results
text_corpus <- clean_corpus(text_corpus)
content(text_corpus[[1]])
$content
[1] "ayyytylerb true drink lots coffee"
meta(text_corpus[[1]])
$meta
  id      : 1
  author  : thejennagibson
  date    : 8/9/2013 2:43
  language: en
Text mining met bag-of-words in R

Laten we oefenen!

Text mining met bag-of-words in R

Preparing Video For Download...