Creating an E-Commerce Product Category Classifier using Deep Learning — Part 2

Problem Description :

We aim to create a product category API that utilizes machine learning and deep learning to predict the possible categories/classes for any provided product name and its descriptions. The problem is considered for an e-commerce domain and the dataset used to train our models will contain some products and their labeled categories.

Machine Learning Pipeline :

Fig 1. The machine learning pipeline for the category prediction task.
  1. Multi-class classification: The labels are combined into one big binary classifier called powerset. For instance, having the targets A, B, and C, with 0 or 1 as outputs, we have A B C -> [0 1 0], while the binary classification transformation treats it as A B C -> [0] [1] [0].

Data Splitting

The next step after data preprocessing, converting it into a form the machine learning models can understand is to split it into train/test set.

Fig 2. A mathematical explanation of TF-IDF

Binary Classification Technique :

We will first use the Binary classification technique, which has been also explained above. In the below, you can see how we are creating a separate classifier for a separate product category, in machine learning this technique is called one-vs-all. We have used a simple linear regression model as a single product classification model. Other models worth trying are Naive Bayes, SVC, Random Forest.

Fig 3. Snippet showing individual accuracy/ROC of individual product classification model and finally accuracy/ROC of the overall model.
Fig 4. Predictions on a few samples, we can observe how it predicts Samsung as cell phone, Duracell battery as houseware.

Deep Learning-Based Models :

In this section, we will start creating deep learning-based models which follow the multi-class classification-based modeling. The data first needs to be preprocessed, tokenized, and split which will be quite similar to what we have done for the previous model. The deep learning-based model using vanilla neural nets is as bellow.

Fig 5. Simple neural net-based multi-classification product category prediction model
Fig 6. Performance tracking for neural net model
Fig 7. Prediction by the neural net multi-classification model, we can observe how it has classified Kung Fu Panda as a Video Game which is quite well.
Fig 8. Conv neural net-based multi-classification product category prediction model
Fig 9. Performance tracking for conv neural net model
Fig 10. LSTM + Glove neural net-based multi-classification product category prediction model
Fig 11. Performance tracking for LSTM + Glove neural net model
GET /product/categoryPrediction
"name":"product name",
"description":"product description"
Fig 12. Final prediction from LSTM+Glove based model as a product category classifier.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Prakhar Gurawa

Prakhar Gurawa

Data Scientist | Learner | Caricaturist | Omnivorous | DC Fanboy