Skip to content

maida-maryam06/Real-Time-Twitter-Sentiment-Analysis-using-Machine-Learning

Repository files navigation

Personality & Sentiment Analysis (AI Project)

Project Overview

This project is an Artificial Intelligence Lab final project that performs Sentiment Analysis and Personality Insight extraction from textual data. The system fetches real-time tweets using the Twitter API, analyzes their sentiment using Natural Language Processing (NLP) and Machine Learning, and generates sentiment-based ratings from the extracted data.


Objectives

  • Fetch live tweets at runtime using Twitter API
  • Analyze tweet text for sentiment classification
  • Generate sentiment-based ratings from analyzed tweets
  • Demonstrate practical implementation of NLP and ML techniques

Twitter API Integration

  • Tweets are fetched at runtime using the Twitter API
  • User provides a keyword or hashtag
  • Recent tweets related to the query are collected dynamically
  • These tweets act as real-world input data for analysis

Dataset

  • Source: Live Twitter data fetched at runtime
  • Format: Text data extracted from tweets
  • Usage: Tweets are preprocessed and passed directly to the trained model

Technologies & Libraries

  • Programming Language: Python
  • Libraries Used:
    • pandas
    • scikit-learn
    • re (Regular Expressions)
    • joblib
    • tweepy
  • ML Model: Random Forest Classifier
  • Feature Extraction: CountVectorizer (Bag of Words)

System Workflow

  1. Authenticate with Twitter API
  2. Fetch tweets based on a keyword or hashtag
  3. Clean and preprocess tweet text
  4. Convert text into numerical features using CountVectorizer
  5. Apply trained machine learning model
  6. Classify sentiment (Positive / Negative / Neutral)
  7. Calculate overall sentiment score
  8. Generate star-based rating from sentiment results

Rating Generation Logic

  • Positive tweets increase rating
  • Negative tweets decrease rating
  • Neutral tweets maintain balance
  • Final output is displayed as a sentiment-based rating (e.g., 1–5 stars)

Model Output

  • Trained sentiment model saved using joblib
  • Vectorizer saved for reuse
  • Sentiment predictions for fetched tweets
  • Overall sentiment rating based on live Twitter data

How to Run

  1. Open the project notebook in Jupyter Notebook or Google Colab
  2. Add your Twitter API credentials
  3. Enter a keyword or hashtag
  4. Run all cells sequentially
  5. View sentiment analysis and generated ratings

Academic Purpose

This project was developed as part of the Artificial Intelligence Lab to demonstrate:

  • Real-time data collection using APIs
  • NLP-based text preprocessing
  • Machine learning–based sentiment analysis
  • AI-driven decision and rating systems

Future Enhancements

  • Personality trait detection using Big Five Model
  • Deep learning models (LSTM, BERT)
  • Web-based dashboard
  • Visualization of sentiment trends

License

This project is licensed under the MIT License.


Author

AI Lab Final Project
BSCS – Semester 6

About

Real-time Twitter Sentiment and Personality Analysis system using Python, NLP and Machine Learning. Tweets are fetched dynamically via Twitter API, analyzed for sentiment and converted into star-based ratings to reflect public opinion on keywords or hashtags.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors