Skip to content

Mrunalisa/Sentiment_Analysis_of_Restaurant_Reviews

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

🍴 Sentiment Analysis of Restaurant Reviews

This project performs Sentiment Analysis on restaurant reviews using Natural Language Processing (NLP) and Machine Learning (Naïve Bayes Classifier).
It predicts whether a given review is positive 😊 or negative 😞 based on the text entered by the user.


📘 Overview

The project uses a dataset of restaurant reviews (Restaurant_Reviews.tsv) to train a text classification model.
By cleaning, tokenizing, stemming, and converting text into numerical form using a Bag of Words model, it learns to classify reviews accurately.


🚀 Features

  • 🧹 Text preprocessing (cleaning, tokenization, stopword removal, stemming)
  • 🧠 Feature extraction using CountVectorizer (Bag of Words)
  • 🤖 Trained Naïve Bayes Classifier for sentiment prediction
  • ⚙️ Interactive console input to test custom reviews
  • 📊 Evaluation metrics: Accuracy, Precision, and Recall
  • 🔎 Hyperparameter tuning using different alpha values

🧰 Tech Stack

Category Libraries / Tools Used
Language Python
Data Handling NumPy, Pandas
NLP NLTK
Machine Learning scikit-learn
Visualization / Output Console-based metrics and predictions

📁 Dataset

The project uses the Restaurant_Reviews.tsv dataset, which contains two columns:

Column Description
Review The text review given by a customer
Liked The sentiment label (1 = Positive, 0 = Negative)

⚙️ Installation & Setup

  1. Clone the repository

    git clone https://github.com/yourusername/Sentiment_Analysis_of_Restaurant_Reviews.git
    cd Sentiment_Analysis_of_Restaurant_Reviews
  2. Install required libraries

    pip install numpy pandas nltk scikit-learn
  3. Download NLTK stopwords

    import nltk
    nltk.download('stopwords')
  4. Place the dataset
    Ensure the file Restaurant_Reviews.tsv is in the same directory as your Python script.

  5. Run the project

    python Sentiment_Analysis_of_Restaurant_Reviews.py

🧠 Model Workflow

  1. Data Preprocessing

    • Remove non-alphabetic characters using regex
    • Convert text to lowercase
    • Remove English stopwords
    • Apply stemming using PorterStemmer
    • Create a corpus of cleaned reviews
  2. Feature Extraction

    • Convert text into numeric vectors using CountVectorizer(max_features=1500)
  3. Model Training

    • Split data into training and testing sets (train_test_split)
    • Train using Multinomial Naive Bayes
  4. Evaluation

    • Calculate Accuracy, Precision, and Recall
    • Tune alpha hyperparameter to find the best score
  5. Prediction

    • Accept custom user input from console
    • Predict whether the review is Positive or Negative

📊 Example Output

-------------------
|     SCORES     |
-------------------

Accuracy Score  : 83.5%
Precision Score : 78.6%
Recall Score    : 80.1%

Accuracy Score for alpha=0.1 is : 83.25%
Accuracy Score for alpha=0.2 is : 83.5%
...
The Best Accuracy is 83.5%

----------------------------------------------------------------------------
|  This Model Predicts Whether Restaurant Review is Positive or Negative   |
----------------------------------------------------------------------------

Enter Your Review About Restaurant : The food was delicious and service was great!
=> This is Positive Review.

🧪 Example Use

# Example prediction
Enter Your Review About Restaurant : The place was very dirty and food was cold.
=> This is Negative Review.

🧾 Notes

  • The model is trained using Multinomial Naive Bayes, which is efficient for text classification tasks.
  • Adjusting the alpha parameter helps control model smoothing.
  • You can experiment with other classifiers like SVM or Logistic Regression for improved accuracy.

👩‍💻 Author

Mrunali Badgujar
📧 mrucoder@gmail.com

🔗 GitHub Profile


📜 License

This project is licensed under the MIT License — see the LICENSE file for details.


“Let the code decide if your meal was worth it!”

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages