Skip to content

Mehtab161/Twitter-Sentiment-Analysis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

🐦 Twitter Sentiment Analysis (NLP Project)

This project performs Sentiment Analysis on Twitter data using Natural Language Processing (NLP) and a Naive Bayes Classifier to classify tweets into Positive and Negative sentiments.


📌 Project Overview

  • Built a sentiment classifier for tweets
  • Removed neutral tweets for better performance
  • Applied text preprocessing and feature extraction
  • Visualized frequent words using WordCloud

🧰 Tech Stack

  • Python
  • NumPy, Pandas
  • NLTK (Natural Language Toolkit)
  • Scikit-learn
  • Matplotlib
  • WordCloud

🔄 Workflow

1️⃣ Data Preprocessing

  • Removed neutral tweets

  • Cleaned text:

    • Removed URLs, mentions (@), hashtags (#)
    • Removed stopwords
    • Converted text to lowercase
    • Tokenization

2️⃣ Data Visualization

  • Generated WordClouds for:

    • Positive tweets
    • Negative tweets

3️⃣ Feature Engineering

  • Extracted words using nltk.FreqDist

  • Created feature set using:

    contains(word)

4️⃣ Model Training

  • Algorithm: Naive Bayes (NLTK)
  • Trained on processed tweet dataset

5️⃣ Model Evaluation

📊 Results:

Training Size: 7449 tweets

Negative Tweets:
651 / 674 correct (~96.6%)

Positive Tweets:
51 / 176 correct (~28.9%)

⚠️ Observations

  • High accuracy for Negative tweets

  • Low accuracy for Positive tweets

  • Possible reasons:

    • Class imbalance
    • Limited feature extraction
    • Simple model

🚀 Future Improvements

  • Use advanced models:

    • Logistic Regression
    • SVM
    • Deep Learning (LSTM)
  • Use TF-IDF / Word Embeddings

  • Balance dataset

  • Deploy using Streamlit

  • Add real-time Twitter API


▶️ How to Run

git clone https://github.com/Mehtab161/Twitter-Sentiment-Analysis.git
cd Twitter-Sentiment-Analysis
pip install -r requirements.txt
jupyter notebook

📌 Requirements

See requirements.txt


👨‍💻 Author

Mehtab Khan


⭐ Support

If you like this project, give it a ⭐ on GitHub!

About

Twitter Sentiment Analysis using NLP and Naive Bayes with text preprocessing, feature extraction, and WordCloud visualization.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors