Amazon Recommendation System using Python

Recommendation Systems are one of the widely used applications of Data Science in most companies based on products and online services. Amazon is a great example of such companies. Being an online shopping website Amazon needs to generate personalised recommendations to provide a better user experience. In this article, I will take you through how to create an Amazon Recommendation System using Python.

Amazon Recommendation System

The Recommendation System of Amazon follows the principle of generating product based recommendations which means measuring the similarities between two products and then recommend the most similar products to each user. The methods of measuring similarities between two products have always been a major focus of researchers.

But when it comes to a website like Amazon, it needs to add more criteria to recommend products to the users such as the quality of the product. A good quality product will always have a good collection of reviews so we can use both the similarity score and product reviews to generate recommendations. In the section below, I will take you through how to create an Amazon Recommendation System using Python.

Amazon Recommendation System using Python

I will try to use the fewer Python libraries I can for creating this recommendation system. To work with data I will be using only pandas and NumPy library in Python. So let’s import the data and see how to create an Amazon Recommendation System using Python:

import numpy as np
import pandas as pd

data = pd.read_csv("amazon.csv")
print(data.head())
    AKM1MP6P0OYPR  0132793040  5.0  1365811200
0  A2CX7LUOHB2NDG  0321732944  5.0  1341100800
1  A2NWSAGRHCP8N5  0439886341  1.0  1367193600
2  A2WNBOD3WNDNKT  0439886341  3.0  1374451200
3  A1GI0U4ZRJA8WN  0439886341  1.0  1334707200
4  A1QGNMC6O1VW39  0511189877  5.0  1397433600

The dataset that I am using here does not have columns names, so let’s give the most appropriate names to these columns:

data.columns = ['user_id', 'product_id','ratings','timestamp']

This dataset is very large so I will select a sample:

df = data[:int(len(data) * .1)]

Now let’s prepare the dataset for creating a recommendation system:

Now I will write a Python function to generate recommendations based on the score of the product reviews:

      user_id  product_id  score  Rank
113        11  B00004SB92      6   1.0
1099       11  B00008OE6I      5   2.0
368        11  B00005AW1H      4   3.0
612        11  B0000645C9      4   4.0
976        11  B00007KDVI      4   5.0

Summary

This is how we can create an Amazon Recommender System using Python. This dataset does not have names of products in it, it only had product id so the score of the product reviews becomes the most important feature for such kinds of datasets. I hope you like this article on how to create an Amazon Recommender System using Python. Feel free to ask your valuable questions in the comments section below.

Aman Kharwal
Aman Kharwal

Data Strategist at Statso. My aim is to decode data science for the real world in the most simple words.

Articles: 1607

Leave a Reply

Discover more from thecleverprogrammer

Subscribe now to keep reading and get access to the full archive.

Continue reading