単語だけを超えて

Rで学ぶBag-of-Wordsによるテキストマイニング

Ted Kwartler

Instructor

ユニグラム、バイグラム、トライグラム

# コーヒー関連ツイートの先頭2件のみを使用
tweets$text[1:2]
[1] @ayyytylerb that is so true drink lots of coffee
[2] RT @bryzy_brib: Senior March tmw morning at 7:25 A.M. in the SENIOR lot. Get up early, make yo coffee/breakfast, cus this will only happen…
# 先頭2件のツイートでユニグラムDTMを作成
unigram_dtm <- DocumentTermMatrix(text_corp)
unigram_dtm
<<DocumentTermMatrix (documents: 2, terms: 18)>>
Non-/sparse entries: 18/18
Sparsity           : 50%
Maximal term length: 15
Weighting          : term frequency (tf)
Rで学ぶBag-of-Wordsによるテキストマイニング

ユニグラム、バイグラム、トライグラム

# RWekaパッケージを読み込み
library(RWeka)
# バイグラム用のトークナイザーを定義
tokenizer <- function(x) NGramTokenizer(x, Weka_control(min = 2, max = 2))

# バイグラムTDMを作成 bigram_tdm <- TermDocumentMatrix(clean_corpus(text_corp), control = list(tokenize = tokenizer)) bigram_tdm
<<DocumentTermMatrix (documents: 2, terms: 21)>>
Non-/sparse entries: 21/21
Sparsity           : 50%
Maximal term length: 19
Weighting          : term frequency (tf)
Rで学ぶBag-of-Wordsによるテキストマイニング

演習に進みましょう

Rで学ぶBag-of-Wordsによるテキストマイニング

Preparing Video For Download...