Sentiment Analysis of Social Media: A New Pulse for Urban Security in Bogotá
Sentiment Analysis of Social Network Content to Characterize the Perception of Security
This paper presents an automated framework for quantifying the Perception of Security (PoS) in Bogotá by performing sentiment analysis on georeferenced Spanish tweets. Using a dataset of 26,000 tweets, the study compares rule-based (lexicon) and supervised machine learning approaches, identifying Multinomial Naive Bayes with TF-IDF vectorization as a high-performing method for real-time security monitoring.
TL;DR
Researchers at the Universidad Nacional de Colombia have developed a system to measure the "Perception of Security" (PoS) in Bogotá by analyzing 26,000 tweets. Moving beyond slow, expensive physical surveys, they demonstrated that supervised machine learning—specifically Multinomial Naive Bayes with TF-IDF—can effectively track the emotional state of a city in real-time, even within the linguistic complexities of Spanish.
Problem & Motivation: The Failure of Static Surveys
Understanding the fear of crime is as critical for urban planning as understanding crime itself. Traditionally, this has been measured through surveys. However, the authors argue that surveys are:
- Costly and Time-Consuming: They cannot be performed daily.
- Delayed: By the time results are processed, the public mood may have shifted.
- Fragmented: They only reach a small sample of the population.
The challenge in moving this to social media lies in the language. Spanish is rich in colloquialisms and "noise." Most sentiment analysis tools are optimized for English, leaving Spanish-speaking cities like Bogotá without specialized toolsets for quantifying public safety sentiment.
Methodology: Rules vs. Learning
The study compared two distinct technical paths to process tweets filtered for security-related keywords (e.g., robo, asalto, arma):
1. The Rule-Based Approach (Lexicon)
This method uses ML-Senticon, a multilingual lemma-level lexicon. It counts positive and negative words to calculate a "Polarity Score." While straightforward, it lacks context—it doesn't understand irony or how neighboring words change a sentiment's meaning.
2. The Supervised Learning Pipeline
The authors utilized a gold-standard dataset labeled by 10 experts. They processed the text through:
- Pre-processing: Stemming, removing stop words, and normalizing Spanish punctuation (like ¡ and ¿).
- Feature Extraction: Comparing Bag of Words (BOW) vs. TF-IDF (Term Frequency-Inverse Document Frequency).
- Classification: Testing Logistic Regression, Naive Bayes, and SGD.
Fig 1: The proposed workflow from data acquisition to final sentiment classification.
Experimental Insights
The results provide a clear hierarchy of performance. Rule-based models were found to be insufficient for the nuances of security-related speech in Bogotá.
Key findings from the supervised models:
- TF-IDF is essential: It proved more effective than simple word counts (BOW) because it highlights the "importance" of rare, high-impact security terms.
- Multinomial Naive Bayes (MNB): Achieved the highest Precision, making it the best candidate if the goal is to minimize false alarms in security reporting.
- SGD Classifier: Showed the best F1-Score, suggesting it is the most robust when balancing sensitivity (Recall) and accuracy.
Fig 2: Comparison of classifiers. Note the stability of Logistic Regression and the precision peaks of MNB.
Critical Analysis & Future Outlook
This work represents a vital shift toward Algorithmic Governance in Latin America. By treating Twitter as a "distributed sensor," the city can detect spikes in fear or frustration immediately after specific incidents.
Limitations: The authors acknowledge that current Spanish lexicons are "poorly developed." Additionally, using simple ML models like Naive Bayes may limit the capture of complex semantic structures compared to modern Large Language Models (LLMs) like BERT.
The Takeaway: The path to a safer city involves listening to its digital heartbeat. This study proves that even with classic machine learning, we can bridge the gap between subjective human feeling and objective data analysis. The next evolution will likely involve LIME (Local Interpretable Model-agnostic Explanations) to help policy makers understand why a model flagged a specific neighborhood as feeling "insecure."
