시작하기무료로 시작하기

How do bigrams affect word clouds?

Now that you have made a bigram DTM, you can examine it and remake a word cloud. The new tokenization method affects not only the matrices but also any visuals or modeling based on the matrices.

Remember how "Marvin" and "Gaye" were separate terms in the chardonnay word cloud? Using bigram, tokenization grabs all two-word combinations. Observe what happens to the word cloud in this exercise.

This exercise uses str_subset from stringr. Keep in mind, other DataCamp courses cover regular expressions in more detail. As a reminder, the regular expression ^ matches the starting position within the exercise's bigrams.

이 연습은 강의의 일부입니다

Text Mining with Bag-of-Words in R

강의 보기

연습 안내

The chardonnay tweets have been cleaned and organized into a DTM called bigram_dtm.

  • Create bigram_dtm_m by converting bigram_dtm to a matrix.
  • Create an object freq consisting of the word frequencies by applying colSums() on bigram_dtm_m.
  • Extract the character vector of word combinations with names(freq) and assign the result to bi_words.
  • Pass bi_words to str_subset() with the matching pattern "^marvin" to review all bigrams starting with "marvin".
  • Plot a simple wordcloud() passing bi_words, freq and max.words = 15 into the function.

실습형 인터랙티브 연습

이 예제를 이 샘플 코드를 완성하여 풀어보세요.

# Create bigram_dtm_m
___ <- ___(___)

# Create freq
___ <- ___(___)

# Create bi_words
___ <- ___(___)

# Examine part of bi_words
___(___, ___)

# Plot a word cloud
___(___, ___, ___)
코드 편집 및 실행