The Implementation Of Amazon Food Reviews with Deployment
By: Sachin D N
Tags: Kaggle, Data Science, Coursera, Machine Learning, Towards Data Science

Contents

Overview of Dataset. Data Preprocessing. Train-Test split. Text Featurization using Bag of Words. Hyper Parameter Tuning. Model Building using the Naive Bayes algorithm. Performance Metrics. Model deployment into Web app using Flask API. Production of the model by Heroku platform. Results.

First We want to know What is Amazon Fine Food Review Analysis?

This dataset consists of reviews of fine foods from amazon. The data span a period of more than 10 years, including all ~500,000 reviews up to October 2012. Reviews include product and user information, ratings, and a plaintext review. We also have reviews from all other Amazon categories.

Amazon reviews are often the most publicly visible reviews of consumer products. As a frequent Amazon user, I was interested in examining the structure of a large database of Amazon reviews and visualizing this information so as to be a smarter consumer and reviewer.

Source: https://www.kaggle.com/snap/amazon-fine-food-reviews

Introduction

The Amazon Fine Food Reviews dataset consists of reviews of fine foods from Amazon.

Number of reviews: 568,454 Number of users: 256,059 Number of products: 74,258 Timespan: Oct 1999 — Oct 2012 Number of Attributes/Columns in data: 10

Attribute Information:

Id ProductId — unique identifier for the product UserId — unique identifier for the user Helpfulness Numerator — number of users who found the review helpful HelpfullnessDenominator — number of users who indicated whether they found the review helpful or not Score — a rating between 1 and 5 Time — timestamp for the review Summary — Brief summary of the review Text — Text of the review

Objective

Given a review, determine whether the review is positive (Rating of 4 or 5) or negative (rating of 1 or 2).

[Q] How to determine if a review is positive or negative?

[Ans] We could use the Score/Rating. A rating of 4 or 5 could be considered a positive review. A review of 1 or 2 could be considered negative. A review of 3 is neutral and ignored. This is an approximate and proxy way of determining the polarity (positivity/negativity) of a review.

Data Preprocessing

Data Preprocessing is a technique that is used to convert the raw data into a clean data set. In other words, whenever the data is gathered from different sources it is collected in raw format which is not feasible for the analysis.

To Know the Complete overview of the Amazon Food review dataset and Featurization visit my previous blog link here.

Train-Test split

The train-test split procedure is used to estimate the performance of machine learning algorithms when they are used to make predictions on data not used to train the model.

If you have one dataset, you’ll need to split it by using the Sklearn train_test_split function first.

Featurization using BOW Vectorizer

Hyper Parameter tuning

we want to choose the best Depth and best min_split for better performance of the model, to choose these by using Grid Search cross-validation.

Trained the model by NaiveBayes algorithm

Applied Multinomial NaiveBayes on these feature sets

Naive Bayes is a statistical classification technique based on Bayes Theorem. It is one of the simplest supervised learning algorithms. Naive Bayes classifier is a fast, accurate, and reliable algorithm. Naive Bayes classifiers have high accuracy and speed on large datasets.

Naive Bayes is the most straightforward and fast classification algorithm, which is suitable for a large chunk of data. Naive Bayes classifier is successfully used in various applications such as spam filtering, text classification, sentiment analysis, and recommender systems. It uses Bayes theorem of probability for the prediction of an unknown class.

Naive Bayes makes an assumption that features are conditionally independent. Theoretically, if the assumption does not hold true then the performance of NB degrades. But the research has shown that even if there is some feature dependency the Naive Bayes gives the best result.

To Know detailed information about NaiveBayes algorithm and implementation please visit my Previous blog

After we find the best Parameters using a Grid search CV we want to check the performance with Test data, in this case, study, we use the AUC as the Performance measure.

Performance Metrics

Performance metrics are used to measure the behavior, activities, and performance of a business. This should be in the form of data that measures required data within a range, allowing a basis to be formed supporting the achievement of overall business goals.

To Know detailed information about performance metrics used in Machine Learning please visit my previous blog link here.

Save the trained model in a pickle file for production

Amazon_Food_Reviews_Model_Deployment

Building a machine learning project is one thing but what matters at the end is how you show your project to the world. Documenting your whole project on GitHub is another thing but deploying your deep learning model as a web application is totally different game ball.

In order for Machine Learning Engineers to succeed at work, they need to build services such that other teams can use or a product where people can use it directly. Essentially, the goal is to provide a model as a service and for that, there is a concept called API. API is the way for computer systems to talk to each other over Internet Protocols. They act as an agent that takes information from the user to the server and then again from the server to the user giving back the answer. Flask provides that capability. Flask will act as an API between your model and the HTML file.

We begin by creating a project folder where we define all dependencies in the requirements.txt file. To ensure that all dependencies are isolated from our application, we create a virtual environment for our working space.

To deploy we want to train our model and save the outputs in a pickle file and these pickle files are used to predict the new reviews in production.

Steps

Create a GitHub Repository (optional)

Create and Pickle a Model Using Titanic Data.

Create a Flask App.

Test Flask App Locally (optional)

Deploy to Heroku.

Test Working App.

Results

Positive Reviews

Negative Reviews

I have deployed the app in Heroku Platform to see visit here

To Know the Complete overview of the Amazon Food review dataset and Featurization visit my previous blog link here.

To Know detailed information about performance metrics used in Machine Learning please visit my previous blog link here.

To understand the full code please visit my GitHub link.

Thanks for reading and your patience. I hope you liked the post, let me know if there are any errors in my post.

References

Applied AI

Wikipedia

Coursera

Data Camp

Contact: Email LinkedIn Github Medium Twitter

The blog is also published at https://sachin-d-n.github.io.