A comparative study of Machine Learning approaches for sentiment classification of real-world YouTube comments.
This project implements and compares multiple Machine Learning techniques for sentiment analysis on YouTube video comments. Comments were extracted directly from YouTube using the YouTube Data API, manually labelled, and used to train and evaluate different models — ranging from traditional ML classifiers to neural networks.
The goal was to determine which approach performs best on informal, noisy, real-world text data such as social media comments.
- Source: YouTube comments from a real video using the YouTube Data API
- Collection: Custom Python script (
Comment_Extraction.py) using the YouTube Data API v3 - Labelling: Manually labelled into sentiment classes (Positive / Negative / Neutral)
- Files:
comments.csv(raw),Labelled_Dataset.csv(processed & labelled)
Baseline classifiers trained on bag-of-words features:
- Logistic Regression
- Naive Bayes
- Support Vector Machine (SVM)
- Random Forest
TF-IDF vectorization combined with ML classifiers to capture term importance across the corpus, improving on simple bag-of-words representations.
A deep learning approach using a neural network trained on word embeddings to capture semantic context within comments.
- Language: Python
- Libraries: scikit-learn, TensorFlow/Keras, pandas, NumPy, NLTK, matplotlib
- Tools: Jupyter Notebook, YouTube Data API v3
- Environment: Google Colab / Jupyter
├── Comment_Extraction.py # YouTube API comment scraper
├── comments.csv # Raw extracted comments
├── Labelled_Dataset.csv # Manually labelled dataset
├── Traditional_model_comparison.ipynb # Baseline ML classifiers
├── TF_IDF_Final_Khalid.ipynb # TF-IDF based approach
├── Neural_Network.ipynb # Deep learning approach
└── README.md
- Clone the repository:
git clone https://github.com/SaraAzmin/Sentiment-Analysis-from-Text.git
cd Sentiment-Analysis-from-Text- Install dependencies:
pip install scikit-learn pandas numpy nltk tensorflow matplotlib- Open any notebook in Jupyter or Google Colab and run all cells.
To extract new comments, add your YouTube Data API key to
Comment_Extraction.pybefore running.
- Real-world social media text is noisy and informal, making preprocessing critical
- TF-IDF significantly outperformed simple bag-of-words on this dataset
- Neural networks require more data to outperform traditional ML on small datasets
- Manual labelling introduces subjectivity, especially for neutral comments