その他のワードクラウドと単語ネットワーク

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

Ted Kwartler

Instructor

共通性クラウド

 

共通性

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

共通性クラウド

# 2つのコーパスを結合: all_tweets
all_coffee <- paste(coffee_tweets$text,
                    collapse = "")
all_chardonnay <- paste(chardonnay_tweets$text,
                        collapse = "")

all_tweets <- c(all_coffee, all_chardonnay)
# all_tweets をクレンジング all_tweets <- VectorSource(all_tweets) all_corpus <- VCorpus(all_tweets) all_clean <- clean_corpus(all_corpus) all_dm <- TermDocumentMatrix(all_clean) all_m <- as.matrix(all_tdm)
# 共通性クラウドを作成 commonality.cloud(all_m, colors = "steelblue1", max.words = 100)

共通性クラウド

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

比較クラウド

 

比較

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

比較クラウド

# 2つのコーパスを結合: all_tweets
all_coffee <- paste(coffee_tweets$text, 
                    collapse = "")
all_chardonnay <- paste(chardonnay_tweets$text, 
                       collapse = "")
all_tweets <- c(all_coffee, all_chardonnay)

# all_tweets をクレンジング all_tweets <- VectorSource(all_tweets) all_corpus <- VCorpus(all_tweets) all_clean <- clean_corpus(all_corpus) all_tdm <- TermDocumentMatrix(all_clean)
colnames(all_tdm) <- c("coffee", "chardonnay")
all_m <- as.matrix(all_tdm) # 比較クラウドを作成 comparison.cloud(all_m, colors = c("orange", "blue"), max.words = 50)

比較クラウド

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

ピラミッドプロット

# 両方の文書で共有される語を抽出
common_words <- subset(
  all_tdm_m,
  all_tdm_m[, 1] > 0 & all_tdm_m[, 2] > 0
)

# 最も共通する語を特定 difference <- abs(common_words[, 1] - common_words[, 2])
common_words <- cbind(common_words, difference) common_words <- common_words[order(common_words[, 3], decreasing = TRUE), ] top25_df <- data.frame(x = common_words[1:25, 1], y = common_words[1:25, 2], labels = rownames(common_words[1:25, ]))
Rで学ぶBag-of-Wordsによるテキストマイニング

ピラミッドプロット

# ピラミッドプロットの作成
pyramid.plot(top25_df$x, top25_df$y, 
             labels = top25_df$labels, 
             main = "Words in Common",
             gap = 8, laxly = NULL, 
             raxlab = NULL, unit = NULL,
             top.labels = c("Chardonnay", 
                            "Words", 
                            "Coffee")
)

ピラミッドプロット

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

単語ネットワーク

# 単語ネットワークの作成
word_associate(coffee_tweets$text,
    match.string = c("barista"), 
    stopwords = c(Top200Words, "coffee", "amp"), 
    network.plot = TRUE, 
    cloud.colors = c("gray85", "darkred"))

# タイトルを追加
title(main = "Barista Coffee Tweet Associations")

単語ネットワーク

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

Passons à la pratique !

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

Preparing Video For Download...