Skip to content

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.

avinash-027/sentiment-analysis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

📝 Sentiment Analysis Web App

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.

🧰 Tech Stack

🔙 Backend

  • 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

💻 Frontend

  • React: JavaScript library for building user interfaces
  • Vite: Fast development server and bundler
  • Axios: Promise-based HTTP client to interact with the API

🗃️ Data

  • Dataset: Restaurant reviews (TSV format, labeled for sentiment)

🚀 Setup Instructions

🛠 Backend

cd backend
pip install -r requirements.txt         # Install dependencies
python train_model.py                   # Train and save the model (primary)
python app.py                           # Start Flask API

💻 Frontend

cd frontend
npm install                             # Install frontend packages
npx update-browserslist-db@latest      # (optional) Fix browserslist warning
npm run dev                             # Start the React app

📊 Features

  • 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

✅ Before You Run

Make sure to:

  1. Train the model using python train_model.py
  2. Start the Flask backend with python app.py
  3. Launch the frontend React app using npm run dev

🧠 Model Training Options

✔️ train_model.py (Recommended)

  • 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

⚙️ train_model11.py (Alternative)

  • 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 use train_model.py.

📌 Notes

  • 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.json and confusion matrix in analysis.png.

About

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.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published