4
$\begingroup$

I am working on a product classification problem (E-Commerce) in which I have to identify product category based on keywords.

Say for example, if input is given as 'Samsung Galaxy On Nxt 3 GB RAM 16 GB ROM Expandable Upto 256 GB 5.5 inch Full HD Display' , It should correctly identify it as 'Mobile'.

The problem here is that I have certain key-value pairs on which I have to train the model. Previously, I was doing the same problem by training model on product level using LinearSVC and it was giving satisfactory results.

Details about data:

  1. I have 39 classes/ categories currently, which might increase in future.

  2. I am using a csv file which is of around 10 MB and it has around 7000 rows.(Refer below structure)

  3. I am using LinearSVC from sklearn.svm

I have the following structure for training now:

--------------------------------------------------------------
| Attribute_Names   |  Attribute_Values        |   Category  |
--------------------------------------------------------------
| Brand             |  Samsung, Nokia, OnePlus | Mobile      |
| RAM, Memory       | 2 GB, 4 GB, 3 GB, 6GB    | Mobile      |
| Color,Colour      | Black, Golden, White     | Mobile      |
--------------------------------------------------------------
| Fabric, Material  | Cloth, Synthetic, Silk   | Ethnic Wear |
| Pattern, Design   | Digital, floral print    | Ethnic Wear |
--------------------------------------------------------------

I have the following queries:

1 - Which Model to use for this problem ?

2 - How would you handle such problem ?

3 - Any similar problem you have seen.

Any help is much appreciated.

EDIT:

step 1) - merge column(attribute_names, attribute_values)

step 2) - Cleaned the data(removing stopwords,special characters, steming)

step 3) - Feature extraction using TfidfVectorizer(stop_words='english',lowecase=True)

step 4) - OneVsRestClassifier(LinearSVC(loss='hinge',penalty='l2'))

This are the steps we have performed till now,and the results are not good enough (miss-classification still exist)

format/structure of data is same as we mentioned above.

$\endgroup$
5
  • $\begingroup$ I need to understand something. Is the structure you're showing is the actual structure ? Like you have 3 columns and 7000 rows that are going into those 3 clumns ? $\endgroup$ – MaxouMask Feb 5 '18 at 13:25
  • $\begingroup$ Yes, the structure that I have given above is the actual structure for the usecase. $\endgroup$ – Sumit S Chawla Feb 6 '18 at 6:16
  • $\begingroup$ Well this is not a gift... If I were you I'd try to get back to a classic X design matrix. Using the content of Attribute_Names to create your features and corresponding Attributes_Values to create your training set. Otherwise you're not having enough features compared to the number of classes you're facing. Do you think it's feasible ? $\endgroup$ – MaxouMask Feb 6 '18 at 8:22
  • $\begingroup$ @MaxouMask : I think I can not do that way in this case as number of attributes will change with every new class and also is it feasible to use all the features if they are varying. $\endgroup$ – Sumit S Chawla Feb 6 '18 at 8:53
  • $\begingroup$ So I have an idea but I'm really in the juice right now at work so I will provide a long solution description some time later. Hope it'll helps $\endgroup$ – MaxouMask Feb 6 '18 at 10:20
4
$\begingroup$

The problem type you're dealing with is referred to as multiclass classification. Not all algorithms are suited to handle it, but tree based methods and neural networks are popular choices. If you need it to run quickly and probability calibration isn't too important, Naive Bayes also works quite well for some data sets. To see an example of a dataset of this type, check of the Kaggle Spooky Author Identification competition. The published kernels give some good examples of feature engineering and modeling choices.

(I'm assuming the category label is unique. If there can be more than one label per record, it's called multilabel classification, which I would handle by building a separate binary model for each of the 39 labels in your data set. For an example dataset, check out the Kaggle Toxic Comments competition.)

As for modeling with your data in specific, the structure you have it in now seems a bit odd to feed to a model. A training data set should have each row represent one record, and each column represent a feature with the value in the column describing the record, whereas in your format, any cell phone should have information regarding each value in the corresponding mobile Attribute_Names. When you get the raw input 'Samsung Galaxy On Nxt 3 GB RAM 16 GB ROM Expandable Upto 256 GB 5.5 inch Full HD Display', how is that transformed into a format that can be fed into the model?

Also, where are the Attribute_Names, Attribute_Values coming from, are they manually specified? If so, that is limiting the performance potential from a model since there could be additional words in the data the model could detect if left to generate features on it's own. For a good modeling flow, the training data should contain the inputted raw text, then process the text to generate features, then feed into the actual model to output a label. So one row of raw training data set would be:

------------------------------------------------------------------------
| Description                                            |   Category  |
------------------------------------------------------------------------
| 'Samsung Galaxy On Nxt 3 GB RAM 16 GB ROM Expandable   | Mobile      |
| Upto 256 GB 5.5 inch Full HD Display'                  |             |
------------------------------------------------------------------------

You would then turn the text into features using some sklearn pre-processors. Count Vectorizer or TF-IDF Vectorizer are popular choices. You can also create your own features from keywords from the Attribute key and values you already have, such as creating a Brand indicator column if the words Samsung, Nokia or OnePlus appear in the text, but I would never use only manually specified features when modeling with text features.

$\endgroup$
1
  • $\begingroup$ Thanks for the answer but the steps you are referring to has already been done. This was my previous use case. But now the structure of the data has changed and it is not giving desired results for the data format we are using. $\endgroup$ – Sumit S Chawla Feb 6 '18 at 6:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.