A full-stack web application that performs sentiment analysis on restaurant reviews using machine learning. It includes a Flask backend for the API and a React frontend for user interaction.
- Python: Core programming language
- Flask: Lightweight web framework for the API
- scikit-learn: Machine learning for training and inference
- nltk: Natural language processing (text cleaning & preprocessing)
- joblib / pickle: Model serialization
- matplotlib / seaborn: Visualizing evaluation metrics
- React: JavaScript library for building user interfaces
- Vite: Fast development server and bundler
- Axios: Promise-based HTTP client to interact with the API
- Dataset: Restaurant reviews (TSV format, labeled for sentiment)
cd backend
pip install -r requirements.txt # Install dependencies
python train_model.py # Train and save the model (primary)
python app.py # Start Flask APIcd frontend
npm install # Install frontend packages
npx update-browserslist-db@latest # (optional) Fix browserslist warning
npm run dev # Start the React app- Train a sentiment classification model on restaurant reviews
- Use Logistic Regression (default) or Naive Bayes (alternative)
- Predict sentiment (positive/negative) via a REST API
- Visualize model metrics and confusion matrix
- React-based UI to input reviews and view predictions
Make sure to:
- Train the model using
python train_model.py - Start the Flask backend with
python app.py - Launch the frontend React app using
npm run dev
-
Vectorizer: TF-IDF
-
Model: Logistic Regression
-
Usage: Best for more accurate, real-world sentiment predictions
-
Saves:
c1_BoW_Sentiment_Model.pkl(TF-IDF vectorizer)c2_Classifier_Sentiment_Model(Logistic Regression model)metrics.json,analysis.png
- Vectorizer: CountVectorizer (Bag of Words)
- Model: Gaussian Naive Bayes
- Usage: Simpler model, quicker to train, lower accuracy
- Note: Uses only the first 900 reviews for training
💡 If you're just testing or exploring, you can try
train_model11.py, but for production usetrain_model.py.
- Ensure both backend and frontend are running on compatible ports (e.g., 5000 for Flask, 5173 for Vite).
- CORS configuration may be required if cross-origin requests are blocked.
- Model files (
*.pkl, classifier) must be generated before API calls will work. - After training, metrics are saved in
metrics.jsonand confusion matrix inanalysis.png.