This project implements a text classification machine learning model that analyses the customer's sentiments based on their reviews about a restaurant. The dataset is preprocessed, cleaned, and used to train a Naive Bayes classifier to classify reviews as either Positive or Negative.
This project is focused on building a sentiment analysis model for restaurant reviews. It consists of the following major components:
model.py
: Code to train the sentiment analysis model. It uses a dataset of restaurant reviews and saves the trained model (model.pkl
) and the CountVectorizer (cv-model.pkl
).app.py
: Flask app that serves as the main application. It provides:- A web interface to input reviews and get predictions.
- A REST API to send reviews programmatically and get responses.
request.py
: A script to demonstrate how to call the Flask API using Python'srequests
library.templates/
: Contains the HTML template for the web interface.static/
: Contains static files like JavaScript and CSS.
- Clone the Repository:
git clone https://github.com/sanskriti49/Sentiment-Analysis.git cd Sentiment-Analysis
- Set Up Python Environment
python3 -m venv venv venv\Scripts\activate
- Install Dependencies from requirements.txt:
pip install -r requirements.txt
Ensure that you are in the project home directory. Create the machine learning model by running below command -
python model.py
This would create a serialized version of our model into a file model.pkl
Run app.py using below command to start Flask API
python app.py
By default, flask will run on port 5000. Navigate to url http://localhost:5000
-
Run the script to train the model and display performance metrics:
python sentiment_analysis.py
-
View the final_df DataFrame to see the original reviews with their classified sentiments.
-
Use the saved model.pkl and cv-model.pkl files for predictions on new data.
The script generates:
- Accuracy score and confusion matrix for the trained model.
- A DataFrame (final_df) mapping original reviews to their classified sentiments.
Review | Second Header |
---|---|
The food was amazing! | Positive |
Terrible service and cold food | Negative |