An end-to-end Sentiment Analysis project on Amazon Product Reviews using Natural Language Processing (NLP) and Machine Learning. This project performs data cleaning, exploratory data analysis, text preprocessing, sentiment classification, emotion analysis, and builds a Logistic Regression model for predicting customer sentiment.
- Project Overview
- Features
- Project Structure
- Technologies Used
- Workflow
- Exploratory Data Analysis
- VADER Sentiment Analysis
- Emotion Analysis
- Machine Learning Model
- Results
- Installation
- Usage
- Future Improvements
- Author
Customer reviews contain valuable information about user satisfaction and product quality. This project analyzes Amazon product reviews using Natural Language Processing techniques and Machine Learning to classify reviews into:
- π Positive
- π Neutral
βΉοΈ Negative
The project also performs emotion detection using the NRC Emotion Lexicon and compares rule-based sentiment with VADER sentiment analysis.
- Data Cleaning
- Exploratory Data Analysis (EDA)
- Text Preprocessing
- Tokenization
- Stopword Removal
- Lemmatization
- Word Cloud Generation
- Word Count Analysis
- Rule-Based Sentiment Classification
- VADER Sentiment Analysis
- NRC Emotion Analysis
- TF-IDF Feature Extraction
- Logistic Regression Classifier
- Confusion Matrix
- Classification Report
- Model Serialization using Joblib
CodeAlpha_Sentiment_Analysis
β
βββ data
β βββ raw
β β Reviews.csv
β β
β βββ processed
β cleaned_reviews.csv
β final_cleaned_reviews.csv
β final_sentiment_analysis.csv
β
βββ images
β confusion_matrix.png
β emotion_distribution.png
β ml_confusion_matrix.png
β review_score_distribution.png
β sentiment_distribution.png
β vader_score_distribution.png
β vader_sentiment_distribution.png
β word_count_distribution.png
β wordcloud.png
β
βββ models
β sentiment_model.pkl
β tfidf_vectorizer.pkl
β
βββ notebooks
β sentiment_analysis.ipynb
β
βββ reports
β
βββ requirements.txt
βββ README.md
This project uses the Amazon Fine Food Reviews dataset.
Due to GitHub's 100 MB file size limit, the dataset is not included in this repository.
Download it from Kaggle:
https://www.kaggle.com/datasets/snap/amazon-fine-food-reviews
After downloading, place the dataset as shown below:
CodeAlpha_Sentiment_Analysis/ βββ data/ βββ raw/ βββ Reviews.csv
- Python
- Pandas
- NumPy
- Matplotlib
- Seaborn
- NLTK
- NRCLex
- Scikit-learn
- WordCloud
- Joblib
- Jupyter Notebook
Amazon Reviews Dataset
β
βΌ
Data Cleaning
β
βΌ
Exploratory Data Analysis
β
βΌ
Text Preprocessing
β
βΌ
TF-IDF Vectorization
β
βΌ
Logistic Regression Model
β
βΌ
Sentiment Prediction
β
βΌ
Performance Evaluation
Shows the distribution of ratings from 1 to 5.
Rule-based sentiment generated from review ratings.
Distribution of review lengths after preprocessing.
Most frequently occurring words in customer reviews.
VADER calculates a compound sentiment score between -1 and +1.
Comparison between rating-based sentiment and VADER sentiment.
Emotion detection performed using the NRC Emotion Lexicon.
Detected emotions include:
- Joy
- Trust
- Fear
- Anger
- Sadness
- Surprise
- Anticipation
- Disgust
The cleaned review text was converted into numerical features using TF-IDF Vectorization.
A Logistic Regression classifier was trained to predict customer sentiment.
Processed Review
β
βΌ
TF-IDF Vectorizer
β
βΌ
Logistic Regression
β
βΌ
Prediction
86.45%
| Class | Precision | Recall | F1 Score |
|---|---|---|---|
| Negative | 0.74 | 0.67 | 0.70 |
| Neutral | 0.52 | 0.19 | 0.28 |
| Positive | 0.90 | 0.97 | 0.93 |
The trained model and TF-IDF vectorizer are stored for future predictions.
models/
β
βββ sentiment_model.pkl
βββ tfidf_vectorizer.pkl
Clone the repository
git clone https://github.com/kindlefest08/CodeAlpha_Sentiment_Analysis.gitMove into the project
cd CodeAlpha_Sentiment_AnalysisInstall dependencies
pip install -r requirements.txtLaunch Jupyter Notebook
jupyter notebookRun the notebook
notebooks/sentiment_analysis.ipynb
The notebook will:
- Load the dataset
- Clean text
- Perform EDA
- Perform NLP preprocessing
- Analyze sentiments
- Train the ML model
- Evaluate the model
- Save the trained model
- Deep Learning using LSTM
- BERT-based Sentiment Classification
- Streamlit Web Application
- Real-Time Sentiment Prediction
- REST API using FastAPI
- Docker Deployment
Vaishali Limbapure
Computer Engineering Student
Python β’ Machine Learning β’ NLP β’ Data Analytics
GitHub: https://github.com/kindlefest08








