Social network analysis of 5,596 tweets about traffic in Guatemala. User mentions are modeled as a weighted graph to detect communities, identify influential accounts, study posting patterns, and measure public sentiment. The results show that a conversation that looks like it is about traffic is, structurally, a political one.
| Metric | Value |
|---|---|
| Tweets (after deduplication) | 5,596 |
| Unique users | 2,071 |
| Mentions | 11,009 |
| Hashtags | 592 |
Raw data was stored as line-delimited JSON (UTF-16) with formatting inconsistencies, so a custom loader validated each record and automatically repaired malformed lines. Duplicates were removed using a user–text–date key.
- Preprocessing: text normalization (lowercasing; removal of links, mentions, hashtags, emojis, numbers, and punctuation), Spanish stopwords, and extraction of mentions, hashtags, retweets, and replies
- Exploratory analysis: most-mentioned accounts, hashtag analysis, word clouds, and hourly activity distribution
- Network construction: weighted directed graph of mentions between users
- Community detection: comparison of Louvain, greedy modularity, label propagation, and Girvan–Newman on a filtered graph (edge weight ≥ 3, 2-core pruning)
- Centrality analysis: degree, closeness, and betweenness centrality
- Isolated subnetworks: structural analysis across edge-weight thresholds (W = 2 to 50)
- Sentiment analysis: two lexicon-based methods (normalized polarity score vs. a negative-priority rule)
A sparse but small-world network. Density is only 0.0010, yet the main component has a diameter of 7 and a clustering coefficient of 0.23. Few users are connected directly, but information travels in a few steps.
One dominant hub. @traficogt (Guatemala City's traffic authority) receives more than 4,000 mentions and leads all three centrality metrics.
Three types of influential accounts:
- Hubs: @traficogt, which concentrates the conversation
- Amplifiers: high degree and closeness; political figures, institutions, and media such as @barevalodeleon, @drgiammattei, @mpguatemala, and @lahoragt
- Bridges: high betweenness but low visibility; accounts such as @servoveritatis and @quorumgt that connect otherwise separate communities
Seven communities. Louvain achieved the highest modularity of the four algorithms (Q ≈ 0.431). The resulting groups are organized around distinct poles: traffic monitoring, media and journalists, and political figures.
A core–periphery structure. As the edge-weight threshold increases, the network contracts from a broad conversation into a star-shaped core around @traficogt. Many users participate occasionally, but a few sustain the discussion.
A critical tone. Around a quarter of tweets carry negative sentiment (20.2%–24.4% depending on the method), against about 5% positive. Frequent terms such as corrupto, gobierno, bloqueo, and congreso show that traffic complaints are closely tied to criticism of institutions.
Activity patterns. Activity drops sharply in the early morning and peaks in the evening, reaching up to 350 tweets per hour, when users are experiencing traffic in real time.
| File | Description |
|---|---|
Lab No.6.ipynb |
Full analysis: loading, preprocessing, network analysis, and sentiment |
Lab 6.zip |
Project data and supporting files |
Lab 6 informe.docx |
Full written report with figures and discussion (in Spanish) |
Python · pandas · NetworkX · python-louvain · NLTK · scikit-learn · WordCloud · Matplotlib
- Clone the repository and extract
Lab 6.zip - Install dependencies:
pip install pandas networkx python-louvain nltk scikit-learn wordcloud matplotlib - Open
Lab No.6.ipynband run all cells
Developed as part of the Data Science course at Universidad del Valle de Guatemala.