Skip to content

kindlefest08/CodeAlpha_Sentiment_Analysis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“Š CodeAlpha Sentiment Analysis

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.

Python Pandas Scikit-Learn NLTK License


Table of Contents

  • 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

Project Overview

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.


Features

  • 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

Project Structure

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

Dataset

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

Technologies Used

  • Python
  • Pandas
  • NumPy
  • Matplotlib
  • Seaborn
  • NLTK
  • NRCLex
  • Scikit-learn
  • WordCloud
  • Joblib
  • Jupyter Notebook

πŸ”„ Workflow

Amazon Reviews Dataset
            β”‚
            β–Ό
     Data Cleaning
            β”‚
            β–Ό
 Exploratory Data Analysis
            β”‚
            β–Ό
 Text Preprocessing
            β”‚
            β–Ό
 TF-IDF Vectorization
            β”‚
            β–Ό
 Logistic Regression Model
            β”‚
            β–Ό
 Sentiment Prediction
            β”‚
            β–Ό
 Performance Evaluation

πŸ“Š Exploratory Data Analysis

Review Score Distribution

Shows the distribution of ratings from 1 to 5.


Sentiment Distribution

Rule-based sentiment generated from review ratings.


Word Count Distribution

Distribution of review lengths after preprocessing.


Word Cloud

Most frequently occurring words in customer reviews.


VADER Sentiment Analysis

VADER calculates a compound sentiment score between -1 and +1.

VADER Sentiment Distribution


VADER Score Distribution


Rule-Based vs VADER

Comparison between rating-based sentiment and VADER sentiment.


❀️ Emotion Analysis

Emotion detection performed using the NRC Emotion Lexicon.

Detected emotions include:

  • Joy
  • Trust
  • Fear
  • Anger
  • Sadness
  • Surprise
  • Anticipation
  • Disgust

Emotion Distribution


Machine Learning Model

The cleaned review text was converted into numerical features using TF-IDF Vectorization.

A Logistic Regression classifier was trained to predict customer sentiment.

Model Pipeline

Processed Review
        β”‚
        β–Ό
TF-IDF Vectorizer
        β”‚
        β–Ό
Logistic Regression
        β”‚
        β–Ό
Prediction

Model Performance

Accuracy

86.45%

Classification Report

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

Machine Learning Confusion Matrix


Saved Model

The trained model and TF-IDF vectorizer are stored for future predictions.

models/
β”‚
β”œβ”€β”€ sentiment_model.pkl
└── tfidf_vectorizer.pkl

Installation

Clone the repository

git clone https://github.com/kindlefest08/CodeAlpha_Sentiment_Analysis.git

Move into the project

cd CodeAlpha_Sentiment_Analysis

Install dependencies

pip install -r requirements.txt

Launch Jupyter Notebook

jupyter notebook

Usage

Run 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

Future Improvements

  • Deep Learning using LSTM
  • BERT-based Sentiment Classification
  • Streamlit Web Application
  • Real-Time Sentiment Prediction
  • REST API using FastAPI
  • Docker Deployment

Author

Vaishali Limbapure

Computer Engineering Student

Python β€’ Machine Learning β€’ NLP β€’ Data Analytics

GitHub: https://github.com/kindlefest08


⭐ If you found this project useful, consider giving it a Star!

About

A Machine Learning based Sentiment Analysis project using TF-IDF, Logistic Regression, NLTK, and VADER sentiment analysis with comprehensive visualizations.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages