0
$\begingroup$

I am doing an LDA analysis, I have the topics, but I need to cluster the topics according to Hellinger distance.I need to group the 20 topics generated by the LDA model and present it in a dendrogram. I share part of the code.

'''
textos <-select(Base_Articulos, Articulo, Evento, Ano)
textorder <- textos[order(textos$Ano),]

bd_duplicados <- textos[duplicated(textos),]
bd_unicos <- unique (textos)
bd_unicos <- na.omit(bd_unicos)
ap_td <- tibble(textos)
ap_td

tidy_articulo <- ap_td %>%
  unnest_tokens(word, Evento)

espstopwords <- tibble(word = c(stopwords(kind = "es")))
enpstopwords <- tibble(word = c(stopwords(kind = "en")))

miastopwords <- tibble(word = c("colombia", "study", "bogota",
                                "colombian", "colombiano", "t",
                                "medellin", "n", "k", "b", "hom", 
                                "cc", "92", "85", "m", "1", 
                                "l", "sp", "50",
                                "155.000", "155", "59",
                                "64", "70", "80",
                                "18", "ri", "2", "3", "4", "5", "6", "7","8", "9"))

tidy_articulo <- tidy_articulo %>%
  anti_join(espstopwords)
tidy_articulo <- tidy_articulo %>%
  anti_join(enpstopwords)
tidy_articulo <- tidy_articulo %>%
  anti_join(miastopwords)

ap_td <- mutate(ap_td, Evento = as.character(ap_td$Evento))

tidy_articulo %>%
  count(word, sort = TRUE)

word_counts <- tidy_articulo %>%
  count(Articulo, word, sort = TRUE) %>%
  ungroup()

word_counts


desc_dtm <- word_counts %>%
  cast_dtm(Articulo, word, n)

desc_dtm

ap_lda <- LDA(desc_dtm, k = 20, control = list(seed = 1234))

ap_lda

ap_topics <- tidy(ap_lda, matrix = "beta")
ap_documents <- tidy(ap_lda, matrix = "gamma")'''
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.