Różne kryteria częstości

Eksploracja tekstu metodą Bag-of-Words w R

Ted Kwartler

Instructor

Wagi terminów

  • Domyślna częstość terminu = prosta liczba wystąpień
  • Częste słowa mogą maskować wnioski
  • Dostosuj wagi terminu za pomocą TfIdf
  • Słowa występujące w wielu dokumentach są penalizowane

wordcloud2.png

Eksploracja tekstu metodą Bag-of-Words w R

Wagi terminów

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

Standardowe ważenie terminów.

# 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)

Ważenie TfIdf.

Eksploracja tekstu metodą Bag-of-Words w R

Zachowanie metadanych dokumentu

# 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
Eksploracja tekstu metodą Bag-of-Words w R

Czas na ćwiczenia!

Eksploracja tekstu metodą Bag-of-Words w R

Preparing Video For Download...