{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE)
Arlette | Andrés | Andrea | Carlos
Ejercicios
1.Cargue y limpie sus datos de acuerdo a lo revisado en el tutorial(para a variable de comentarios).Visualice los resultados.
head(booksReviews)
# Se crea una función que realiza todo lo requerido
Clean_String <- function(string){
# minúscula
temp <- tolower(string)
# Remover todo lo que no sea número o letra
temp <- stringr::str_replace_all(temp,"[^a-zA-Z\\s]", " ")
# remover espacios extra
temp <- stringr::str_replace_all(temp,"[\\s]+", " ")
return(temp)
}
# Aplicar la función a los comentarios
booksReviews$comments <- Clean_String(booksReviews$comments)
head(booksReviews$comments,10)
# Convertir el texto en bigramas
booksReviewsTN_2 <- booksReviews %>%
mutate(id=paste(prod,author,date,sep="-")) %>%
select(id,stars,comments) %>%
unnest_ngrams(input = comments,output = bigram,n=2)
# Agrupar por token para conteo de eventos
booksReviewsTN_2 %>%
group_by(bigram) %>%
summarise(count=n()) %>%
arrange(desc(count))
3.Elimine los stopwords del resultado del ejercicio anterior.Visualice el conteo de mayor frecuencia de los resultados.
#se carga el dataset the stopwords
data(stop_words)
sample_n(stop_words,10)
#se eliminan los stopwords
tidyReviews <- booksReviewsT %>%
anti_join(stop_words)
# Agrupar por token para conteo de eventos
tidyReviews %>%
group_by(word) %>%
summarise(count=n()) %>%
arrange(desc(count))
4.Analice los resultados del ejercicio anterior.Que bigramas tienen mayor frecuencia? Se ven Resultados diferentes. Se ven palabras cortar como: The, in, on..
Escoja dos bigramas de su preferencia para analizar y filtre el dataset solo por ese bigrama.Cuál es la frecuencia o conteo de esos bigramas según la variable stars?
library(tidyr) # Se carga esta librería para usar funciones que nos ayuden a remover los stopwords
#Separar primero los bigrams
booksReviewsTN_2_separated <- booksReviewsTN_2 %>%
separate(col = bigram, into = c("word1", "word2"), sep = " ")
head(booksReviewsTN_2_separated)
#Eliminar los que contengan stop words
booksReviewsTN_2_filtered <- booksReviewsTN_2_separated %>%
filter(!word1 %in% stop_words$word) %>%
filter(!word2 %in% stop_words$word)
# Volver a juntar los bigramas que separamos
booksReviewsTN_2_filtered <- booksReviewsTN_2_filtered %>%
unite(bigram, word1, word2, sep = " ")
# Nuevo conteo de frecuencia
booksReviewsTN_2_filtered %>%
group_by(bigram,stars) %>%
summarise(count=n()) %>%
arrange(desc(count))