Recommendation Systems are one of the popular applications of Data Science for every e-commerce platform. When it comes to fashion, an e-commerce platform wants to recommend the most trending fashion to its users for higher sales and engagement. Myntra is one of the popular e-commerce platforms known for its fashion recommendations. So, if you want to know how to build a recommendation system to recommend trending fashion, this article is for you. This article will take you through how to build a fashion recommendation system using Python.
Fashion Recommendation System
A fashion recommendation system is an application that recommends the most trending fashion based on the user’s search query. For example, if a user is looking for a Kurti, the recommendation system will recommend the most trending or highly rated Kurtis on their platform.
To build a fashion recommendation system, we need a dataset based on fashion products. We collected data about Kurtis from Myntra that we can use to create a fashion recommendation system using Python.
You can download the dataset from here.
In the section below, I will take you through building a fashion recommendation system using Python.
Fashion Recommendation System using Python
Let’s start this task by importing the necessary Python libraries and the dataset:
import numpy as np import pandas as pd from sklearn.metrics.pairwise import cosine_similarity import matplotlib.pyplot as plt from wordcloud import WordCloud, STOPWORDS, ImageColorGenerator from nltk.corpus import stopwords import string data = pd.read_csv("Myntra kurtis.csv") print(data.head())
Brand Name Product URL \ 0 Rain & Rainbow https://www.myntra.com/kurtis/rain--rainbow/ra... 1 HERE&NOW https://www.myntra.com/kurtis/herenow/herenow-... 2 Anouk https://www.myntra.com/kurtis/anouk/anouk-wome... 3 Anubhutee https://www.myntra.com/kurtis/anubhutee/anubhu... 4 GERUA https://www.myntra.com/kurtis/gerua/gerua-wome... Image Product Ratings \ 0 https://assets.myntassets.com/dpr_2,q_60,w_210... 4.2 1 https://assets.myntassets.com/dpr_2,q_60,w_210... 4.2 2 https://assets.myntassets.com/dpr_2,q_60,w_210... 4.2 3 https://assets.myntassets.com/dpr_2,q_60,w_210... 4.3 4 https://assets.myntassets.com/dpr_2,q_60,w_210... 4.2 Number of ratings Product Info \ 0 28 Printed Pure Cotton Kurti 1 805 Embroidered Pure Cotton A-Line Kurti 2 2800 Printed Pure Cotton Indigo Anarkali Kurta 3 1100 Ethnic Motifs Printed Kurti 4 157 Ethnic Motifs Printed Kurti Selling Price Price Discount 0 837.0 1395.0 (40% OFF) 1 719.0 1799.0 (60% OFF) 2 594.0 1699.0 (65% OFF) 3 521.0 1739.0 (70% OFF) 4 449.0 1499.0 (70% OFF)
The data contains information about:
- brand name of the product
- URL of the product
- Image URL of the product
- Ratings of the product on Myntra
- Total number of ratings
- Information about the product
- Selling price and original price of the product
- and discount on the product
Let’s have a look if the dataset contains any null values or not:
print(data.isnull().sum())
Brand Name 0 Product URL 0 Image 467 Product Ratings 198 Number of ratings 0 Product Info 0 Selling Price 74 Price 74 Discount 74 dtype: int64
The dataset has some null values, but there are 467 null values in the Image column, where the total number of rows in the data is 600. So, I will delete the Image column and move further:
data = data.drop("Image",axis=1)
Now let’s drop the null values present in the other columns in the dataset:
data = data.dropna()
Now let’s have a look at the shape of the dataset:
print(data.shape)
(364, 8)
So there are 364 rows present in the dataset after removing the null values. Now let’s move forward by looking at the brands that sell Kurtis more on Myntra:
text = " ".join(i for i in data["Brand Name"]) stopwords = set(STOPWORDS) wordcloud = WordCloud(stopwords=stopwords, background_color="white").generate(text) plt.figure( figsize=(15,10)) plt.imshow(wordcloud, interpolation='bilinear') plt.axis("off") plt.show()

So, brands like Anubhutee, Malhaar, Now, Tissu, and Pistaa are popular for Kurtis on Myntra. Now let’s have a look at the highest-rated Kurtis on Myntra:
highest_rated = data.sort_values(by=["Product Ratings"], ascending=False) highest_rated = highest_rated.head(10) print(highest_rated[['Product Info', "Product Ratings", "Brand Name"]])
Product Info Product Ratings Brand Name 435 Mandarin Collar Kurti 5.0 INDYES 249 Floral Printed Kaftan Kurta 5.0 Sangria 448 Solid Pure Cotton Kurti 5.0 MALHAAR 308 Floral Printed Kurti 5.0 MALHAAR 538 Pure Cotton Kurti 5.0 MALHAAR 277 Women Solid Embellished Kurti 5.0 Fabindia 515 Chikankari Embroidered Kurti 5.0 PARAMOUNT CHIKAN 62 Ethnic Motifs Printed Kurti 4.9 Biba 80 Ethnic Motifs Embroidered Kurti 4.8 Sangria 450 Self Striped Straight Kurti 4.8 Saanjh
So, brands like Indyes, Sangria, Malhaar, Fabindia, Paramount Chikan, Biba, and Saanjh are selling the highest-rated Kurtis on Myntra.
Recommending Fashion Products
To recommend the trending fashion, we cannot use the content-based filtering strategy. The content-based filtering strategy is good to use when a user is looking at a fashion product, and your application wants to recommend something similar.
To recommend the trending fashion, we can find the weighted average of all the ratings and recommend the products based on the weighted average ratings. To count the weighted score of all the ratings of Kurtis, we need:
- mean rating (mr): the mean rating of all the products
- minimum ratings (m): minimum number of ratings
- number of ratings (n): total number of ratings of the product
- average ratings (a): average rating of the product
Now below is the formula to calculate the weighted score of the product ratings:
- score = (n/(n+m) * a) + (m/(m+n) * mr)
Now let’s calculate the weighted score and recommend the most trending Kurtis on Myntra:
mr = data['Product Ratings'].mean() m = data['Number of ratings'].quantile(0.9) n = data['Number of ratings'] a = data['Product Ratings'] data["Score"] = (n/(n+m) * a) + (m/(m+n) * mr) recommendations = data.sort_values('Score', ascending=False) print(recommendations[['Brand Name', 'Product Info', 'Product Ratings', 'Score', 'Selling Price', 'Discount']].head(10))
Brand Name Product Info \ 48 Tissu Women Floral Print A-Line Kurti 11 Anubhutee Ethnic Motifs Printed Kurti 155 Anubhutee Women Printed Kurti 66 YASH GALLERY Printed A-Line Kurti 27 Anubhutee Women Printed Straight Kurti 102 AKIMIA Embroidered Pure Cotton Kurti 88 Tissu Women Floral Printed Straight Kurti 3 Anubhutee Ethnic Motifs Printed Kurti 42 Rain & Rainbow Women Printed Pure Cotton Pure Cotton A-Line K... 18 GERUA Ethnic Motifs Printed Kurti Product Ratings Score Selling Price Discount 48 4.4 4.338320 549.0 (45% OFF) 11 4.4 4.300868 521.0 (70% OFF) 155 4.4 4.296895 486.0 (72% OFF) 66 4.5 4.295568 629.0 (55% OFF) 27 4.3 4.274815 521.0 (70% OFF) 102 4.5 4.273667 767.0 (52% OFF) 88 4.3 4.267992 548.0 (39% OFF) 3 4.3 4.267992 521.0 (70% OFF) 42 4.4 4.264685 797.0 (50% OFF) 18 4.6 4.262359 449.0 (70% OFF)
So this is how you can create a fashion recommendation system using Python.
Summary
A fashion recommendation system is an application that recommends the most trending fashion based on the user’s search query. Myntra is one of the popular e-commerce platforms known for its fashion recommendations. I hope you liked this article on building a fashion recommendation system using Python. You can learn more about recommendation systems here. Feel free to ask valuable questions in the comments section below.