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

No packages published

Languages