Neural Computing and Applications

, Volume 31, Issue 12, pp 9207–9220 | Cite as

Hybrid N-gram model using Naïve Bayes for classification of political sentiments on Twitter

  • Jamilu AwwaluEmail author
  • Azuraliza Abu Bakar
  • Mohd Ridzwan Yaakub
Original Article


Twitter, an online micro-blogging and social networking service, provides registered users the ability to write in 140 characters anything they wish and hence providing them the opportunity to express their opinions and sentiments on events taking place. Politically sentimental tweets are top-trending tweets; whenever election is near, users tweet about their favorite candidates or political parties and at times give their reasons for that. In this study, we hybridize two n-gram [two n-gram models used in this study are unigram and n-gram. Therefore, in this study, where unigram is mentioned that refers to a least-order n-gram (unigram) and where n-gram is mentioned that refers to the highest-order (full sentence or tweet level) n-gram] models and applied Laplace smoothing to Naïve Bayesian classifier and Katz back-off on the model. This was done in order to smoothen and address the limitation of accuracy in terms of precision and recall of n-gram models caused by the ‘zero count problem.’ Result from our baseline model shows an increase of 6.05% in average F-Harmonic accuracy in comparison with the n-gram model and 1.75% increase in comparison with the semantic-topic model proposed from a previous study on the same dataset, i.e., Obama–McCain dataset.


n-gram Data mining Naïve Bayes Social network Sentiment analysis 


Compliance with ethical standards

Conflict of interest

The authors declare that there is no conflict of interests with anybody or any institution regarding the publication of this paper.


  1. 1.
    Mitch W (2008) Obama election ushering in first internet presidency. InformationWeek Government. Accessed 26 June 2014
  2. 2.
    Kharde VA, Sonawane SS (2016) Sentiment analysis of Twitter data: a survey of techniques. Int J Comput Appl 139(11):5–15Google Scholar
  3. 3.
    Cambria E (2016) Affective computing and sentiment analysis. IEEE Intell Syst 16(March/April):102–107CrossRefGoogle Scholar
  4. 4.
    Perikos I, Hatzilygeroudis I (2016) A classifier ensemble approach to detect emotions polarity in social media. In: Proceedings of the 12th international conference on web information systems and technologies (WEBIST 2016), vol 1, pp 363–370Google Scholar
  5. 5.
    Shaheen S, El-Hajj W, Hajj H, Elbassuoni S (2014) Emotion recognition from text based on automatically generated rules. In: IEEE international conference on data mining workshop, pp 383–392.
  6. 6.
    Fersini E, Messina E, Pozzi FA (2014) Sentiment analysis: Bayesian ensemble learning. Decis Support Syst 68(2014):26–38. CrossRefGoogle Scholar
  7. 7.
    Bravo-marquez F, Frank E, Pfahringer B (2016) From opinion lexicons to sentiment classification of Tweets and vice versa: a transfer learning approach. In: The 2016 IEEE/WIC/ACM international conference on web intelligence at Omaha, NebraskaGoogle Scholar
  8. 8.
    Boroş T, Ştefănescu D, Ion R (2013) Handling two difficult challenges for text-to-speech synthesis systems: out-of-vocabulary words and prosody: a case study in Romanian. In: Neustein A, Markowitz J (eds) Where humans meet machines. Springer, New YorkGoogle Scholar
  9. 9.
    Zhu L, Smith ML, Lerman K, Kozareva Z (2013) The role of social media in the discussion of controversial topics. Accessed on 10 Jan 2014Google Scholar
  10. 10.
    Mukund D, Avik S (2010) BI and sentiment analysis. Bus Intell J 15(2):41–43Google Scholar
  11. 11.
    Cambria E, Schuller B, Xia Y, Havasi C (2013) New avenues in opinion mining and sentiment analysis. IEEE Intell Syst 28(2):15–21CrossRefGoogle Scholar
  12. 12.
    Jagtap VS, Pawar K (2013) Analysis of different approaches to sentence-level sentiment classification. Int J Sci Eng Technol 2(3):164–170Google Scholar
  13. 13.
    Saif H, He Y, Alani H (2012) Semantic sentiment analysis of Twitter. In: 11th international semantic Web conference, Boston, MA, USA, November 11–15, 2012, proceedings, part I, pp 508–524Google Scholar
  14. 14.
    Tobias G, Johansson R (2013) Sentiment analysis of microblogs. Dissertation, University of GothenbergGoogle Scholar
  15. 15.
    Wang S, Manning CD (1998) Baselines and bigrams: simple, good sentiment and topic classification, vol 94305(1)Google Scholar
  16. 16.
    Tan S et al (2009) Adapting Naive Bayes to domain adaptation for sentiment analysis. In: Proceedings of the 31th European conference on IR research on advances in information retrieval, pp 337–349Google Scholar
  17. 17.
    Rennie JDM, Shih L, Teevan J, Karger DR (2003) Tackling the poor assumptions of naive bayes text classifiers. In: Proceedings of the twentieth international conference on machine learning (ICML-2003). AAAI Press, Washington, DC, pp 616–623Google Scholar
  18. 18.
    Rish I (2001) An empirical study of the Naive Bayes classifier. IBM Research Report. IBM Research Division, pp 41–46Google Scholar
  19. 19.
    Araque O, Corcuera-Platas I, Sánchez-Rada JF, Iglesias CA (2017) Enhancing deep learning sentiment analysis with ensemble techniques in social applications. Expert Syst Appl 77:236–246. CrossRefGoogle Scholar
  20. 20.
    Mensikova A, Mattmann CA (2018) Ensemble sentiment analysis to identify human trafficking in web data. In: Proceedings of ACM workshop on graph techniques for adversarial activity analytics (GTA32018), pp 0–5Google Scholar
  21. 21.
    Hande K (2017) Sentiment analysis using ensemble classifier. Int J Innov Res Comput Commun Eng 5(9):15125–15130. CrossRefGoogle Scholar
  22. 22.
    Ekman P (1999) Basic emotions. In: Handbook of cognition and emotion, pp 45–60CrossRefGoogle Scholar
  23. 23.
    da Silva NF, Hruschka ER, Hruschka ER Jr (2014) Tweet sentiment analysis with classifier ensembles. Decis Support Syst 66:170–179. CrossRefGoogle Scholar
  24. 24.
    Narayanan V, Arora I, Bhatia A (2013) Fast and accurate sentiment classification using an enhanced Naive Bayes model. In: Proceedings of 14th international conference, IDEAL 2013, Hefei, China, October 20–23, 2013, pp 1–8CrossRefGoogle Scholar
  25. 25.
    Jurafsky D, Martin JH (2007) Speech and language processing. In: An introduction to speech recognition, computational linguistics and natural language processing, p 42Google Scholar
  26. 26.
    Xiang B (2014) Improving Twitter sentiment analysis with topic-based mixture modeling and semi-supervised training. In: Proceedings of the 52nd annual meeting of the association for computational linguistics, pp 434–439Google Scholar
  27. 27.
    Jurafsky D, Martin JH (2008) Speech and language processing. N-grams, 2nd edn. Prentice Hall, Englewood Cliffs, pp 83–121Google Scholar
  28. 28.
    Peng F (2003) Augmenting Naive Bayes classifiers with statistical language models. University of Massachusetts—Amherst, Computer Science Department, Faculty Publication Series 91. Accessed 26 June 2014
  29. 29.
    Bo P, Lillian L (2005) Seeing stars: exploiting class relationships for sentiment categorization with respect to rating scales. In: Proceedings of the ACLGoogle Scholar
  30. 30.
    Riaz M (2018) Fuzzy parameterized fuzzy soft compact spaces with decision-making. J Math 50(2):131–145MathSciNetGoogle Scholar
  31. 31.
    Riaz M, Hashmi MR (2018) Fixed points of fuzzy neutrosophic soft mapping with decision-making. Fixed Point Theory Appl 2018(1):7. CrossRefGoogle Scholar
  32. 32.
    Sa M, Riaz M, Hashmi MR (2016) Fuzzy parameterized fuzzy soft topology with applications. Ann Fuzzy Math Inf 13(5):593–613MathSciNetzbMATHGoogle Scholar
  33. 33.
    Saif H, Fernandez M, He Y, Alani H (2013) Evaluation datasets for Twitter sentiment analysis: a survey and a new dataset, the STS-Gold. In: 1st international workshop on emotion and sentiment in social and expressive media: approaches and perspectives from AI (ESSEM 2013)Google Scholar

Copyright information

© Springer-Verlag London Ltd., part of Springer Nature 2019

Authors and Affiliations

  1. 1.Universiti Kebangsaan MalaysiaBangiMalaysia

Personalised recommendations