A comprehensive Natural Language Processing (NLP) project that analyzes Amazon Alexa product reviews to predict sentiment classification. The project implements multiple machine learning algorithms and provides both web interface and API endpoints for sentiment prediction.
This project performs sentiment analysis on Amazon Alexa reviews using advanced NLP techniques and machine learning models. It classifies customer reviews as positive or negative, providing insights into customer satisfaction and product feedback patterns.
- Multi-Model Approach: Implements Random Forest, XGBoost, and Decision Tree classifiers
- Text Preprocessing: Advanced NLP preprocessing with stemming, stopword removal, and text normalization
- Interactive Web Interface: Modern responsive UI for single text prediction and bulk CSV processing
- REST API: Flask-based API endpoints for integration with other applications
- Data Visualization: Comprehensive EDA with word clouds, distribution plots, and sentiment analytics
- Batch Processing: Support for bulk sentiment analysis with downloadable results
- Source: Amazon Alexa product reviews dataset
- Size: 3,150 reviews across different Alexa variations
- Features: Rating, date, product variation, verified reviews, feedback
- Distribution: 91.87% positive reviews, 8.13% negative reviews
- Format: TSV (Tab-Separated Values)
- Data Cleaning: Null value handling and data validation
- Text Preprocessing:
- Regex-based text cleaning (removing non-alphabetic characters)
- Lowercasing and tokenization
- Stopword removal using NLTK
- Porter Stemming for word normalization
- Feature Engineering: Count Vectorization with 2,500 features
- Data Scaling: MinMax normalization for optimal model performance
- Random Forest Classifier: Ensemble method with hyperparameter tuning via GridSearchCV
- XGBoost Classifier: Gradient boosting for enhanced performance
- Decision Tree Classifier: Baseline interpretable model
- Evaluation Metrics: Accuracy scores, confusion matrices, cross-validation
- Training Accuracy: ~95-98% across models
- Testing Accuracy: ~90-93% validation accuracy
- Cross-Validation: 10-fold CV for robust performance estimation
├── api.py # Flask REST API server
├── main.py # Streamlit web application
├── Data Exploration & Modelling.ipynb # Complete EDA and model training
├── requirements.txt # Python dependencies
├── Data/
│ ├── amazon_alexa.tsv # Original dataset
│ ├── Predictions.csv # Sample predictions output
│ └── SentimentBulk.csv # Bulk processing template
├── Models/
│ ├── countVectorizer.pkl # Trained Count Vectorizer
│ ├── scaler.pkl # MinMax Scaler
│ ├── model_rf.pkl # Random Forest model
│ ├── model_xgb.pkl # XGBoost model
│ └── model_dt.pkl # Decision Tree model
└── templates/
├── index.html # Simple web interface
└── landing.html # Modern landing page
- Python 3.8+
- pip package manager
- Clone the repository
git clone <repository-url>
cd sentiments- Create virtual environment (recommended)
conda create -n sentiment-analysis python=3.10
conda activate sentiment-analysis- Install dependencies
pip install -r requirements.txt- Run the Flask API
flask --app api.py run --port=5000- Access the application
http://localhost:5000
streamlit run main.py# API endpoint: POST /predict
{
"text": "I love my new Alexa device, it works perfectly!"
}
# Response
{
"prediction": "Positive"
}Upload a CSV file with a 'Sentence' column for batch sentiment analysis. The system returns:
- Processed CSV with sentiment predictions
- Visualization of sentiment distribution
- Downloadable results
- Modern UI: Responsive design with gradient backgrounds
- Real-time Prediction: Instant sentiment analysis
- File Upload: Drag-and-drop CSV processing
- Visual Analytics: Automatic pie chart generation for bulk results
The project includes comprehensive data analysis:
- Rating Distribution: Heavily skewed towards 5-star ratings (79.18%)
- Product Variations: 16 different Alexa product types analyzed
- Review Length: Average review length correlates with sentiment intensity
- Word Analysis: Unique positive/negative vocabulary identification
- Rating and feedback distribution charts
- Product variation performance analysis
- Review length distribution by sentiment
- Word clouds for positive/negative reviews
- Correlation analysis between features
Random Forest:
- Training Accuracy: 98.2%
- Testing Accuracy: 92.1%
- Cross-validation: 91.8% ± 2.3%
XGBoost:
- Training Accuracy: 96.8%
- Testing Accuracy: 93.4%
Decision Tree:
- Training Accuracy: 95.1%
- Testing Accuracy: 90.7%
XGBoost was selected as the primary model for deployment due to:
- Highest testing accuracy
- Better generalization capability
- Robust performance on imbalanced data
Core Technologies:
- Python 3.10: Primary programming language
- Flask: REST API framework
- Streamlit: Interactive web application
Machine Learning & NLP:
- scikit-learn: ML algorithms and preprocessing
- XGBoost: Gradient boosting classifier
- NLTK: Natural language processing
- NumPy/Pandas: Data manipulation
Data Visualization:
- Matplotlib/Seaborn: Statistical visualizations
- WordCloud: Text visualization
- Plotly: Interactive charts
Frontend:
- HTML5/CSS3: Modern web interface
- TailwindCSS: Responsive design framework
- JavaScript: Dynamic interactions
- Advanced NLP: Implement BERT/Transformer models for better accuracy
- Real-time Processing: Add streaming sentiment analysis capability
- Multi-language Support: Extend to analyze reviews in multiple languages
- Deployment: Docker containerization and cloud deployment (AWS/GCP)
- Advanced Analytics: Sentiment trends over time, topic modeling
- Model Monitoring: MLOps pipeline for model performance tracking
This project is available under the MIT License.
Contributions are welcome! Please feel free to submit pull requests or open issues for improvements.
Note: This project demonstrates end-to-end machine learning workflow from data exploration to production deployment, showcasing skills in NLP, web development, and ML engineering.