This project analyzes public sentiment toward the Makan Bergizi Gratis (MBG) policy using data collected from X (Twitter). By applying Natural Language Processing (NLP) and machine learning, tweets are classified into positive, negative, and neutral sentiments.
This project demonstrates how social media data can be utilized to understand public opinion on government policies.
- Analyze public opinion on MBG policy
- Classify tweets into sentiment categories
- Evaluate machine learning model performance
- Visualize sentiment distribution
- Source: Scraped from X (Twitter)
- Total data: 199 tweets
tweet→ raw tweet textsentiment→ label- 0 = Negative
- 1 = Positive
- 2 = Neutral
- Lowercasing
- Remove URLs, mentions, hashtags
- Remove symbols & numbers
- Stopword removal (NLTK Indonesian)
- Stemming using Sastrawi
- TF-IDF (Term Frequency – Inverse Document Frequency)
- Multinomial Naive Bayes
- Train-test split (80:20)
- Metrics:
- Accuracy
- Precision
- Recall
- F1-score
- Accuracy: 77.5%
- Model performs well on negative sentiment
- Model struggles to detect neutral sentiment
- Issue caused by imbalanced dataset
- WordCloud (Positive Sentiment)
- WordCloud (Negative Sentiment)
- Sentiment Distribution Chart
- Public sentiment toward MBG is dominated by negative opinions
- Dataset imbalance significantly impacts performance
- Small dataset limits model generalization
- Increase dataset size (≥ 500 tweets)
- Balance dataset (SMOTE / undersampling)
- Try advanced models:
- Logistic Regression
- SVM
- IndoBERT
- Hyperparameter tuning
- Add confusion matrix visualization
- Python
- Pandas
- NumPy
- Scikit-learn
- NLTK
- Sastrawi
- Matplotlib
- WordCloud
git clone https://github.com/username/mbg-sentiment-analysis.git cd mbg-sentiment-analysis
pip install pandas numpy scikit-learn nltk sastrawi matplotlib wordcloud
jupyter notebook
This project shows that sentiment analysis can effectively extract public opinion from social media. While the model achieved 77.5% accuracy, improvements in dataset size and model selection are needed for better performance.
Akmal Azamrudi
If you find this project useful, please give it a ⭐ on GitHub!