Forecasting the Chilean Electoral Year: Using Twitter to Predict the Presidential Elections of 2017

  • Sebastián RodríguezEmail author
  • Héctor Allende-Cid
  • Wenceslao Palma
  • Rodrigo Alfaro
  • Cristian Gonzalez
  • Claudio Elortegui
  • Pedro Santander
Conference paper
Part of the Lecture Notes in Computer Science book series (LNCS, volume 10914)


Failures of traditional survey methods for measuring political climate and forecasting high impact events such as elections, offers opportunities to seek alternative methods. The analysis of social networks with computational linguistic methods have been proved to be useful as an alternative, but several studies related to these areas were conducted after the event (post hoc). Since 2017 was the election year for the 2018–2022 period for Chile and, moreover, there were three instances of elections in this year. This condition makes a good environment to conduct a case study for forecasting these elections with the use of social media as the main source of Data. This paper describes the implementation of multiple algorithms of supervised machine learning to do political sentiment analysis to predict the outcome of each election with Twitter data. These algorithms are Decision Trees, AdaBoost, Random Forest, Linear Support Vector Machines and ensemble voting classifiers. Manual annotations of a training set are conducted by experts to label pragmatic sentiment over the tweets mentioning an account or the name of a candidate to train the algorithms. Then a predictive set is collected days before the election and an automatic classification is performed. Finally the distribution of votes for each candidate is obtained from this classified set on the positive sentiment of the tweets. Ultimately, an accurate prediction was achieved using an ensemble voting classifier with a Mean Absolute Error of \(0.51\%\) for the second round.


Election forecasting Sentiment analysis Machine learning Ex Ante forecasting 



This work was supported by the “Proyectos Interdisciplinarios” Grant of VREIA - Pontificia Universidad Católica de Valparaíso. Héctor Allende-Cid’s work was supported by the “Fondecyt Initiation into Research 11150248” of Conicyt, Chile.


  1. 1.
    Agarwal, A., Xie, B., Vovsha, I., Rambow, O., Passonneau, R.: Sentiment analysis of Twitter data. In: Proceedings of the Workshop on Languages in Social Media, pp. 30–38. Association for Computational Linguistics (2011)Google Scholar
  2. 2.
    Beauchamp, N.: Predicting and interpolating state-level polls using Twitter textual data. Am. J. Polit. Sci. 61(2), 490–503 (2017)CrossRefGoogle Scholar
  3. 3.
    Bermingham, A., Smeaton, A.: On using twitter to monitor political sentiment and predict election results. In: Proceedings of the Workshop on Sentiment Analysis Where AI Meets Psychology (SAAIP 2011), pp. 2–10 (2011)Google Scholar
  4. 4.
    Breiman, L., Friedman, J.H., Olshen, R.A., Stone, C.J.: Classification and Regression Trees. Chapman & Hall, New York (1984)zbMATHGoogle Scholar
  5. 5.
    Breiman, L.: Random forests. Mach. Learn. 45(1), 5–32 (2001). Scholar
  6. 6.
    Burnap, P., Gibson, R., Sloan, L., Southern, R., Williams, M.: 140 characters to victory?: Using Twitter to predict the UK 2015 general election. Elect. Stud. 41, 230–233 (2016)CrossRefGoogle Scholar
  7. 7.
    By, R.T., Ford, J., Randall, J.: Changing times: what organizations can learn from brexit and the 2016 us presidential election. J. Change Manag. 17(1), 1–8 (2017). Scholar
  8. 8.
    Ceron, A., Curini, L., Iacus, S.M., Porro, G.: Every tweet counts? How sentiment analysis of social media can improve our knowledge of citizens’ political preferences with an application to Italy and France. New Media Soc. 16(2), 340–358 (2014). Scholar
  9. 9.
    Ceron, A., Curini, L., Iacus, S.M.: Politics and Big Data: Nowcasting and Forecasting Elections with Social Media. Taylor & Francis, New York (2016)Google Scholar
  10. 10.
    Chung, J., Mustafaraj, E.: Can collective sentiment expressed on twitter predict political elections? In: Proceedings of the Twenty-Fifth AAAI Conference on Artificial Intelligence, pp. 1770–1771, AAAI 2011. AAAI Press (2011).
  11. 11.
    Cortes, C., Vapnik, V.: Support-vector networks. Mach. Learn. 20(3), 273–297 (1995)zbMATHGoogle Scholar
  12. 12.
    Franch, F.: (Wisdom of the crowds)2: 2010 UK election prediction with social media. J. Inf. Technol. Polit. 10(1), 57–71 (2013). Scholar
  13. 13.
    Freund, Y., Schapire, R.E.: A short introduction to boosting. In: Proceedings of the Sixteenth International Joint Conference on Artificial Intelligence, pp. 1401–1406. Morgan Kaufmann, San Francisco (1999)Google Scholar
  14. 14.
    Gayo-Avello, D.: No, you cannot predict elections with Twitter. IEEE Internet Comput. 16(6), 91–94 (2012)CrossRefGoogle Scholar
  15. 15.
    Gayo Avello, D., Metaxas, P.T., Mustafaraj, E.: Limits of electoral predictions using twitter. In: Proceedings of the Fifth International AAAI Conference on Weblogs and Social Media. Association for the Advancement of Artificial Intelligence (2011)Google Scholar
  16. 16.
    Jungherr, A., Jürgens, P., Schoen, H.: Why the pirate party won the German election of 2009 or the trouble with predictions: a response to Tumasjan, A., Sprenger, T.O., Sander, P.G., & Welpe, I.M. "predicting elections with Twitter: what 140 characters reveal about political sentiment". Soc. Sci. Comput. Rev. 30(2), 229–234 (2012).
  17. 17.
    Kouloumpis, E., Wilson, T., Moore, J.D.: Twitter sentiment analysis: the good the bad and the OMG!. ICWSM 11(538–541), 164 (2011)Google Scholar
  18. 18.
    Lariscy, R.W., Avery, E.J., Sweetser, K.D., Howes, P.: Monitoring public opinion in cyberspace: how corporate public relations is facing the challenge. Public Relat. J. 3(4), 1–17 (2009)Google Scholar
  19. 19.
    Liu, B., Zhang, L.: A survey of opinion mining and sentiment analysis. In: Aggarwal, C., Zhai, C. (eds.) Mining Text Data, pp. 415–463. Springer, Boston (2012). Scholar
  20. 20.
    Lui, C., Metaxas, P.T., Mustafaraj, E.: On the predictability of the us elections through search volume activity (2011)Google Scholar
  21. 21.
    Madge, C., Meek, J., Wellens, J., Hooley, T.: Facebook, social integration and informal learning at university: ‘it is more for socialising and talking to friends about work than for actually doing work’. Learn. Media Technol. 34(2), 141–155 (2009)CrossRefGoogle Scholar
  22. 22.
    Metaxas, P.T., Mustafaraj, E., Gayo-Avello, D.: How (not) to predict elections. In: 2011 IEEE Third International Conference on Privacy, Security, Risk and Trust (PASSAT) and 2011 IEEE Third Inernational Conference on Social Computing (SocialCom), pp. 165–171. IEEE (2011)Google Scholar
  23. 23.
    Omnicore Agency: Twitter by the numbers: stats, demographics & fun facts. Accessed 28 Dec 2017
  24. 24.
    Pak, A., Paroubek, P.: Twitter as a corpus for sentiment analysis and opinion mining. In: LREc, vol. 10 (2010)Google Scholar
  25. 25.
    Pang, B., Lee, L., et al.: Opinion mining and sentiment analysis. Foundations and trends\(\textregistered \). Inf. Retriev. 2(1–2), 1–135 (2008)Google Scholar
  26. 26.
    Pedregosa, F., Varoquaux, G., Gramfort, A., Michel, V., Thirion, B., Grisel, O., Blondel, M., Prettenhofer, P., Weiss, R., Dubourg, V., Vanderplas, J., Passos, A., Cournapeau, D., Brucher, M., Perrot, M., Duchesnay, E.: Scikit-learn: machine learning in Python. J. Mach. Learn. Res. 12, 2825–2830 (2011)MathSciNetzbMATHGoogle Scholar
  27. 27.
    Sang, E.T.K., Bos, J.: Predicting the 2011 Dutch senate election results with Twitter. In: Proceedings of the Workshop on Semantic Analysis in Social Media, pp. 53–60. Association for Computational Linguistics, Stroudsburg, PA, USA (2012).
  28. 28.
    Shirky, C.: The political power of social media: technology, the public sphere, and political change. Foreign Aff. 90(1), 28–41 (2011)Google Scholar
  29. 29.
    Singh, P., Sawhney, R.S., Kahlon, K.S.: Forecasting the 2016 US presidential elections using sentiment analysis. In: Kar, A.K., Ilavarasan, P.V., Gupta, M.P., Dwivedi, Y.K., Mäntymäki, M., Janssen, M., Simintiras, A., Al-Sharhan, S. (eds.) I3E 2017. LNCS, vol. 10595, pp. 412–423. Springer, Cham (2017). Scholar
  30. 30.
    Fung Global Retail & Technology: Deep dive social media in Latin America. Technical report, May 2016.
  31. 31.
    Tumasjan, A., Sprenger, T.O., Sandner, P.G., Welpe, I.M.: Predicting elections with Twitter: what 140 characters reveal about political sentiment. ICWSM 10(1), 178–185 (2010)Google Scholar
  32. 32.
    Valentino, N.A., King, J.L., Hill, W.W.: Polling and prediction in the 2016 presidential election. Computer 50(5), 110–115 (2017)CrossRefGoogle Scholar

Copyright information

© Springer International Publishing AG, part of Springer Nature 2018

Authors and Affiliations

  • Sebastián Rodríguez
    • 1
    Email author
  • Héctor Allende-Cid
    • 1
  • Wenceslao Palma
    • 1
  • Rodrigo Alfaro
    • 1
  • Cristian Gonzalez
    • 2
  • Claudio Elortegui
    • 3
  • Pedro Santander
    • 3
  1. 1.Escuela de Ingeniería InformáticaPontificia Universidad Católica de ValparaísoValparaísoChile
  2. 2.Instituto de Ciencias de Lenguaje y LiteraturaPontificia Universidad Católica de ValparaísoValparaísoChile
  3. 3.Escuela de PeriodismoPontificia Universidad Católica de ValparaísoValparaísoChile

Personalised recommendations