I am involved in twitter analysis data. I want to find trending topics in tweets with some hashtags, like #finance or #technology. I have a hugh data set of tweets and now I need to analyze them.

I need to recognize topics, if there are. They way I'm approaching this is, first, performing a vector representation of each tweet, with a tfidf technique, and then, build groups of them based on their cosine similarity.

Are there common techniques in tweets analysis?

  • $\begingroup$ The Question is way too broad $\endgroup$
    – Aditya
    Commented Apr 10, 2018 at 18:42
  • $\begingroup$ @Aditya yes, I extended my question explaining what I'm doing now. Since I am new in this, I need to know if there are common techniques in twitter data analysis to recognize trending topics. $\endgroup$ Commented Apr 10, 2018 at 19:08
  • $\begingroup$ Twitter data is utter crap, totally overrated. $\endgroup$ Commented Apr 11, 2018 at 19:38
  • $\begingroup$ Yes, I know there is too much noise out there, but I need to perform this study just complementing another studies and then evaluate if there is some data I can retrieve. $\endgroup$ Commented Apr 11, 2018 at 19:44

2 Answers 2


I believe that the algorithm that you want to use is something called a latent dirichlet allocation (LDA) model. This model is designed to uncover the topics in a corpus of documents.

Scikit learn has an implementation.

They even have a tutorial which teaches you how to extract topics. The tutorial also describes Non-negative Matrix Factorization (NNMF) as a method to extract the topics. I can't vouch for this algorithm, because I haven't used it personally (as opposed to LDA which I have used before), but from their tutorial NNMF does seem to give reasonable results.

Using cosine similarity will help you to group tweets that are most similar, but it wouldn't give you their topics. Which may be what you want? It really is hard to say, because only you would know how you should have the system behave. Unfortunately, that doesn't help you figure out what is trending, and you will need to do some heavy post-processing to make whatever algorithm you use spit out something that is useful to you.

Good luck!

  • $\begingroup$ That tutorial is great! I'm going to adapt it with my own dataset. Thanks! $\endgroup$ Commented Apr 11, 2018 at 14:07
  • $\begingroup$ It's a good start, however, these models need the number of topics in the dataset, which are unknown. $\endgroup$ Commented Apr 11, 2018 at 14:27
  • $\begingroup$ you can use the log-likelihood (the score method of the LDA class) and a version of an elbow rule to determine the optimal number of topics. $\endgroup$
    – Ryan
    Commented Apr 11, 2018 at 17:17
  • $\begingroup$ ok, choosing the optimal number of topics based in some metrics, like coherence score, could be very useful. Thanks! $\endgroup$ Commented Apr 11, 2018 at 18:25

As mentioned by @Ryan the LDA is a way to go but I am not sure it will provide robust results on documents that are fundamentally limited to 140 characters in length. I tried it in the past on summaries of news articles and got mixed results. One alternative idea might be to test the performance of a supervised model like SVM or KNN when hash-tags are used as the classes?

As an aside if you are committed to the LDA check out the gensim and LDAviz packages in python.

  • $\begingroup$ yes that packages are great, but the real thing is that LDA is not giving me good results. The best thing I found is, like you are saying, only take into account the hashtags. $\endgroup$ Commented Apr 12, 2018 at 19:05
  • $\begingroup$ I was more thinking of using the hashtags as an internalized classification for the rest of the text in the tweet. The thing you can toy with is combining hashtags by setting a "reasonable" difference under which two tags are considered equal and using a something basic like a string distance algorithm to determine the differences. This might generalize your results some more. Also consider using a stemmer, if you aren't already, to regularize the tags. $\endgroup$
    – Dan Temkin
    Commented Apr 12, 2018 at 19:23

Not the answer you're looking for? Browse other questions tagged or ask your own question.